Wednesday, August 14, 2013

i'm back!

Wow, it's been a while!

But I'm back now, and with good news:

I landed my first rails job! I'm currently working for a nice startup who works with a major credit card company... The team is very talented, and they're very nice people! I'm very happy, I'm already learning a ton of new stuff at a very fast pace. That's much better than learn on my own, at home!

Another good thing: I've FINALLY finished my first sample application! Take a look at it on GitHub and Heroku. If you want to see more, just ask me for the username and password. I'll implement a signup system using devise later, it's on my todo list. =)

Wednesday, May 29, 2013

updating rvm and ruby

I'm starting a new project today, and I wanted to update Ruby to its latest version before starting.

The first thing I tried was to use RVM to upgrade the Ruby version, but it didn't work. I had to upgrade RVM first, so the last Ruby version would be included in the "known Rubies" list:

$ rvm get stable

When I ran rvm list known, it was there:

[ruby-]2.0.0[-p195]

And this last command did the trick:

$ rvm upgrade 2.0.0-p0 2.0.0-p195

Thursday, April 25, 2013

the good book

It's been a while since I posted for the last time.

I was watching the rails workshop like crazy and trying to extract every last bit of knowledge of it. Now I'm done, and it's time do start coding again, so I'll be posting more.

I still have to finish Kent Beck's TDD book, I've read only the first part, but today I felt the impact it had. Kent, I salute you!

I was coding something to a friend, and I was really able to think in a TDD-way, it was awesome, there's no going back now.

But the best part was refactoring the code. Kent says "Eliminate duplication", and I think I'll tattoo this on the back of my hands. Refactoring is AWESOME! Identify the duplication, eliminate it, "cool, my code looks cleaner!", run tests, all green, FUCK YEAH! It's almost like magic, you code shrinks before you eyes, becomes cleaner, and you have full confidence that you code still works.

If you wanna take a look at my code, see how it evolved, it's all here.

I wonder how much more cool stuff there is to learn in books like the classics Refactoring and Code Complete. I wish I had 48 hours in a day. =)

Tuesday, April 9, 2013

domain specific languages

The very first time I've hear about DSLs was after the Thoughtworks Boot Camp in March/2012.

I've read some articles after that, but I just really understood it after I started using Capybara.

Capybara is a framework for testing user interaction in rails applications.

A Capybara test will have statements like these:

visit "/"
click_link "My account"

fill_in "Your email", with: "john@example.org"

fill_in "Your password", with: "test"
click_button "Login"

Those statements are part of the Capybara framework. They are part of a language that was created specifically for the purpose of testing web applications. This is the Capybara DSL. A small language created for this specific purpose, or domain.

I've read that DSLs are not a new topic, but with the popularity of dynamic languages like Ruby, they are easy to create and incredibly useful. I'll try to create my own in the near future.

all in

Last friday I quit my job to study Rails full time.

And I must say I'm quite happy. The first day was a bit overwhelming, the workshop I'm currently attending has A LOT of information, and it will take some time to soak it all up, but the teacher is really good, and it's better to learn from a master than try to learn everything by myself.

It will take a lot of time and effort, but I'm feeling great about it, and I'm 100% motivated.

Let's do this! =)

Friday, March 29, 2013

method aliasing

It's possible to create aliases for methods in Ruby:

Now we can call either say_hello or greet and have the same results:

> h = Hello.new
=> #<Hello:0x9390ba8>

> h.say_hello

Hello!
=> nil

> h.greet

Hello!
=> nil

Monday, March 25, 2013

posting by chance

I had a delightful day with my girlfriend yesterday. =)

But just before I went to bed, I realized I hadn't written a single line of code all day, and that's bad luck. =)

It was already late and I after searching for ten minutes or so (man, it's hard to find a website with real simple exercises) I chose a trivial problem: write a program that simulates rolling a par of dice (I wanted something really simple, just to write my bit of code for the day and not upset the Coding Spirits).

I started writing a test, something like:

def test_roll_dice
  die = Die.new
  result = die.roll
  # assert... wait, what?
end

What would be my assertion? That the result had to be between 1 and 6? But if I write a roll() method which returns numbers between 1 and 7, the test would pass 85% of the time. I thought about it for a while, and I really don't have any clue of how to test random stuff. I hope Kent covers that in his book...

The really fun thing is that something trivial like this led me to a meaningful question, something interesting that I will surely look into later.

I guess programming is like a box of chocolates... =)