Yesterday I decided to start prototyping in Ruby one aspect of our future product (more on this one soon), and the experience was valuable enough for me to share it here. I had a pretty clear idea of what I wanted to accomplish, and I knew it was feasible in a reasonable amount of time, but I wanted to see it working.
At the end of the day, I was able to test my (very basic) use cases, with already some good lessons (knowing about a way not to do something is sometime as or more valuable than knowing about the way to do it). While the prototype was my initial objective, I found more interest in what I was able to learn in the process.
Some things I learned yesterday
About character encodings
- Differences between UTF-8 and ASCII8-BIT, and the nice (1.9) String force_encoding method (that seems to pass when decode may throw an exception on characters that does not exists in UTF-8)
- Differences between Ruby 1.8 and 1.9, like the way Ruby encodes string that changed much between the two versions, so if you have an encoding problem, be sure to check answers related to the Ruby version you use
- How to build a gem from Ruby code. Bookmarked for later, this will be useful for multi-module development.
- Some basic Ruby (which I'm still learning, even if it is now my language of choice). Seems that each time that I start doing a bit of code using arrays or strings, there is a method that does exactly what I need.
- require_relative and how "require" works, especially for requiring a file in the same directory. I did not like to put code like "require File.expand_path(File.dirname(__FILE__)..." and Ruby 1.9 "require_relative" gave a nice solution to this.
On Ruby versions and rvm
- rvm: If you do not use rvm yet, now is the time to start. It allow painless switch between various Ruby versions on the same machine (1.8 / 1.9 of course, but also Maglev, JRuby...). Works like advertised.
- Use of .bashrc. I'm still new in the Linux world, but I like most of the things I found about it. For example, this simple file where you can put commands that will be executed each time you start a terminal.
- Using rvm choosen Ruby in Aptana. It does not work "out of the box", which is regrettable, but as a Ubuntu user, I had already to execute some commands before, so this is only one more.
- That gems are "Ruby version related", meaning that by switching to 1.9, I had to "gem install" some again (which is quite logical)
- How to call commands from Ruby. Kernel::system even returns true of false according to the launched command return code.
On GitHub and Git
- GitHub API and its various versions (the one that is deprecated and the one that is in beta). Both happen to be nice, working and well documented.
- Some Ruby libs wrapping the GitHub API : octokit, octopi, and especially hubruby.
- How to build a little domain around an API (as, logically, I decided that none of these were good enough for me, and started to build my own)
- Grit, a git API. Which is not the same as a GitHub API. Is/was used internally by GitHub, will be replaced by Ruby bindings on a C lib, rugged.
- A weird bug or incompatibility between rails 3.1.3 and coffee-script-source 1.1.3. I did not go for the explanation for this one, the fix (switch back to 1.1.2) was enough for me.
- The json Ruby library: A nice, very Ruby-ish library, with methods to get/save/convert to and from json
- Nice opinions on "where to I put my logic in rails". This one seems to come back again and again. I got my actual definitive answer - see above - I've decided to make my logic an apart gem and include it via my gemfile.
- A bit of arel, as I'm using (and liking) the new API more and more.
- Some Rails command line options (that I had forgotten). I wonder why this guide is in the "advanced" section. Looks like one of the most useful to me.
I only took the measure of it when I started to put it on (figurative) paper. That makes a quite impressive list, even if most of those points are rather simple and/or entry level. My objective here is not to elaborate those (the provided links are doing a far better job that I could), but to show how a simple coding session can lead to a lot of reading and learning.
As I was going back in my (large) browser history, I saw that I used a lot of knowledge in this simple prototype building, none of it which was mine. This community (blogs, Stack Overflow, libraries documentation or others) is one of the biggest things in development, and as become as mandatory for me as my IDE to work efficiently.
The emergence of an healthy library ecosystem is one of the best advantages a language can have (far over its own technical merits), and Ruby has come a long way on this. While this lead to tremendous productivity (it would have been ten times more works to manage my prototype using only a bare Ruby), it also means that the development knowledge has shifted from being about the language only. While mastering your main tool is still necessary, it is no more sufficient, and it is no more possible to be proficient in every aspect of a language ecosystem, which makes the community importance only bigger.