Post

#97: Ruby: help every programmer to be productive and to be happy

Yukihiro Matsumoto, the creator of Ruby programming language, famously said: "_I hope to see Ruby help every programmer in the world to be productive, and to enjoy programming, and to be happy_." Honestly, not many programming languages were built with developer's happines in mind. And to be honest, Ruby is a joy to work with. It's fairly easy to learn, easy to read, yet, very powerful. Also, with the appearance of Ruby on Rails, it became insanely productive. But first things first.

Ruby is dynamicaly, strongly typed, interpreted language. It’s inspired by Python, Lisp, Smalltalk and Java. It’s object-oriented to the point where every function is a method on some object. However, functional programming is also possible higher-order functions and lambda expressions. The source code is interpreted or runs within a virtual machine. There are actually a few popular interpreters. The original one was written in C. But, for example, there’s also JRuby, targetting Java Virtual Machine and Java interoperability. Surprisingly, Java implementation of Ruby can be faster than the native one.

Back to the language itself. Ruby also supports reflection and meta-programming. Features that enabled the creation of powerful frameworks. One of them was Ruby on Rails. The popularity of Ruby exploded after its flagship web framework was released. Ruby on Rails inspired a whole generation of web frameworks, including Django, Laravel, Phoenix and Grails. Which was initially named Groovy on Rails. So what’s so innovative in Rails? Well, it’s a web framework that simplifies many typical and mundane tasks. Let’s say you’re building an application to manage patients. Rails, with just one command, will auto-generate database table, model, controller and view. The framework assumes several naming conventions to provide working application in seconds.

Building simple create/restore/update/delete (CRUD) applications is trivial. Customizing generated views or database table is of course possible. Rails promotes convention over configuration and model-view-controller patterns. Also, Active Record pattern greatly simplifies database access. You don’t need a separate data access layer. Each model object has built-in methods for persistence. For example, patient->save() persists patient object to database.

The HTML view is also auto-generated based on conventions. So you get creating, updating, listing and deleting your objects for free. Oh, and HTML templating engine, known as ERB, is based on Ruby. So you don’t need to learn another language.

As you can see, Ruby on Rails definitely has batteries included. And by that I mean support for database migrations, build tool and web server. No wonder why building web applications with Rails exploded around 2005.

Now Ruby on Rails is not the only killer application of Ruby. As a matter of fact, there are more than 100 thousand Ruby packages, known as Gems. Also, there is plentfy of software written in Ruby. For example, Metasploit vulnerability scanner, Jekyll static site generator and Chef DevOps automation tool.

That’s it, thanks for listening, bye!

More materials

This post is licensed under CC BY 4.0 by the author.