Rails over PHP

November 12, 2016

I have been programming for more than 2 years, But among those years I have spent most of my time either learning or doing PHP. I used to love PHP. It is a great programming language, But not good enough to get me to stick around. Then what language do I use for most of the time? Well, it’s Rails. What is Rails aka Ruby on Rails? Rails is a web framework built on top of Ruby programming language. At the time of writing this post I have done Rails for more than 3 months. And comparing those 3 months of experience with Rails and 2 years of experience with PHP, I am happy for last 3 months aka I am happy with Rails. To show you guys why I am happy with Rails over PHP let me describe each language with pros and cons and I will let you guys decide why.

PHP:

PHP is most famous for its simplicity and shallow learning curve. You don’t have to configure anything to get started with PHP, all you need is an HTML file change the extension to .php write some PHP code inside <?PHP //code here ?> Run it on any PHP web server then you are good to go. Deploying PHP is also so easy you just have to FTP the files to the web server and your website is live on the internet. But too much simplicity is bad because you could find people easily who can write PHP, But it’s harder to find people who writes maintainable, scalable and efficient code. It’s because of simplicity PHP is often considered as having sloppy and unmaintainable code.

PHP has a unique plus point as it is made for the web. Yes PHP is entirely designed for web. Many of the inbuilt functions are there to solve real world web problems. For example, function like md5(), mysql_connect() and header() these functions make the life of PHP developer a lot easier.

The Bad point about PHP is that it was just a scripting language build to solve web problems and did not use OOP patterns on its earlier age. With PHP, OOP started to become feasible with the release of PHP 4, But really came around with the release of PHP 5. So There have not been a long period since it started using OOP concepts. It’s good that an old and widely popular language started using OOP, but with this comes complexity as most of the newbie developers don’t know how to write OOP PHP creating much more sloppy and unmaintainable code. But there’s another point to remember PHP does have certain coding patterns/rules to be followed by developers being formulated by the PHP community as the years go by, which makes PHP harder and confusing as any other High level programming language. Even though PHP is now trying hard to implement OOP features, it’s developers don’t really care to implement the true power of OOP PHP.

Still with some design flaws and being old PHP is still the most widely used programming language to build web applications. More than 80% of the web today is powered by PHP. But (Truly my opinion) I guess it will not be the case for long enough. As the beautiful tip of the iceberg has hidden its dark face in the water. But out there who loves PHP and want to be a great developer. I suggest (If you think me worthy) to use its framework rather than sticking with raw PHP. PHP has some great framework that helps it’s developer to use the power of OOP PHP with maintainable and scalable code still keeping the spirit of its simplicity.

Ruby On Rails aka Rails:

It has not been a long period of time since I have started using Rails over PHP, But it has been long enough to tell me that I love Rails. I have found that Rails enables to create beautiful web applications faster, that are maintainable and scalable. It’s based on the Ruby programming language which is truly OOP makes the use of OOP concept and power. Other than that because of its large community and stable nature, it’s a lot easier to find immediate support.

Other than being really powerful web framework Rails also has a distinctive feature having English like code structure which makes easier to understand its code. Even a non-programmer reading the rails code could easily tell what the following line of code is doing. This is because of Ruby as Ruby was build for making the life of programmer easy. Yet it has another special plus point as it enables its developer focus on problem automating all the repetitive task putting its spirit of Convention over Configuration.

Rails also has a large number of plugin called gems. These gems helps developer to avoid re-inventing the wheel, thus making the development process faster and hectic free. It also has generators that generate most of the repetitive code on a single command again making the life of the developer easier.

I should not talk about this as I am comparing a language and a framework here but it’s a legitimate point. Rails follows an MVC pattern separating an application’s database and its UI increasing its security and the most important feature maintained code. PHP also has a framework that uses the MVC pattern, but the point here is that every developer using Rails has to understand the principle of MVC and has to use it, But developer using PHP doesn’t have any such rule that gives Rails a point over PHP. Other than that Rails follows the test development process, making its developer to test each line of code. Testing is easy on rails as it has many testing tools while PHP is still struggling to create an ecosystem of testing. Rspec is one of the example of testing tool used in rails.

Rails also has some bad points as it has a steep learning curve. Yes, Rails is not an easy framework to learn. Developer learning Rails have to learn some advanced topic from the first week. Not only it is criticized for having a steep learning curve it is often criticized for being slow. Rails is slower than PHP as it is built upon the foundation of the Ruby language. Ruby takes time to be executed by a computer because of its architecture of becoming a programmer friendly.

Following some patterns on rails are pain in an ass for new developers as they are struggling to learn Rails and also may have to learn CoffeeScript instead of Javascript, SCSS etc. Deploying Rails app is also harder then of PHP. But once you configure the host then you just have to run a single command before your application is live on the internet.

Conclusion:

Then at last what do I think. PHP is easy to learn and has many resources to get started with. It also has cool new frameworks like Laravel. Rails is really hard to learn but all those pain are worth once you feel comfortable with this amazing framework. Due to its cool features like supporting caching out of the box and having a background process makes Rails the best web tool over PHP. I can tell once you get your hands on this amazing framework you are never looking back. Rails, Rocks (Truly My Opinion)