A few things I've learned with Ruby and Rails
Autor: vitor navarro | Publicado: 2014-04-14T20:12:00-03:00

The past 3 months have been a heavy storm with hail rain and everything, still there is always a bright side on life events.

During my last job at Code Miner I had the pleasure to work with:

Ruby on Rails (and the huge amount of things that come along with it)
Good professionals


This short time lead me to decide to share my small knowledge with the others that may struggle, like I did at some points.&nbsp;



So first things first: Ruby on Rails. This pack made it appearance several times in all those years and deserves a cool place in things you would like to learn or at least should learn.



The Ruby and the Rails community, along with my teammates, taught me lots of new skills and improved old ones, so let's get to the sweeties.

1 - Debug, debug... and.... did I said debug?

The most important thing to learn when programming in any language is how to debug your code. Ruby has this quite good Gem to help you: pry.&nbsp;



All you have to do to use it is requiring: require 'pry' then you add binding.pry anywhere on your code and ta-da! when you run your app it will stop at that command and from this time on there is access to code variables, next steps and a few more useful things (take a look at github)

2 - My precious! My gems, gollum gollum

You probably already heard that cliche line: Don't reinvent the wheel.



Ruby has those precious libraries of working software called Gems.&nbsp;

Need something to debug your code? Bam: Pry gem.&nbsp;

Need something to parse xml? Boom: Nokogiri gem.

Need some background processing? Pow: Sidekiq gem.

Need your sidekiq jobs to be scheduled? Bang: Sidetiq gem.



There is a huge sort of gems sitting there just waiting to help in solving pesky problems so you can focus on creating an awesome app. Oh and there is a lot of them dedicated directly to Rails like the famous ActiveAdmin.



Ruby Toolbox and Ruby Gems may help you finding the ones you need.

3 - Did you saw that bug?

Sadly Test Driven Development (TDD) isn't used as much as it should be and &nbsp;I can understand that.&nbsp;



Most of &nbsp;the non TDD teams have lots of excuses but almost none of them spent or want to spend enough time using it, otherwise they would see how beautiful and useful it is.



TDD has proven worthy to me after much struggling still with objective-c in iOS world, which community is not so visibly into it.&nbsp;



Here is 4 reasons why I love it:


1. Bugs reduction and faster bug finding:

The first happens because you're thinking ahead, you need a way to check your code output even before it exists. The later happens because when changes are made you know what is the desired output.

2. Improves code readability and quality


It's hard to believe, but you tend to be more careful with what you're writing since you and others will be getting back to the tests a thousand of times.&nbsp;



Since you're being more careful with the code it's architecture will receive a boost, be prepared to read tons of articles/book on the subject.

3. &nbsp;Changes the way you see refactoring

You start to hate when its difficult to test your code, and that will be more often than you think. Refactoring begins to be more clear and this feeling fades away &nbsp;before you know.



Besides with a good testing suite refactoring &nbsp;will be easier and&nbsp;delightful.

4. Working in teams is nicer

Hey have you never hated that hard to use friend's code? Now if you have tests you probably will just have to run them a few times and there you go.&nbsp;


4. Everyone loves free candies, but do you give them too?


This one is short, we all love to use open source projects (yep Gems for example), but most of us don't have the guts to contribute.

Hey no one will shove you off if you're really helping, just give it a try. Oh and those beautiful projects of yours, release them properly as Open Source too, who knows, maybe you get some katas for that attitude.

I didn't learned this here with Ruby, but this feeling is stronger amongst its community.

This absolutely isn't all the things I wanted to share, there is more, but I think this is enough to my purpose, to give you a glimpse of the good things from the many which will improve yourself as a programmer when you enter, even for a moment, in the Ruby and Rails world.


By the way, I can't address how fulfilling is working with a great team, so if you have the chance of doing this please just go for it.