14 descriptive reasons why Ruby may be better than PHP


Picking a language for a programming project is never an easy task. Depending on your choice, your hosting costs can differ, the documentation can be helpful or nonexistent, and your choice of IDE or other programming tools can change. This is especially true with web programming projects. Because you are not always in control of the environment where one’s application will be run, it is important to pick a language that can adapt to many situations. Ruby is a better language than PHP for the following reasons.

1. Human-readable code

Yukihiro Matsumodo wanted to create a language that was designed for programmer functionality. By keeping naming consistent and keywords sensible, he was able to do so.

.

2. Principle of least surprise

it is designed in such a way that the language minimizes confusion for experienced users. Methods for different objects, if they do the same task, are generally named and capitalized the same way. This makes it less necessary to constantly refer to the documentation, which leads to faster coding.

.

3. Community maturity

The community is better able to give concise, coherent answers since the community is a little more learned. As it is generally not a first language the people in the community already have experience coding and helping others.

.

4. Rails

Creating a web application complete with database is as easy as typing in a few simple commands. The web app framework community for PHP, on the other hand, is fragmented and far less organized.

.

5. Objected Oriented Programming

Ruby was initially designed to be object-oriented. Robust, organized programs are easier to create with an object oriented language.

.

6. ActiveRecord design

using Rails, it is possible to map database records/tables to objects, which makes creating and handling persistent data extremely easy.

.

7. Easier to install

Gem makes it extremely easy to download and install different frameworks and applications to use in your code. PHP, however, makes you find, download, install, and configure all extensions yourself.

.

8. MVC

The model view controller architecture is a common system that all software engineers use. Rails is designed around this concept, so it gives future maintainers of your project an advantage when trying to understand your code.

.

9. JVM support

Whenever there is a JVM installed, you can use JRuby to run your programs. You can also integrate your project into a Java application if you would like. This is especially useful if you are already writing a large application in Java, and are just looking for a scripting language to augment some functionality.

.

10. Formal namespaces

Organizing code is much easier when you can group classes into namespaces.

.

11. Pre-installed on certain operating systems

It ships with OSX 10.5 (Leopard), so you can get started coding immediately.

.

12. Interactive shell

It comes default with a robust interactive shell that makes it easy to experiment with code. Instead of typing out some code, saving it to your sever, opening up your internet browser, and navigating to your page, you can just open up the console and type.

.

13. Maintainability

Less code (assuming the complexity is the same) means there is less to get confused about. Forcing MVC on you (through Rails) also helps developers maintain your code. Unit testing has also been tightly integrated from the beginning of the language, so it is more convenient to create/use unit tests for regression tests.

.

14. Everything is an object

Not having primitives makes code easier to handle. Instead of making sure something is an object and then executing it’s methods, one can just execute the method.

.



Comments

11.07.10

These are all just statements without evidence. What about the Performance? MVC with Rails, what about Symfony, CakePHP and all the others? Collectively, not a good contribution…

11.07.10

hmh, didnt know, that activerecord and mvc is built in ruby language.

11.07.10

1.Totally subjective, Ruby is unreadable to me compared to PHP.
2.This is programming rule not language one
3.Give an example where PHP community had least maturity.
4.Plenty of frameworks, cms and libraries available.
5.I thought PHP had Object-Oriented Programming. Most of websites don’t even need OO at all but basic scripting. OO would make their job much harder to produce.
6.I bet there are solutions but what RoR functionality has to do with PHP vs. Ruby?
7.There much more chances that web server administrators can install PHP related addons rather than Ruby’s because PHP is much more widely used thus more web admins experienced with it.
8.Framework (RoR) has MVC not the language.
9.I bet there are solutions for that while JVM not the most important issue for web developer.
10.I thought PHP had Namespaces
11.This is the most silliest. PHP comes on most of Linux based servers which are used to host and develop applications as PHP rule the scene. .NET comes on any Windows based platform which rules the market. Even Python has more systems installed with that Ruby.
12.User IDE with debugging for this not an interactive shell.
13.Odd language that doesn’t look anything near most common C based languages, what can be less complex.
14.Isn’t that part of OO?

