PHP vs Ruby on Rails - Which language is Better for Web Development in 2018?

CONTENTS

    From time to time you'll stumble upon developers that are familiar with both of these languages and able to compare them. But this comparison is probably will be too quick and superficial, because of the fact that such articles are made because of clickbait titles that will lead to traffic.

    I'm not going do that. Instead, I want to provide an interesting and fair comparison between PHP and Ruby, not to promote any of them. So, let's begin!

    CONTENTS

      Ruby and PHP, what do we have?

      Ruby and PHP are well-known dynamically typed languages that are widely used in web development. You don't have to declare variables before using dynamically typed languages. Both of these languages come with public and private classes, exceptions and a spectacular range of standard libraries in the arsenal. However, these languages are very different from other stuff.

      Advantages and disadvantages of Ruby on Rails and PHP

      I already mentioned the advantages and disadvantages of PHP in previous article, so let’s focus on Ruby this time!

      Ruby is more object-oriented than Python and stronger than Perl as a language. Just like any other programming language, Ruby comes with its own pros and cons. Let’s sort out, which sides of Ruby can be considered as strengths and which can as weaknesses.

      5 Strengths of Ruby

      1. Simple syntax. Ruby is elegant and compact, which made it a great way to build your web application fast. It is very close to a real language, which we are using every day;
      2. It is easy to pick up for the beginners as well as for the experienced programmers;
      3. It is available for free for anyone since it is a part of an open-source collab. Expert users can improve or modify the code anytime they need.
      4. Numerous freely available plugins and gems. With them, the programmer can get an extensive customization and tons of features.
      5. Unlike Java or PHP, Ruby comes with its adaptability, so the developer can research and explore multiple prototypes.

      5 Weaknesses of Ruby

      1.      It is simple to learn and work with if you do some small projects. But if you are working with a large scale project, you have to understand Ruby better and go beyond basics, which makes work more difficult;

      2.      You have to spend a lot of time to understand and learn about plugins and gems;

      3.      It is hard to find a good Railer. However, in Ruby’s defense, it is difficult to find a good programmer in any language these days;

      4.       Slow performance. Let’s be honest: RoR is comparably slower than C languages or Java when it comes to application development;

      5.      ActiveRecord is heavily used in RoR, it is also a hard dependency of the RubyGems.

      Frameworks

      Ruby on Rails is the most popular framework based on Ruby, so it's comparable to Laravel, Symfony, Codeigniter, and other PHP frameworks.

      According to this Google Trend graph, Ruby on Rails holds a solid second position after Laravel in terms of the amount of the number of searches on the Internet. Their curves are notably similar, if not identical. You can ask me “Dude, looks like Rails is not as good as Laravels! What's a point?”. I have a simple and straightforward answer for you. It would help if we look at the market share between Ruby and PHP:

      ruby vs php chart

      PHP share is more than 70%! While Ruby holds only tiny 0.11% fritter. Now, if you sort out this information, you can get that Laravel, the best framework provided by such giant as PHP that holds more than 2\3 of the market is dangerously close to the Ruby on Rails, provided by Ruby that holds only 0.11% market share. That tells us about two possible things:

      1. Ruby on Rails is an ingenious framework that beats Laravel in a fair competition;

      2. Laravel doesn't meet requirements when it comes down to much more complicated stuff, which is typical for big specific startups and business. That's why people are looking for a good alternative, and eventually, prefer Ruby on Rails.

      A lot of PHP projects are struggling because of the absence of a proven, mature web framework. Furthermore, it's no secret that a lot of developers would rather build their own PHP framework, instead of using ready-made frameworks, such as Zend, Codeigniter, Symfony, etc. It can become tangible when you working with a complex project and have to spend hours trying to sort how to use it. Thus, here comes the Rails with its simple approach in the learning process of its framework. As as the business owner or developer you have little to choose and decide on when it comes to organizing, running or hosting your application. That definitely looks like a good thing, and for the most cases, it truly is! That's why Ruby on Rails is so competitive and popular worldwide.

      Property, Method, and Variable

      Ruby doesn't offer different syntax that will provide access to methods, properties, and variables, but  PHP does.

      PHP

      ruby vs php

      Ruby

      ruby vs php

      If you look closely, you'll see that attr_reader :turtle dynamically defines a method, which acts as a getter for @turtle, so bike and turtle are the same things. As a PHP developer, you will be really confused about where turtle is coming from, due to the fact that it doesn't have a method or variable name explicitly defined.

      Such problems rarely occur, but may catch you now and then. Knock-on effect might be caused if somebody on your team change contents from your attr_readerto a full method.

      Now we are going to compare these two languages by their web development capabilities, like development speed, tools, performance, communities and learning curve.

      Debugging

      XDebug is a cool weapon! I'm sure that it is amazing when you use breakpoints: such approach revolutionizes the whole process of debugging of the application and going beyond the classy var_dump () + refreshdebug approach that is commonly used by junior developers. However, setting up XDebug can be an intense headache: if right addon is missing, you have to find it, you have ensured that php.ini is tweaked for a required version of PHP so eventually you can enable zend_extension=xdebug.so for your web version and CLI, then you have to send out the breakpoints (even if you are using Vagrant), etc, etc, etc.

      Ruby using a different approach. It's pretty similar to the way you debug JavaScript in your browser: all you need to do is just add the debugger keyword into the code and that's how you get a breakpoint. After your code executed this line (it doesn't matter if we talking about a unit or integration test or  $ rails server, etc.), you'll get an instant-read eval print loop that can interact with your code.

      Ruby also provides a few more debuggers, like pry and byebug that both are gems and can be installed with Bundler, if you add the next command to Gemfile:

      If you are using Rails, all you have to do is call Debugger. If you don't, call requires "byebug" first.

      Let's take a look at the next example to understand what happens if you put this keyword into your app's code:

       

      You might be wondering, what's a point of this arrow at the 8th line? It is the line the read eval print loop is running, and you are allowed to execute the code from this point. From there, @articles is not defined. If you wish, you can call Article.find_recent to see what's happening. If an exception occurs, just type next to skip this line or step if you need the execution of the next instruction.

      It is pretty handy, especially when you are out of ideas why this goddamn piece of code is not giving the right output. You are able to inspect each and every value until eventually, you sort out where is the culprit.

      Development Speed

      Developers can add PHP scripts right into HTML, in other words, they don't need a web framework for execution. However, without using PHP frameworks you are not able to run your application quick enough and get it up. A lot of customers ask for features that consist of long code sheets. That means that a programmer has to spend a lot of time to review and debug the code.

      With Ruby, you can build web apps much quicker. Web framework Ruby on Rails comes with a wide range of handy plug-ins and gems that can speed up your working process and make database operations much more simpler.

      Useful Tools for the Developer

      Ruby comes with a mature and solid web framework called Ruby on Rails. It constantly evolves and obtains new features in accordance with trends in the web development field. However, Rails' advantages are limited by its language. On the other hand, PHP can offer a wide range of CRMs, libraries, toolkits and web frameworks. With Joomla, Magneto and, of course, WordPress you can easily build a website for general purposes. PHP also provides a big number of development and testing tools that could help fit the project needs. That's why PHP is so popular in terms of web development if you match it with other programming languages.

      Performance

      PHP 7.0 comes with built-in capabilities for web development and modified in order to improve the performance. Despite this fact, web frameworks provided by PHP still range from the delivered performance.

      Meanwhile, Ruby shows good results at speeding through multiple requests second after second. That will cost a big memory consumption that slows down web applications. As a developer, you have to change the runtimes if you want to compensate for this slowdown.

      Community

      Both PHP and ruby can boast their big community that provides a constant support. These communities could be really helpful in numerous situations, due to the huge number of lively supporters of each existing framework. From a developer's perspective, there are always people ready to help and give an advice for any technical issue developer may have.

      This additional informal layer is really important and can be considered an extra point to chose PHP  as a favorite server-side tech. Each PHP developer is calm if he stuck because he knows that the answer is coming pretty soon. It's possible because of the Golden Horde community that consists of thousands and thousands of minds that will help you overcome your problem. And when even the time is on your side, you understand that you can deal with anything.

      In this part, PHP is the outright winner. Sorry, Ruby.

      Learning Curve

      PHP is a good choice for a beginner compared to other languages. There are also tons of free video tutorials, programs and even games that help beginners pick up the main ideas and concept of PHP. Despite the fact that Ruby is much more complicated, it is pretty good in a long-term perspective.

      The Bottom Line

      So, what do we know?

      PHP has a friendly learning curve in the web development field in contrast to Ruby. Furthermore, it's simpler, comes with a huge available resource base so you can meet your goals faster.

      Despite this fact, working with Ruby can be much more enjoyable than with PHP. The ecosystem of Ruby provides a more detailed and superior toolkit for developing web apps. It is understandable why PHP fans do not share this opinion, and that's totally okay.

      Your own choice should depend on your own priorities and features that will be suitable for you in PHP or Ruby. Ruby is both flexible and powerful language with a miraculous web framework in Rails. The problematic part is that it is difficult to learn and as a developer, you need high-level skills. Due to this fact, it is harder to find a good Ruby developer.


      Average rating:0 of 0