Ruby and PHP: which is the best fit for your startup?

Dmitry avatar
Dmitry Chekalin
in Technology

So, you want to start a new project from scratch, and you’re looking for the best web development platform. When it comes to web programming languages, it’s not that easy to make a choice which complies with your requirements.

In the following article, we're going to compare Ruby vs. PHP in 2018 and find the main pros and cons of critical aspects of both technologies. The latest versions of languages are Ruby 2.5 and PHP 7.2. All statistics shown below is relevant for June 2018.

Both languages are more than 20 years old, mature and proven in production. A lot of great products were created on their basis. So let’s look at these technologies from the beginning.

History

PHP invented as an HTML templating language in 1994 is now a reliable web development technology which can be used even for general purpose. In contrast, Ruby was released in 1995 as a general purpose object-oriented language but is now mainly applied in the web development due to Ruby on Rails success.

Although both programming languages initially had different aims, currently they are highly competitive technologies on the web development scene.

Philosophy

One of the main differences between Ruby and PHP relies on their philosophies.

The primary objects of Ruby were pleasure and productivity of developers who wish to work with stylish, elegant and flexible language.

I believe people want to express themselves when they program. They don't want to fight with the language. Programming languages must feel natural to programmers. I tried to make people enjoy programming and concentrate on the fun and creative part of programming when they use Ruby - Yukihiro Matsumoto, Ruby creator.

That’s why this language syntax is so elegant and beautiful. Developers love it and enjoy programming in it.

Coming back to PHP, it was primarily written for the personal purpose of Rasmus Lerdorf, its creator. Initially, he just wanted to count the number of visits of his online resume.

Well, I didn’t plan PHP. I think in terms of solving problems, not in terms of software projects. I actually hate programming, but I love solving problems - Rasmus Lerdorf

Soon, the simplicity of PHP attracted a lot of programmers in the web development world, and within several years it evolved into the first mass-market scripting language. But popularity had a reverse side. Due to the rapid growth, it was tough to create a good language design. A lot of articles were written in that manner as "PHP: a fractal of bad design".

Many developers switch from PHP to Ruby or Python because the design of the two latter is much better.

Comparison list

We’re going to compare the following aspects of both web technologies:

  • Learning Curve
  • Frameworks
  • Popularity
  • Community
  • Cost of developers
  • Speed and performance

So, let’s start our brief survey.

1. Learning Curve

While studying Ruby or PHP, both technologies have a short learning curve. There are a lot of online interactive tutorials, for example, Learn PHP or Try Ruby.

Ruby code example:

1
2
3
4
odd_numbers = [1, 3, 5, 7, 9]
odd_numbers.each do |odd_number| 
  puts odd_number
end

PHP code example:

1
2
3
4
5
6
<?php
$odd_numbers = [1, 3, 5, 7, 9];
foreach ($odd_numbers as $odd_number) {
  echo $odd_number . "\n";
}
?>

As you see, PHP example has an open tag <?php. Now developers don’t mix any other parts of codes (like HTML or CSS) with PHP as before but still have to use such open tag at the beginning of the file. This action confirms precise compatibility with the oldest versions of the language.

Unlike the languages, frameworks have the steep learning curve. Even for experienced developers, it’s not that easy to effectively operate with several frameworks at the moment.

2. Frameworks

Let’s take a look at web frameworks.

In this table, you can find main frameworks of both languages and the number of the Github stars. As it shows, Rails is the front-runner in the world of Ruby, while in PHP world, Laravel took over the show.

Ruby Frameworks Github stars PHP Frameworks Github stars
Ruby on Rails 39k Laravel 43k
Sinatra 10k Symfony 17k
Hanami 4k CodeIgniter 16k
Padrino 3k Yii2 12k
Phalcon 8k

While Rails is dominating over other Ruby frameworks, competition between PHP frameworks is much stronger because PHP gained popularity long before any other web development languages did it.

From the other side, Rails has gained fame of the first mass MVC framework in the web. A lot of frameworks in many languages including PHP have copied ideas from Rails and Laravel was among them.

3. Popularity

There is a variety of online resources providing statistics on the prevalence of these two programming languages.

3.1 Sites written in Ruby and PHP

As W3Techs statistic cites, PHP is an absolute leader in the number of sites written in it.

W3Techs statistic languages use statistic

(The data are valid for July 2018)

The total percentage of PHP use comprises 83.5%. However, it is necessary to admit that a huge part of the PHP market is composed of such CMS as Wordpress, Drupal, and Joomla.

3.2 Sites built with frameworks

BuiltWith.com shows that Rails framework is more popular in comparison with PHP frameworks.