To sum it up, i’m far from being PHP developer but it is much widely used. Ruby and RoR is just a keyword trend that everyone likes. Do your programming anywhere you like, you will probably get almost identical results but all those comparisons are lame, especially when real comparison haven’t been made at all.

11.07.10

PHP has an interactive shell (12), namespaces (10), it’s installable by repositories in every Linux distributions (11). has pear instead of gem (7) and has deprecated Active Record as it is a solution that couples too much to the relational database (6). Oh yeah, but these graphics are good.

11.07.10

Not a bad list, but don’t you think comparing PHP sans a framework to Ruby with Rails is a little disingenuous?

You could argue that Ruby pretty much only having Rails makes it easier to get started, as there’s a unified community (vs PHP’s fragmented one with a dozen or more different frameworks), but add in almost any of the major frameworks to PHP and suddenly you have MVC, OOP, ORM/ActiveRecord, just like Ruby+Rails.

11.07.10

Ruby has a lot of features that make it better than PHP as a language – none of which you mentioned in this article

11.07.10

I use both languages PHP and Ruby with Rails, but this article is plain subjective.

If you want to compare something you must look at it objectively…

11.07.10

Spoken like a true RoR fanboy. Most of your points are invalid/wrong.

11.07.10

1. the syntax of ruby is more readable. the absence of parenthesis and hash parameters without graph make the code more readable.
Hash and Array are more fast to write that in php.
Ruby is born for DSL e Metaprogramming. write a DSL in ruby is much simple. Try to make the same things in php and try to confront the 2 dsl.

2. Constants, variables, global variables, instance variables and class variables has their prefix and mode of writing.

3. Much ruby programmers come from php. generally ruby isnt’ the first language that a programmer learn. The syntax is more complex of php, so a programmer must be more skilled for learning ruby. In 100 php programmers 60 know the basic language 40 the oop and the 10 of oop know functional paradigm in php.

4. is true many program. any program has is orm, is library template is controller, is system of authentication , system of caching ecc…..
There are many applications in php but also many fragmentation og library and people as community.

5. Ruby is oop from the orgiin. PHP has introduce oop in php 4 and after in php 5 a better oop.
Ruby is oop, true oop like smalltalk. in ruby all is object (with some exception). concept that there are in ruby of metaprogramming, metaclasses ecc ecc in php are not existence.

6. the response is metaprogramming applied to activerecord. Learn how activerecord function and try to learn the equivalent library in php. And you will see the difference of implementation on 2 languages.

7. is true but with passenger a bundler a deploy of an application can be really fast. with warbler the deploy on tomcat ins really fast.

8. true

9.you should try rails on jruby i think first of say this.

10. yes from 5.3. many libraries and framework are write for compatibility in 5.2 PHP 5.3 is born in 2009. are passed 2 years. Drupal 7 dosnt support php 5.3. Zend and symfony are in alpha/beta why must wait the middle of 2011?

11. true
12. is possible use debugger also in ruby. what is speaking here with live code is REPL.

14. the response is learn smalltalk

11.07.10

1. Subjective. Ruby is as unreadable as Perl to me
2. Can’t tell for Ruby itself but RoR has a lot surprising automagic
3. Your blog post clearly shows that it’s not mature (and we all know how elitist the Ruby fanboys can be)
4. all of the above squared and it’s not like PHP was lacking any frameworks
5. PHP has solid OO support.
6. AR is not suitable as an ORM. See http://kore-nordmann.de/blog/why_active_record_sucks.html
7. how is PEAR more difficult than using Gem?
8. MVC is just a pattern and not a difficult one to implement. There is plenty of MVC frameworks in PHP
9. PHP had a Java Bridge long before Ruby was envogue. Zend Server has one too.
10. PHP 5.3 has namespaces.
11. PHP is readily available on a wide range of platforms
12. Not as fancy as Ruby’s but doing php -a on CLI will run PHP in interactive mode
13. Maintainability does not stem from a language or a particular framework but by design. And tightly coupled monoliths like RoR are not exactly known to be maintainble.
14. subjective. I’ve never had any issues with scalars

11.07.10

