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.
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.
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?
As of January 2013, PHP was installed on more than 240 million websites (39% of those sampled) and 2.1 million web servers.
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.
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
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.
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!<";
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:
- PHP – 8,238
- Ruby – 2,937
- Python – 1,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.
Advantages of Ruby
- 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
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.
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:
personal = “I don’t love my girlfriend”
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:
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.
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.
This post may contain affiliate links. See our disclosure about affiliate links here.