CHROMABITS

4 minutes

My last post in web development was about Node.js and how easy I found to build web apps with it. However, this doesn’t mean I have abandoned PHP, in fact, it has pushed me to write better PHP applications and improve the quality of my code.

Old vs New PHP

A common thing that has happened to me recently is that when I tell other CS majors (at least the ones that know about web development) that I write web applications in PHP, they instantly start talking about how awful it is as a language, how antiquated it is, etc.

These claims are not entirely baseless; PHP has seen better days, and many parts of the language have always felt like a hack due to the lack of standards and inconsistent type system (I can declare the type of a parameter of a function as class but not a string or integer?).

However, PHP hasn’t stayed frozen in time, the community has slowly been improving the language by adding some cool features.

Sadly, the general consensus in some cases still seems to be that applications in languages like Java and PHP are old and hard to write, and that you as developer are uncool if you are not using a “hip and modern” framework/language like Ruby on Rails or Node.js. In addition to the regular need to improve software, this situation has pushed the PHP community to improve their practices and have a modern development workflow. Sort of like a ?We can do modern development too?, which shows that the community is resilient and that it is open to major changes.

A few days ago I attended an AtlantaPHP talk on modern PHP development, by Ben Ramsey (@ramsey), and some of the ideas that got my attention were that the PHP community is very good at ?borrowing? concepts and including them into the language and frameworks, and that PHP development is not only about the language itself, but the tools around it and they way applications are built.

One of the most important recent projects in PHP is Composer. Composer is a very similar to other package managers like Node’s npm. It greatly simplifies the process of sharing and including external libraries into a project (Specially since code can be easily hosted online in places like Bitbucket and Github). This puts PHP’s workflow closer to how you would build a Node.js application.

The old way I used to write PHP applications consisted on me trying to build everything from scratch (the ?not built here syndrome?), which resulted in big projects that were difficult to maintain. I even got as far as to build my own PHP bsic framework (See: Brickwalls CMS) which attempted to organize applications into a basic MVC model.

Being able to use multiple modules from different libraries put some on the weight of developing and maintaining an application on the community rather than all of it on yourself or your team. Many PHP open source libraries are well maintained and probably more secure than your own code (Although it’s always good to look at the code that you’re importing into your project).

Additionally, just because somebody writes an application in PHP it doesn’t mean that they are barred from using tools like Grunt, Bower or Rubygems even if these are written in another language or platform. Specially since CSS pre-processors like SASS and LESS, and Javascript minification and dependency resolution are becoming standard in many applications nowadays.

A modern PHP framework

Logo

The other big thing in PHP right now are frameworks. There are a bunch of them, and thanks to standards and Composer they are all cooperating together. My favorite one so far is Laravel.

Development in Laravel is much different from classic PHP development, and the best part is that it achieves this by changing how we build applications rather than the syntax of the language.

I like to think that Laravel as a big compilation of web development patterns and knowledge that people have gained over time (also in part because it includes many smaller libraries as dependencies). It provides libraries for most basic development tasks and application structure, such as a database abstraction system and a request router. Additionally, if you ever need a library that is not included it is pretty easy to include it using Composer.

Something that kept me away from libraries for a long time was the fact that many frameworks force you into molding your code and mind to fit their way of thinking. This leads to developers fighting with code or frustrated because the framework may not expressive enough or do some things in a weird way. Laravel is very different in this aspect thanks to the fact that most of it’s components are optional and have very standard behaviors. While you won’t probably be doing things different form the Laravel way for basic applications, you still have enough flexibility to implement custom behaviors just by ignoring components or using a lower level library (like using a Query Builder instead of a ORM like Eloquent).

Similarly to how Ruby on Rails works, Laravel also includes a command line tool called Artisan for performing common tasks such as setting up the database or creating a simple PHP development server (Yes, no Apache installation required). It also is extensible, so you can use tools like Laravel Generators for creating boilerplate code like Controllers, Views, Models and Routes. In fact, you can get a basic prototype web application just by using Artisan command tools.

In general, I have enjoyed using Laravel a lot recently, and it really has helped me on an internship project I’m currently working on. It definitely restores my hope on PHP and makes me want to write more applications on PHP due to its simplicity and maturity. If you want to try PHP, I definitely recommend using Laravel.


3 minutes

Desktop screenshot

I have been asked about which Linux distribution I use a few times so I thought that it would be nice to share it here.

When I started using Linux, Ubuntu depended on the GNOME 2 desktop environment. It was simple but looked goood at the same time (and it was all brown/orange-ish). However, I didn’t like it when they decided to drop GNOME and start using their own custom environment, Unity. Since then, I have been installing GNOME 3 on top of Unity on my Ubuntu machines. The process became easier when a group of users decided to create the Ubuntu GNOME distribution, which includes GNOME as the default environment. I started using this distro as soon as it came out. However, more recently I have been experimenting with other distributions like Arch and Fedora to see how difference they are from Debian and Ubuntu. Arch was very customizable and had a strong DIY philosophy, but as a consequence it was really hard to setup and fix if the system broke. On the other hand, Fedora 20 actually impressed me with it’s level of polish and integration with GNOME 3, and it includes a package manager that is similar to what you would expect in a Debian system.

