Background
For the last 10 years or so I have been squarely a PHP developer. From version PHP 4 around 2000 up to and including the current version 7 in 2018. From scripting, to OOP, to the modern language ecosystem it is today. This year I wanted to learn a new language, to add a different perspective on problem solving. I tried out Golang for a couple months as the concurrency and channels model is super interesting and it is a very low level language (all of which PHP is not). However, recently I was approached with a project that is currently written in Ruby (on Rails). I have wanted to learn Ruby for awhile so this provided an excellent opportunity to give Ruby/Rails a spin. After a week of spare time tutorials and reading here is my opinion about Ruby after the first 12 hours.
Good
General Community
I’ve been around the internet a bit. ICQ, AIM, Usenets, direct dial BBSs, Stack Overflow, Dev.to, Regional Conferences, on and on. I have never, in my experience, witnessed a community so open, friendly, and helpful as the Ruby group. If I had to pick a language to learn based on how friendly and curitouse the members are to each other; Ruby would win hands down. Not to say the community is perfect, just the nicest in general.
Language Syntax
You know, I like the short syntax. It is a dot based syntax (like JS for example), paren’s are optional, and the data types ad nearly self defining.
[0 => 'value'] #array
{'key' => 'value'} #hash
1+2=3 # int + int = int
1.2 + 2.3 = 3.3 # dec + dec = dec
self.validate data #object.method parameter_date
The optional paren’s was confusing at first, but quickly mentally internalized.
Package Management
After some digging around I am pleased with the ecosystem around the Ruby language. Dependency management is handled nicely by Bundler and the Gem system. While I am not a personal fan of the Gemfile syntax (being a DSL) it is very readable and easy to spot errors in. I also like that it handles system level dependencies as well. Need Postgres? Add it. Need a library for geolocation calculations? Add it. Need a SASS process for the frontend asset pipeline? Add it. Even the frameworks Rails and Sinatra are dependencies of your PROJECT, not your project being built from a specific commit of a framework. Sure, there are ways around this but Ruby does it this way by DESIGN.
Oh, and Ruby as a version manager similar to NodeJs. Called RVM (Ruby Version Manager).
- https://bundler.io/
- https://www.cloudcity.io/blog/2015/07/10/how-bundler-works-a-history-of-ruby-dependency-management/
- https://rvm.io/
Bad
Modified SemVer
For the love of everything software use normal SemVer! That means you Rub, Laravel, and anyone else who thinks they are _better_ than nearly 60 years of release management. Stop being a special snowflake.
Automagical Frameworks
Both Rails and Sinatra are both VERY opinionated about how things should be done. Want to do thing’s a bit different? Nope, get lost. The language is very flexible but the top two frameworks are very opinionated. I guess this goes hand-in-hand with convention over configuration. You have to expect things to be a given way in order for convention to work properly.
Ugly
Syntax Might be a bit Too short
[A] - [B] = [C]
That is array subtraction in Ruby. If you did not know those are arrays there is minimal chance you would know what is going on. Makes sense for number math, but numbers usually do not have brackets. #confused Some languages have static function for construct manipulation. Not Ruby, nope. “Everything is an object”, so everything has innate abilities and functionality. I know, ‘cant please everyone everyday’. This is really just a nit-pick more than anything.
Performance
Here is where Ruby falls down. For all the short syntax, everything is an objects, neat-coll-shininess; Ruby 2.6 lags behind PHP 74.3 in all buit the binary Tree test. https://benchmarksgame-team.pages.debian.net/benchmarksgame/faster/yarv-php.html
Say what you will, but in the age of instant information every 10ms counts. In some examples Ruby is ice-age slow. the simple fix to this is caching (Redis/et al.). It adds a layer of complexity to even the most basic app but is generally desired for any scale application anyways.
Closing
So far, I am liking it. I could see myself reaching for Ruby (+Rails / Sinatra) for quick web projects for automation scripting as easily as PHP or Golang. 0 (bad) to 10 (good) I give Ruby a 8.5 overall at this time. Will definitely be sticking with it, but has room to grow as well.
What about you, have you used Ruby for an extensive amount of time? Do you have any feelings or opinions about Ruby? Any resources you found helpful while learning the language? Please share in the comments below.