9. PHP runs on JVM. Does Quercus ring a bell?

11.07.10

Hey Steve

I’m a Rubyist – absolutely loathe PHP – but I can’t find I agree with all of your arguments here. As some of the other posters have said, MVC, interactive shell, etc are available to PHP developers. JVM support is available through things like the Quercus project – though I’m not sure how stable/mature/well-used that is.

To me the main diff between PHP and Ruby is the community. For instance, TDD seems to be part of the Ruby culture. A lot of good programming practices happen by default because of the “swimming between the flags” approach of frameworks like Rails. And Rubyist tend to use objects properly – OO has always been a wee bit of a basket case in PHP (IMHO).

There are downsides as well.. the “F**K YOU!” attitude of some Rubyists towards other programming communities. I don’t think that helps our cause at all, other than making some people feel like they are part of an exclusive club.

On balance I’d say Ruby/RoR and PHP are serving different niches. I’d still use PHP if I had to whip something up quickly that had to work anywhere (and PHP is pretty well everywhere). There are some spaces where PHP works really well.. especially when you don’t want to bring over the whole Rails infrastructure just to show a few dynamic pages. But I love Ruby/Rails and given a choice I’d go for that.

I do think it’s easier to read.. I’ll agree there. You can tell a rude joke in Ruby that a non programmer can get offended by. There’s a challenge to your PHP people

:)

Cheers

11.07.10

I hate those kind of article, trying to say which one is better. We all know that Ruby is the “next gen” language and there is the best framework on it.
It will be the best language only if you can find it on any hosting service.

Damn, PHP still hold more than 35% of the web instead of the 2% of Rails.

11.07.10

This writer seems a bit confused – are you talking about ruby or rails-on-ruby are you comparing raw languages or their frameworks? Get your facts right.

11.07.10

thanks for posting these really useful

11.07.10

Another “wannabe programing guru”. I can say the same reasons why PHP is BETTER than Ruby.

11.07.10

Steve, some jumbled thoughts of mine, some brought up by article.

Ruby was my first programming language! I’m always happy to see Ruby or Rails discussed, because I think they are both a joy to work with. I def prefer the Ruby syntax over PHP. For small sites, I find it faster to develop and deploy PHP ( usually via WordPress) code than with a ruby micro-framework or RoR. For larger applications, I do like the organization of RoR apps. I haven’t used them, but I do know lots of folks that develop with PHP MVC frameworks like Zend, CodeIgniter, cakePHP, symfony, expression engine. I have been meaning to mess with them.

*Community Maturity* It may the case that for many Rubyists, Ruby is not their first language. Might be interesting to consider why that is? Def interesting to note that while PHP’s initial creation was explicitly for working with the web, Ruby’s was not. Because most hosts have apache mod_php or some form of PHP interpreter setup from the getgo, it is probably faster to pick up PHP as a first language than Ruby ( for the web).

*Resources* I think there are far more PHP resources scattered around the web than anything else, although many are not of high quality. With Ruby, it feels to me like there is a lot to manage w/r/t the version of Ruby, the gem version, and the potential incompatibilities that sometimes arise. It can be hard to find well-documented fixes to problems with your particular setup.

*Deployment* Initial setup of a Ruby app on the production server can be a real pain. Despite the plethora of different front-end (apache, nginx) and application server (webrick, mongrel, lighttpd, passenger, thin, ebb) combinations for running Ruby apps, none of them are super easy for a beginner to deploy. That said I haven’t shelled out for any of the premium Ruby hosting. Heroku sounds like it has made Ruby deployment very easy. PHP from the getgo has been designed to run on the web.

*Pre-installed* PHP and Apache, like Ruby, is pre-installed on OSX 10.5, AFAIK.

*Interactive shell* “php -a” from a mac terminal gives you somewhat of a PHP interactive shell. Two complaints: 1) After “php -a”, you still have to type <? before your statements will be interpreted as code. 2) The return value is not shown. You must echo out $vars to see their value, whereas IRB kindly shows you the return value of each operation.

11.07.10

Am I the only one that noticed that that’s a picture of a Django project in some IDE and has nothing to do with an interactive shell (12)?