In today’s article, we’re going to take a look at the three popular languages: PHP vs. Ruby vs. Python

We will check how they work, how they differ from each other, who uses them and how popular each language is.

At the end of this article, you will have an idea about which one to learn and which the best option is for each particular task.

difference

PHP: Most Popular Scripting Language for the Web

PHP (Hypertext PreProcessor) is a server scripting language designed by Rasmus Lerdorf, a powerful tool to create dynamic and interactive websites. It is fast, flexible, widely-used scripting language for everything from a simple blog to the most popular and dynamic websites in the world.

test

Advantages of PHP

  • Free software released under the PHP license
  • Easy to learn (Short learning curve)
  • Large community of users and developers
  • Provides extensive database support
  • Offers great number of available extensions and source codes
  • Allows execution of code in restricted environments
  • Offers native session management and extension API
  • A great alternative for competitors like Microsoft’s ASP (Active Server Pages)
  • Can be deployed on most web servers
  • Works on almost every operating system and platform

Disadvantages of PHP

  • Not suitable for making desktop applications
  • Error handling is traditionally poor
  • Global configuration parameters can change language semantics, complicating deployment and portability
  • Objects are CallByValue by default, which is the opposite of most languages and catches lots of programmers off-guard
  • Generally considered to be less secured than the other programming languages

Who Uses PHP?

  • Zend
  • Yahoo
  • Facebook
  • Google
  • NASA
  • W3C

Popularity

As of January 2013, PHP was installed on more than 240 million websites (39% of those sampled) and 2.1 million web servers.

Syntax

A PHP script starts with < ?php and ends with ?> The default file extension for PHP files is “.php”. A PHP file usually contains HTML tags, and some PHP scripting code.

 <?php // PHP code goes here ?>

Python: General Purpose Programming Language

Python is a widely-used high-level (but it also used in a wide range of non-scripting language) design for programmers to express concepts with fewer lines of code. It was conceived in the late 1980s and was implemented by Guido van Rossum.

Python code resembles the pseudo-code just like all the scripting languages. The elegant design and syntax rules of this programming language make it quite readable even among the multi-programmer development teams. It supports multiple ways of building the structure and elements of computer programs, including object-oriented and functional programming.

python

Advantages of Python

  • Easy and quick to learn
  • Runs in multiple systems and platforms
  • Readable and organized syntax
  • Offers rapid prototyping and dynamic semantics capabilities
  • Great community support
  • Easily construct applications by testing and importing crucial functions
  • Reusability through carefully implementing packages and modules
  • Object Oriented Programming-driven

Disadvantages of Python

  • It doesn’t really do multi-processor/multi-core work very well
  • Smaller pool of Python developers compared to other languages, such as Java
  • Absence of a commercial support point, even for an Open Source project (though this situation is changing)
  • Database access layer limitations
  • Reputed to be slower than languages such as Java

Who uses Python?

  • Yahoo Map
  • Zope Corporation
  • Linux Weekly News
  • Shopzilla
  • Ultraseek

Popularity

Since 2008, Python has consistently ranked in the top eight most popular programming languages as measured by the TIOBE Programming Community Index. It is the third most popular language whose grammatical syntax is not predominantly based on C, e.g. C++, C#, Objective-C, Java.

Syntax

Invoking the interpreter without passing a script file as a parameter brings up the following prompt:

