PHP to Ruby

Learning Ruby through PHP examples

A primer to Ruby OOP style programming from PHP

May 13, 2018

Alrighty, so we’re finally starting to get to the meat and potatoes of modern programming. Object Oriented Programming is still the dominant paradigm when it comes to static and dynamic languages. They’re a central concept to established languages such as Java and ported into languages that didn’t necessarily have them originally like PHP and Javascript.

PHP, known back in the day as Personal Homepage Preprocessor, was birthed as a templating language. It’s popularity exploded because of just how easy it was to install it on a web server, and it’s one of PHP’s greatest strengths to this day.

However, as the complexity of PHP applications grew they needed some additional constructs to help developers write scabable and understandable code. So, PHP took a leaf from Java and started incorporating Object Oriented Programming into it’s core.

Ruby on the other hand, is not a web first language. It does not include super global variables that access HTTP request or server information like PHP’s $_GET, $_POST and $_SERVER do.

Ruby was written has a general purpose language, much more akin to Python than to PHP. But central to Ruby is the concept that everything is an object. Therefore the OOP paradigm of thinking and building is very much alive and well in Ruby as a language.

You’ll find that OOP in practice between PHP and Ruby have much more in common than do not. However, in general Ruby’s approach allows more flexible approach. It gives you “sharper knives” as DHH Rail’s creator likes to describe it.