Framework Top 10k sites Top 100k sites Top Million sites The Internet
Ruby on Rails 850 4,184 13,641 1,883,369
Laravel 118 792 5,438 573,932
CodeIgniter 32 376 4,154 408,429
CakePHP 41 194 1,024 90,979

As we see, the biggest numbers in all categories has sites build in Ruby on Rails.

3.3 Programming languages ranking

Spectrum statistics "The top programming language” points that the rate of Ruby for web development is higher than PHP.

Spectrum statistics The top programming language

(The data are valid for July 2017)

As stated by Github report, Ruby was more popular than PHP by the number of pull requests in 2017.

Github report 2017

Overall, although PHP is more popular among all sites, Ruby (and Rails) prevails over PHP by the number of developers’ activity on the Github and websites built with frameworks.

Many PHP projects were formerly written without any framework or reinstalled as copies of Joomla, Wordpress and Drupal systems. Whereas, a vast amount of custom projects and startups was created with Rails.

4. Community

A community built around a programming language represents an excellent force for developers.

Both technologies have great communities. One of the main distinctive features in Ruby vs. PHP comparison is that Ruby has one community based on the Rails framework, while PHP has numerous communities fragmented depending on a framework or existing products.

In general, we can highlight three branches in the PHP community:

  • Developers who work with Laravel, Symfony, etc. frameworks and create projects from scratch.

  • Programmers who exclusively engineer in Joomla, Wordpress or Drupal systems. They are involved in the customization process of those products for their clients.

  • Developers who are aimed to maintain and support websites written before the emergence of modern PHP frameworks.

In this regard, it is fair to compare Rails developers and those PHP developers who work with frameworks. Consequently, the number of Laravel developers, for example, are less than Rails programmers.

In contrast, we can’t downplay the big circle which the strong Ruby on Rails community formed on Github. Together they focus on a robust and a high-quality development, making a significant contribution to collaborative efforts.

5. Cost of developers

There is an opinion that PHP developers are cheaper and could be found easier than Ruby (Rails) developers.

The truth is that the price for the developers’ services depends on their qualifications, and the highly qualified programmers are well paid in both languages.

Actually, at the moment "PHP developer" term doesn’t exist as before. Right now we can talk about Symfony or Drupal developers, for example. And the cost of Rails and Laravel / Symfony engineers is approximately the same.

Below you can find Indeed statistics concerning job postings for both web technologies.

Indeed statistics Ruby Php Ruby on Rails Laravel

(The data are valid for July 2017)

As it is shown, the demand level for the programmers of both languages was nearly the same.

But at the same time, demand level for Rails developers is higher than for Laravel which is the top PHP framework.

6. Speed and performance

Now, all people in web communities do is compare Ruby vs PHP technologies performance.

Having a look at the history, we can find that Ruby and PHP used to have approximately the same speed at some points. But now PHP 7.2 speed is significantly improved. It is much faster than the previous versions. Besides, there’s a room for growth, since 7.3 is on the way now available in alpha version. Good work, now the ball is in Ruby court.

On releasing Ruby 2.5 in December 2017, the community introduced up to 10% performance improvement comparing to Ruby 2.4 and presented a lot of other significant updates. Now the Ruby community is looking forward to release Ruby 2.6 available in preview now. Equally important is the Ruby 3x3 initiative which tends to triple the Ruby performance in its third version.

Although the developers tend to improve technologies performance, it’s not the reason to opt for any language just because of its speed. A hardware upgrading would be a more practical solution to the situation.

Advantages

Each of the given programming languages has its unique aspects and unique energy, serving the purpose for which they were invented. So let’s take a glance at the strong sides of both.

Ruby PHP
Open-source Open-source
Short learning curve Short learning curve
Amazing developers` community Huge developers` community
Great language design Many frameworks available
Rails framework is the number one PHP7 is very fast
A lot of information resources available A lot of information resources available

Disadvantages

Just like the strengths, there are always some pitfalls in each language. Anyway, there’s still room for improvement.

Ruby PHP
Runtime speed could be faster Weak language design
Rails domination makes competition among frameworks weak Problems in maintaining legacy applications

Summary

When choosing between these two programming languages, you won’t find a definite answer which is the best one. Both of them have benefits and drawbacks.

Now PHP has improved performance, but its language design is still weak. Ruby needs some speed increase but has an elegant design and syntax. They both allow producing beautiful and robust web applications.

At Codica we chose Ruby because we like the philosophy, design and simplicity of this language.

But regardless of which language we use, the primary mission for us is helping our clients gain their business aims. As a cutting-edge company, we always deliver business-tailored solutions which our customers enjoy using.

Have an unsolvable problem or audacious idea?

Contact Us