$ python
Python 2.4.3 (#1, Nov 11 2010, 13:34:43)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] on linux2
Type <"help<", <"copyright<", <"credits<" or <"license<" for more information.
<><><>

Typing the some text to the right of the Python prompt and press the Enter key will output the text:

<><><>print <"Put some text here!<";

Job Demand

Based on Jobs Tractor which analyzed more than 45,000 developer jobs advertised on Twitter during the past 12 months, the results are the following:

  • PHP8,238
  • Ruby 2,937
  • Python1,587

Although PHP still has the higher statistics on this site, remember not to use statistics as the basis for learning or using a programming language.

Ruby: Interpreted, Pure Object-Oriented Programming Language

Ruby (programming language) runs with Ruby on Rails or simply rails, an open source, full-stack web application framework. It is a dynamic, imperative object-oriented programming language developed by Yukihiro Matsumoto in Japan.

It was influenced by Perl, Eiffel and Smalltalk. It a has dynamic type system and automatic memory management.

ruby

Advantages of Ruby

  • Open-sourced
  • Works on multiple platforms
  • Can be embedded into Hypertext Markup Language (HTML)
  • A Very High-Level Language (VHLL)
  • Offers encapsulation of data methods within objects
  • Pure OOP (Object-Oriented Programming)
  • Super advanced string and text manipulation techniques
  • Can easily be connected to DB2, MySQL, Oracle, and Sybase
  • Scalable and big programs written in Ruby are easily maintainable
  • Has a clean and easy syntax that allows the new developer to learn Ruby very quickly and easily
  • Ability to write multi-threaded applications with a simple API
  • Offers advanced array class
  • Able to write external libraries in Ruby or C
  • Allows “reserved word” to be used as an identifier as long as the parser doesn’t perceive an ambiguity
  • Better security features
  • It has a debugger
  • It has flexible syntax
  • Powerful string handling

Disadvantages of Ruby

  • Learning it can be difficult
  • Lacks informational resources
  • Slower processing time (CPU time) compared to other programming languages
  • Development and updates are slower

Who uses Ruby?

  • Google Sketchup
  • 37signals
  • GitHub
  • Shopify
  • Indiegogo
  • ThemeForest

Popularity

According to the Ruby website, it is ranked among the top 10 on most popular programming languages worldwide (such as the TIOBE index). Much of the growth is attributed to the popularity of software written in Ruby, particularly the Ruby on Rails web framework.

Syntax

All Ruby files will have the extension “.rb.” Using the Ruby interpreter available in /usr/bin directory, you can run Ruby codes.

#!/usr/bin/ruby -w
puts "Put something here";

Time to Ruby dooby do! It can take a lot of time, and be quite boring, to learn a new programming language. A .Net developer will jump up and say why should I even learn it? I am a professional .Net developer and my day job doesn’t give me time (and scope) to learn a new programming language.

But, it isn’t like that. You learn a lot with new programming languages especially when they are a refined version of other optimized ones. Ruby is that sort of language. I agree that the transition from being a noob developer (in a particular programming language) to a pro is arduous but you will appreciate the experience. As of now all that I can do is let you guys know that if you stick around with Ruby, then you won’t be at a loss. Just be positive.

What is Ruby?

Ruby, as I said before, is a refined combination of various programming approaches. Ruby is the perfect mixture of python’s easy to understand flow, Smalltalk’s elegance and Perl’s easy to learn syntax style. Ruby is a high-level object-oriented programming language (as is the case with most of the programming languages these days) which came into existence in mid-1990s in Japan. With time Ruby has started to become more dominant in the U.S. and Europe too.

Ruby is famous for its dynamic type system and automatic memory management. By dynamic type, I mean that most of the type checking in a Ruby program is done during run time which means you don’t have to worry about integer and string types. Ruby will do that for you. We will see more about this in a short example later.

The basic purpose of launching Ruby was to make it easy for humans to interact with machines and understand codes. Yukihiro Matsumoto, the father of Ruby, insists that Ruby was designed for programmer productivity and not for machine optimization.

Often people, especially computer engineers, focus on the machines. They think, “By doing this, the machine will run faster. By doing this, the machine will run more effectively. By doing this, the machine will something something something.”

They are focusing on machines. But in fact, we need to focus on humans, on how humans care about doing programming or operating the application of the machines. We are the masters. They are the slaves. – Yukihiro Matsumoto

What is Rails?

Rails is an extremely productive application framework written in Ruby by David Heinemeier Hansson. It is said that developing a web application on Rails is ten times faster when compared to that of a Java-based web application framework. Rails is open source (of course!) Ruby based framework that can be used for easy (and fast) database integration.

Rails is famous for over-the-top ideas which resulted in shunning conventions and picking up a dynamic programming structure. The basic application code and the updated database will always contain everything that Rails will require to execute a program from start to finish.

A Basic Ruby Program

See how interesting (and easy) things will get after this:

Code:
personal = “I don’t love my girlfriend”
puts personal

Output:
I don’t love my girlfriend

Yep! That will actually be it to print an output in console. No initialization, semicolons and main methods.

Now, let us see a quick difference in programming between PHP and Ruby when we have to reverse a string:

PHP:
strrev(“string”);

Ruby:
“string”.reverse

Voila! Your string will be reversed in no time. See the difference in effort in both the programming languages. A Ruby based programming language will make it easy for you to write a program. It is more like writing in English than in coded language. It is the future of programming languages.

Advantages of Sticking with Ruby (and Rails)

I know the world of Ruby is big and I haven’t scratched the surface of it but a blog post will prove to be overly small to dive into the world of Ruby. Henceforth, let us directly go through the advantages of Ruby:

  • Elegant – As I have pointed out before, this happens to be the strength of Ruby. As a programming language Ruby is super elegant and almost like English. It is this similarity to English that makes it easy for noobs to take on Ruby without being afraid of it.
  • Concise and Powerful – Our example above itself explains how concise a Ruby code can be. As short as it can get. Also, Ruby is as powerful as any other language as it is Object Oriented High-Level Programming Language just like other trendy programming languages.
  • Never Reinvents the Cycle – Rails (based on Ruby) is one programming interface that will never let you reinvent the cycle. It generates codes that can be reused over and over.
  • Built in Testing – Rails is famous for its harness and fixtures which act as supporting codes that will make it easier for programmers to write their test cases. Also, Rails creates simple test stubs that can be extended by programmers.
  • Dev, Test and Prod Environments – Rails smartly starts your project in three different environments namely Dev, Test and Prod. All three environments behave a little differently from each other and each complement the original software development life cycle.

Conclusion

You are not done yet. You really aren’t. Hang around with Ruby and keep riding the journey on Rails. Someday you will call yourself a Ruby Pro and who knows, your article might just come in handy for me. Ruby has its disadvantages, and the most obvious of them all is the that it is very new to this game. It is still evolving and has a lot to prove. Still, we know that it is going to go places.

Now, it is in our hands. Either we can wait and let it grow or else jump in and evolve as an expert when there is high demand for Ruby professionals.

If you prefer using proven tools and aren’t that hardcore programmer, read this article about what programming languages to learn.

So Which Is the Best Programming Language to Use and Learn?

The answer you’ll have from the most of the programmers is: “You can do everything with all of them”. All of them are good options. There is no real good or bad answer. It always depends on what you want to accomplish.

If you take a step to learn a programming language, chances are, you will use built-in frameworks to use for your projects. Basically, a web framework makes it easier for you to develop your application. Most sites have a common set of functionality (like handling sessions and data validation), and a framework is something that prevents you from re-writing this each time you create a website.

PHP has several number of developed CMS frameworks available if you already dived in learning it. The most popular PHP CMS are WordPress, Joomla, and Drupal with most of them having loads of plugins. You can write new ones easily with a few days of patience and going through the tutorials.

There are others that are quite good too, but using the popular ones increases your probability of finding support quickly or finding that plugin you might need. For Python, there is the Django and CherryPy web framework, which give you quite a good tool kit.

If you go for Ruby, I think you’ll be a bit more limited (since that the language is newer) but its basic framework is Rails. You also need to consider which language offers the best support so that you can find answers quickly in case you encounter problems with your codes.

  • PHP is the best language for creating HTML pages
  • Python is a general purpose programming language. It can be used to build almost anything from web apps, crawlers, daemons, and desktop GUI applications.
  • Ruby is best at creating web application of data entities quickly so that you can focus on the special functionality rather than on the query operations: insert, update and delete.

And that’s it. Hope you gothad an overview of which programming language to learn.

Editorial Team

Written by Editorial Team

  • Gaius Gracchus

    Ruby is on the way out. The trend is clear.

  • Naufra

    Ruby is newer? mmm, only two months than PHP and one month than Python. PHP is good for HTML pages? I don’t need PHP for that, just HTML. PHP can do lot of thing as Ruby, even desktop apps so I think your study is not right. Simply you are a Ruby lover because you don’t want to code with a professional lenguage as PHP or Python.

  • Pouya

    You are not correctly comparing them!
    What I see is,
    First you compared PHP to nothing! so PHP is better of course!
    Then you compared Python to Java! and of course it isn’t about this article,
    Third you compared Ruby with itself! so it’s don’t make sense too.
    At my sight, all this three languages are good, and of course have cons and pros.
    What I learned after working 7 years with Python and PHP, and after doing some deep researches for Ruby, is that :

    1- PHP is best fitted for small to medium web applications, it’s easy to setup, and for a blog, shop or a small business/website it has WordPress, drupal, Magento, etc, and on the other side if your application needs more unusual abblities, you have Laravel, Symfony, CI and much more frameworks to implement things yourself,
    But when it comes to a big application, you should consider switching to another one, as it will became slow and memory hungry.
    So if you have a small project go for it, if not, it’s your choice! you can kill yourself also.

    2- Python can do everything you need, you can count on it if you wanna develop a big web application with medium to high traffic, Instagram and Youtube also use it!
    But when it comes to small or medium web applications, you’re better move to PHP as you have a large set of tools for these things there and almost all of web hostings support it.
    Python is also easy to learn with a easy syntax, but when you want to do big things, you should learn more than what you need in PHP.
    So if you have a small project, go for PHP, and take advantage of tools it have. and if you have a big project, you can then compare pros and cons of python, Java and other competitors.

    3- Ruby is also good for medium to “somewhat” big applications(think about github), but it’s also slow and harder to learn!
    When you work with ruby and rails, you will see how things go fast! it’s perfect when it comes to prototyping and/or fast developing a project.
    So when it comes to a big project that can change it’s needs every moment, Ruby is good for you!

  • Mariusz

    This article is way inaccurate

    In case of Python: It does support multi-processing, it doesn’t support multi-threading. It’s not a drawback, because, well it’s not really needed for anything. Modern web servers for python spawn long-running pool of processes which handle requests. There’s no place for threads. “Absence of a commercial support point” – what for? You have a strong open source community willing to help for free, and yet you want to pay for commercial suppprty? Also what “Database access layer limitations” are you referring to What database layar limitations? Every mainstream database engine is supported in Python.

    In case of ruby: “It has a debugger” – Python and PHP have debuggers too! Its 2016 for god’s sake.

  • nobody

    I think Google doesn’t use php, but Python.

    • Denis

      Totally agree with you

  • Razor

    10? no no, Ruby is ranked 13 according to the TIOBE Index. It’s now less popular than Perl which is pretty sad. http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html Ruby popularity is falling fast, so Ruby is a waste of time to learn at this point. You can see developers dropping it. Python is moving up in popularity and PHP is moving down.

    • Spook McGov

      As far as rankings…it is cyclic and depends on what part of the world you take your polls nm every 4 years there is a “profound” “change” which basically coincides with the next batch of college grads so all these numbers are just fluff. Professionals work with whatever gets the job done as conveniently as possible, usually whatever they have worked with the most. It doesn’t matter if it is Fortran running on a PDP or some 4th gen parsing Swahili.

  • Andrelle

    Really great post,

    I have only worked with PHP and python so far, both are very good programming languages, but I like working with PHP rather than python. Python does not have the quantity of developers that PHP has so its harder to find tutorials and support online when coding with Python.

  • Anaxamaxan

    For the record, 37Signals and Basecamp are the same company, or rather the former is the company and the latter the product. Regarding PHP’s frameworks: you listed CMS systems, and aging ones at that, not frameworks. Drupal is closest to a framework, and is about equivalent to Django in Python. There are probably a hundred times more frameworks and CMSs in PHP than in other languages, some of them actually quite good. Some modern frameworks in PHP include Symfony, Laravel, and Aura. Beginners would do well to start with Laravel, which has a rapidly-growing body of educational material growing up around it, and most of it encourages good programming practice unlike some of the old WordPress or Joomla materials you’ll still find via Google.

  • I’ve decided Python is going to be my general language, I love the design and standard library. However, for web programming PHP is the winner. Ruby is more boxed in (likely why it is more secure) but it is also beautiful I admit.

    But PHP has ease of use anywhere, portability, lots of useful functions, and is very flexible. I think with languages like PHP/JavaScript, you need to instill more discipline. But once you do they become better languages. I will use PHP for my web programming (my site is also WordPress based). But if Python were as easy to use for the web….I’d easily prefer it for web programming too.

  • tux

    Should be Lerdorf right? I like the 3 languages but focusing more on PHP.

    • Rean John Uehara

      Fixed! Thanks :D

  • Mathias Grimm

    Good article.

    You forgot Wikipedia as a great php case.

    I am a php developer but I’ve developed using the 3 languages.

    PHP is not an OO language but offers very good support of OO and better OO support over python.
    In general python uses a convention for doing the same php does natively as a feature.

    Rails has a very different syntax, much different than any other common C syntax descendent

    In PHP, as in Ruby, you also can write external libraries in PHP or C

    PHP still have a lot of things from the past, like convention-less functions names/arguments but every release they are improving and removing old things as well.

    I really like the 3 languages but prefer to develop with php.

  • Mathias Grimm

    Good article.

    You forgot Wikipedia as a great php case.

    I am a php developer but I’ve developed using the 3 languages.

    PHP is not an OO language but offers very good support and better OO support over python.
    In general python uses a convention for doing the same php does natively as a feature.

    Rails has a very different syntax, much different than the common any other common C syntax descendent

    In PHP, as in Ruby, you also can write external libraries in PHP or C

    I really like the 3 languages. PHP still have a lot of things from the past, like convention-less functions names/arguments.

  • C. Holanda

    After 4 years working with PHP, I must to admit that the code is only maintanaible if you use some MVC framework or other code pattern.

    Trying to just use plain PHP and HTML to create your pages will drive you crazy as your project reaches 10+ files.

    But its an awesome language thought. It have some lack of patterns for function names and other quirks, but hey, which language is perfect? Every langage have its caveats and advantages. And for web, yes, PHP takes a HUGE advantage.

    • Carl

      I disagree with your first sentence. The frameworks are also just php – so it make no sense to say you cannot create good (or maintable) code with plain php.
      It is more difficault to create a good structure without them but this is not the fault of the language at its own.