On the SitePoint PHP blog Phil Sturgeon has written up a comparison of the PHP language versus Ruby suggests that we all just get along from the perspective of a developer that works with both happily.
Quite often you see developers who have a lot of experience in one language try to play with another, then make a rather quick comparison between the two. This comparison is usually quite worthless, but the clickbait titles get them a lot of traffic.
Instead of doing that, I thought it would be interesting to have a slightly more fair comparison, from the perspective of someone who really enjoys writing both PHP and Ruby, and has done so for years. The aim here is not to find out which is “better”, but to point out a few key things I like about Ruby and its ecosystem.
He starts with some of the basics conceptual differences between the two languages including the differences with methods/variables/properties and type hinting versus duck typing. He also covers some "fun features" of each language including:
- Nested classes
- Using debuggers (and the tools offered)
- "Unless" handling
- Predicate methods
- Shorter array syntax (in Ruby)
There's many more mentioned through the end of the post too, so be sure to check out the rest in the remainder of the article. Each point come with some brief code examples show how the feature is implemented depending on which language is being discussed.