Why on Rails: Story of a former PHP developer

Daniele Palombo

29 May 2018 Development, Ruby On Rails

Daniele Palombo

4 mins
Why on Rails - Nebulab

In this article I want to share with you my first experience with Ruby on Rails, but before that, I think an introduction to the Ruby language and the related Ruby on Rails framework can be useful.

Ruby

Unlike other languages such as C++ and Java, Ruby is a totally object-oriented language, which means that everything is an object.

There are no primitive types such as numbers and classes, the numbers and even nil (Void Object) are objects themselves and as such can have some methods and properties.

Ruby on Rails

When starting out Ruby on Rails can be hard to learn. The best way to do something is to embrace its philosophy: reading and understanding its documentation and conventions is crucial to understanding how to build something with it. After learning enough of the framework you will be able to combine all its components to work together and keep the code easy to understand and without having to reinvent the wheel.

My experience as former PHP developer

When I started developing web sites, Ruby on Rails was not my first choice. The most popular Web programming language at the time was PHP. Like everybody that picks up a new language I was sceptical at first.

Is this the right language? What advantages will this bring as opposed to PHP?

After many years I have been repaid for making such a choice.

So... Why Rails?

Documentation

I immediately agreed with the documentation provided by https://www.ruby-lang.org, which with http://tryruby.org, allowed me to move as quickly as possible to the next step: Rails.

I soon got started with http://guides.rubyonrails.org, which was really easy to follow. I already knew the MVC Pattern and all I needed to do was to copy and paste a few commands to create a basic working interface to create, read, update and delete (CRUD) blog posts which in PHP would have taken a lot longer. I think that today the tables have turned and PHP frameworks are actually good but, at the time, there was nothing that could create all this code so quickly.

Syntax

Even though I didn't known Ruby very well, or at least not as well as PHP, I quickly noticed that the language was very smooth and simple to understand. Reading it was enough to understand what the code was going to do. This made studying the language a pleasure. At the beginning, the small quantity of punctuation symbols was an unexpected thing, but it revealed the cleanliness of the code.

For example:

PHP

$items = array( 'orange', 'pear', 'banana' );
foreach ( $items as $i => $item ) {
    echo $i, $item;
}

Ruby

items = ['orange', 'pear', 'banana']
items.each_with_index do |item, i|
    puts i, item
end

In the example you can see what I mean: the method name each_with_index is easier to understand than foreach.

Rails Commands

The framework provides a whole set of tools that can be used to complete the most common operations.

  • Generators: the first things that I appreciated. The application bootstrap can be done with one command, this was amazing for me, furthermore having the opportunity to create with one command Controller, Model and View was love at first sight.
  • Tasks: allowed me to manage every side operation: database, cache, logs - each of these have specific tasks to satisfy the developer's most common needs.

These commands can be added rather easily so a lot can be done with them, from bootstrapping your application, like bretelline, to capturing payments on Solidus.

Community

I understood from the beginning the community would be one of the strengths of Ruby on Rails. As opposed to other communities every line of code in Ruby on Rails must be tested and optimized before it's released.

  • Tested: This is one of the foundations of Ruby, write code which tests what code does. This allows developers to effectively reduce the amount of bugs in their application code.
  • Optimized: The code, besides doing its thing, must be readable and easily changeable.

Even if all these checks seem to reduce the development time, they increase the quality of code by greatly reducing the maintenance time, and making developers happy!

Packages

The community is very active and has been writing many libraries (called gems) in order extend the language and the framework. Each of them can be easily installed by typing gem install gem_name or using Ruby's de-facto standard for managing dependencies: Bundler. In general, the code is hosted on Github which allows developers to write documentation in their commits.

Following in the tradition of Ruby on Rails, every gem is checked thoroughly and tested, ensuring that the gem works well.

How Ruby on Rails keeps me happy as developer

Today I feel like my choice of Ruby on Rails was correct, especially because its use has grown exponentially. I've built and actively maintain a lot of Rails projects. These are some of the things I appreciate the most:

  • Every project in Rails follows standards and generally has a test suite so maintaining the code is very easy.
  • Every time I need a library there is a working stable gem, regularly maintained and updated by a skilled developer.

Final notes

What I'm trying to explain in this article is that Rails is more than an HTML generator, it is a full-stack framework that responds to almost every need of the modern web developer by reducing trivial choices and by accepting community conventions. This is the main reason why I love to work with Rails.

You may also like

Let’s redefine
eCommerce together.