Posts Tagged ‘general tips


How to become a better Ruby programmer

1. Buy the Pickaxe and put it on the John

Idea: Know the standard library

When I got an actual copy of Programming Ruby on paper, I found myself looking into it whenever I had spare time and no computer available – usually this was mostly on the toilet. 😉

That way I discovered so many useful methods and classes in Ruby’s standard library, you won’t believe it. Often times developers tend to reinvent some functionality, just because they don’t realize it’s already provided for them. And trust me, Ruby comes with quite some distinct features out of the box.

So my tip is to get a good book that covers the Standard Library or print it out somehow, and have it with you whenever you have to kill time, e.g. in a bus or the bathroom (or even for 10 minutes in bed).

2. Necromancer-Style: Create skeletons

Idea: When using a new tool or trying to implement a bigger feature, get started with just the boilerplate code

Often times, when I want to try out a new library, I hesitate, because of the steps necessary to get started with it. First I have to install it, and maybe some dependencies, then create a file with some boilerplate code, and sometimes also do some configuration.

Not until then can I really start with the actual functionality I want to try. And the worst thing is, weeks later I’d like to use the same library again in another project, can’t remember the procedure and have to do it all over again. And sometimes this keeps me from using that new library (e.g. RSpec) at all, because I can just resort to a good old tool I know (e.g. Test/Unit).

Another exemplification is starting a big feature, where you don’t know how to implement the actual business logic. My suggestion is, just start with something, even if it’s an empty file. And then create a test case, to tell yourself where you want to go. Remember, that you can also write empty (deferred) tests, which just exist to remind you of the behavior you want to realize.

Now when you take a break from the project, and have a Geistesblitz, you can directly open the file and start typing. Believe me, this shouldn’t be underestimated!

Rails is an ideal role model with all it’s generators. It is an important step to get a complete application skeleton
with the rails command, so can directly start with your business logic. And when you create a controller, it also creates a test case for you, to motivate you writing functional tests at all. Sometimes just creating that file and filling it with the necessary boilerplate seems to be too much for us (at least for me).

I recommend preparing the installation and initial configuration of new tools and features, and sometimes even automate this step. There are various ways to do this:

  1. You can add a snippet to TextMate (e.g. try Command+N in your test-folder, choose a filename, hit ENTER,  type tc and press TAB).
  2. Maybe it’s even enough to have a file somewhere in a directory, where you can just copy and paste the configuration.
  3. Ruby is also the perfect language for writing a small shell script to download a library or create necessary files.
  4. You could also write a complex generator for more elaborated tasks.

To sum it up: have a place where you can directly start typing your ideas without being distracted. Create file skeletons, and for more complex tasks, try to automate this step.

3. Don’t be shy

Idea: Communicate with other people on IRC to reinforce your comprehension

Chatting with fellow programmers has a number of advantages:

  1. You can ask questions to Ruby experts, which you haven’t been able to solve with the API documentation or a google search. Sometimes a question can spark really interesting discussions, you weren’t able to predict.
  2. When you help other people with a specific problem, oftentimes you increase your understanding in that area or see things from a different perspective. Many times when someone asks something I’m not sure of,  I open up IRB and just try it out. This lead to some new revelations, but also consolidated things I was already quite certain about. And don’t forget that your helping other people learning the language, which will keep the mutually assistence up.
  3. Hanging in the different channels will possibly bring new connections: maybe you find a project you’re interested in, because some people are constantly talking about it, or you just keep talking to the same guys over again. Which brings us the the next point:
  4. IRC is also a good place to meet new friends, after all everyone in #ruby-lang shares the same hobby, which is a good foundation, right?

So I suggest to just give it a try and download an IRC Client (on OS X i recommend Colloquy), connect to, and join #ruby plus #ruby-lang (there is also #rubyonrails or #shoes and many more specialized channels). But beware: it can get pretty addictive and distracting if you don’t watch it. 😉


July 2018
« Jan