Why GNOME 3?

Some people don’t care too much about how their system looks as long as it gets the job done. However, one of the reasons I use Linux instead of Windows is because I don’t really like the UI (outside of Metro). So the environment I choose should look good and have a consistent design. Gnome 3 really accomplishes this. There is a strong cohesion in the overall design of every Gnome/GTK app and everything I run on the system essentially feels like part of it (except for Java apps, of course). I think it rivals Mac OSX design cohesion and leaves Windows to shame.

One of the things that Unity added to Ubuntu was universal search (kind of like Spotlight in OSX). However, while using it there was this small 1-2 second lag to open the search after you pressed the keyboard shortcut. I would end up writing stuff like “clipse” or “refox”. Windows also has a fast response time, but for some reason it spends more time loading results (an SSD might solve the problem). Gnome shell has a really fast search, and I got used to it really fast. Press key, type first letters of the program, enter It may not have the same amount of lenses that Unity search has, but I think that that is what keeps it fast and lightweight.

Window overview

Another important part of Gnome 3 for me is the overview mode that appears as soon as you press the super (or Windows) key. It really makes it easier to find windows and organize my workspaces. The feature is VERY similar to the one in Mac OSX, but I think it is nice to be able to do this sort of stuff on a non-Apple system.

Apps

Terminal and VIM

Desktop screenshot

I use the Gnome Terminal with a solarized theme. Vim is my favorite editor (sorry Emac fans), but I really can’t use it without plugins anymore. I use a distribution called spf13 that includes many common plugins already configured for you.

Solarized theme: https://github.com/sigurdga/gnome-terminal-colors-solarized

VIM spf13: http://vim.spf13.com

Nautilus

Nautilus (now known just as Files) is the default file manager in Gnome. The new compact design gets rid of the menu bar and merges everything into the title bar. One feature I really like is the server mounting feature. It lets me access SSH server in the same way I would access a USB drive or partition.

Corebird

There are a lot of Twitter clients for Linux. Gwibber was the default on Ubuntu but it was always terribly laggy. I recently found out that a new client designed specifically for Gnome 3 was available. Corebird has a very nice design and animations, and features a realtime stream of tweets just like TweetDeck.

To install on Fedora:

yum install corebird

More info on http://corebird.baedert.org

Empathy

This is my favorite chat application. The fact that it lets you write replies right on the notifications (Note: They added this before OSX did) is really useful and allows me to stay focused on the main window I’m working on and saves a few ALT-TABs


2 minutes

So Node.js has been around for while now and if you read blogs about web development, you probably have heard how good it is supposed to be. For the past few years I have gotten pretty comfortable with PHP, and as a result things got a little bit uninteresting or slightly boring. So I decided to try out and learn a new language for web development. I was specifically looking to learn a language that allows you to roll your own web server. I was already learning about Java web dev in one of my classes that semester (JBoss specifically) so my two remaining options were Python and Node. I ended up choosing Node due to the fact that it used JavaScript (which I had done a pretty good job at avoiding so far) which is also used by most modern web browsers. My first project and learning experience consisted on rewriting the code that runs the blog you are reading right now. Along the way, I found a couple of things that I liked and a few that I didn?t like. Here are some of them:

Liked:

Packages and code reuse: This is a biggie. For me, it felt like Node was designed with the intention of code reuse. The abundance of packages that do all sort of things really allow developers to focus on building applications rather than forcing them reinvent the wheel every time. PHP has had things like Composer but I don?t think the number of packages available even compares.

Simplicity: I found JS to be a very simple and easy to understand language. There are a few things that I?m still trying to get the grasp of (like creating objects and working with prototypes), but in general I think that it was very easy to pick up and many of the functions included by Node are very well documented.

“Owning” the server: This is something I see as just more efficient (I could be wrong). The fact that applications run continuously and create their own HTTP server, and in general keep a lot of things already loaded in memory seems more efficient to me. For example, a template engine I was using keeps precompiled versions of each template in memory in order to avoid loading them on every request. In comparison, PHP on Apache has to load everything from scratch every time a user makes a request.

Source-code and HTML are separate: This one has a lot to do with PHP. I really like having separate files for my code and HTML.

Didn’t like:

Messy code and legibility: This became apparent as my application grew in complexity, but it might be more related to the fact that I?m a beginner rather than the language itself. Once you have a couple of functions nested inside of each other, things can get a little messy and hard to read.

In general, Node seems like a great language for rapid prototyping and small applications. Its package system makes it perfect for projects that mix a lot of technologies together. Although, I would probably need to learn better JS coding patterns or consider other options like Java or Python if I was to build a more complex application.

…or you can find more in the archives.

CHROMABITS
Copyright © 2015-2021 - Eduardo Trujillo
Except where otherwise noted, content on this site is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) license.
Site generated using Gatsby.