Monthly Archives: January 2012

Season of Ruby – Iteration 1 Restrospective

Same 3 questions that I laid out in the last retrospective post.

What Went Well

  • Broke through the “no code” barrier – I was learning a lot with with the Ruby Koans, but they also gave a false sense of knowledge.  Doing the String Calculator Kata got me writing my own code, posting it to github, and developing something of a “new” comfort zone.  I was definitely feeling somewhat uncomfortable as I was struggling to do things that I could do instantly in my familiar .NET surroundings, like project setup, working with version control, etc, so this was a good hurdle to clear.
  • Pushed code to github – OK, so it wasn’t a lot of code, but same idea: break through a barrier.  It also re-familiarized me with git which I had used a little over a year ago.

What Can Be Improved On

  • Not writing Ruby code in the Ruby style – Or maybe I am and just don’t know it.  Regardless, I still feel very much like a .NET developer writing Ruby code.  Bottom line, start to investigate and use Ruby as it is intended.  That means reading and writing more Ruby code.
What Am I Going To Do To Improve Things

Writing code will continue to be the main focus of the iteration,  but I also need to be focusing on what makes Ruby special.  To do that I want to work with some open-source Ruby code that will hopefully point out good Ruby style and also point me towards implementations or Ruby features that I have not seen yet.

I got some books from the library that I also hope will help educate me on elements of the Ruby language, style, and best practices.  I will fill in some non-programming time with going through the books for tips.

Iteration 2 Stories
The theme for this iteration is fundamentals.  I want to continue writing code and exploring features of Ruby, especially OO best practices as well as how Ruby implements blocks and iterators.  Building a strong base of fundamentals will position me to start doing some Ruby on Rails work in subsequent iterations.
Here are the stories for this iteration
  • As a .NET developer learning Ruby, I want to build a strong fundamental base of OO techniques with Ruby so that I can move onto more substantive uses of Ruby such as a Ruby on Rails application.  A 2-hour, time-boxed exercise of Conway’s Game of Life will provide an opportunity to get more experience using classes in Ruby.  Implementation will be stored on github exercises’about_methods’
  • As a .NET developer learning Ruby, I want to learn good Ruby style so that I can contribute to an open source project in the near-term future.  One way to learn style is to work with someone else’s code, so I will fork a repository on github and look at the style used and compare it against the style that I have been using for my development.  I want a project that is a “pure Ruby” project as opposed to Ruby on Rails to keep the scope manageable.  Since I was recently at thoughtbot for a seminar, I found a small project on github, Cocaine, that seems to fit the bill.  This will be a 1 hour, time-boxed, exercise.
  • Continue with the Ruby Koans to get more practice and understanding of blocks and iterators
    • require ‘about_exceptions’
    • require ‘about_triangle_project_2’
    • require ‘about_iteration’
    • require ‘about_blocks’

Season of Ruby – The String Calculator Kata and GitHub

Last iteration I realized that I needed to start writing some code, so the big story for this iteration was to do Roy Osherove’s String Calculator Kata and also to push the code up to github. Mission accomplished! But unlike ‘W’ standing on the aircraft carrier, I know there is a lot more work to do.

I used git a little bit a few years ago, and initially it was a painful adjustment because all my past experience was with centralized repositories like Subversion, Team Foundation, and CVS. Distributed repositories were a paradigm shift, but after some getting used to it really started to grow on
me. I loved home easy it was to create branches and that developers could work on different features in isolation before bringing their code back into the “trunk”. So it was great to get some code up on github, using both the RubyMine integration and plain old git command line tools. I need to spend a little time refamiliarizing myself with the terminology and workflow, but it was a great start.

As far as the kata goes I feel similarly. Did everything turn out exactly the way I wanted? No, but it is a kata. You do it, you learn something, you take those lessons forward, and you move on. Maybe I will do it again in a few weeks and see how the outcome is different. It served it’s purpose in getting me out of my comfort zone and writing code in a new language. It also got me asking new questions and places to take the journey. Some of the things that I wondered about as I was doing the kata

  • Does Ruby have the philosophy that there is one “right and obvious” way to do things, ala Python, or is it more Perl-like in that there are a many ways that are acceptable and it is a developer choice. At least according to this page it seems to borrow from Perl in that there is more than one way to do it.
  • How do private and protected variables/methods work in Ruby?  Are they often used or are there other patterns that are applied?  I remembered with Python that the notion of “private” was downplayed, at least with what I saw. I am not a Python expert so I may be mis-representing here.
  • Are instance variables used much?  In one of my refactorings I noticed that I was passing the same argument to a lot of methods, and decided to keep it in an instance variable. Was that Ruby-esque? Was it habits from .NET creeping in?  Was it the “best” solution

I don’t know the “Ruby Way” yet, so these questions are all the more reasons to start looking at OPC (other people’s code). So it is probably time to fork a Ruby open source project and start playing around with it.

I want to make sure I keep writing code too, so I think I will take a time-boxed stab at Conway’s Game of Life. I had a lot of fun with that at the Global Day of Code Retreat. I want to time-box it because it is something that I could spend a lot of time on, depending on how far I want to take it, and I am not looking for a complete solution but to exlore some different ideas in code. Maybe it’s time to start thinking about bring Rails into the mix too.

All these ideas make me think I should be keeping a formal backlog and continuing with the notion of treating this journey as an Agile project. I use a tool called Rally at work, maybe I’ll use that or investigate another tool. Any ideas or recommendations from the blogosphere?

Season of Ruby – Iteration Zero Retrospective

Keeping in the Agile spirit, I did a retrospective for Iteration Zero of my Season of Ruby.  When I conduct a retrospective I cover 3 areas:

  1. What did we do well
  2. What can we improve on
  3. What are we going to focus on in the next iteration to improve the process or the product

I am a team of 1 on this journey, so “we” is me.

What Went Well

  • Digging the Ruby KoansI’m happy that I am not just blowing through them to get to the next subject, but asking questions when something doesn’t make sense or surprises me.  I also find myself adding additional tests to experiment with behaviors
  • Love playing around in the IRB  –  This also has a lot to do with experimenting and following where my curiosity takes me.
  • Got a Ruby environment set – OK, so it is not the shiny new Mac I wanted, but RubyMine on my Windows laptop has been a very low-friction experience.  The Mac will come.  I have a birthday coming up and maybe I will be good to me.

What Can Be Improved On

  • Not writing enough code – Although I am learning with the Ruby Koans, I am not writing enough code.
  • Making really good progress, but need to dedicate more time – I’m happy with where I am, but the time goes by quickly.  May need to dedicate just a little more time on a weekly basis.
  • Haven’t done anything with github yet – One of the goals was to set up a github account.  Technically I have satisfied that criteria because I have an account…an empty account.  That needs to change

What Am I Going To Do To Improve Things

As a rule, I usually only like to pick one thing to improve on, especially in a short iteration, but since these two things go so well together:

  • Do the String kata in Ruby – It’s a pretty straightforward problem, one that I have done in C# and C++, and this will get me actually writing code
  • Put the String kata in github, committing as new functionality is added.
Iteration 1 Stories
  • Continue with the Ruby Koans, doing these exercises
    • ‘about_methods’
    • ‘about_constants’
    • ‘about_control_statements’
    • ‘about_true_and_false’
    • ‘about_triangle_project’
    • ‘about_exceptions’
  • Do the String kata in Ruby in a github repo

Season of Ruby – Learning the Syntax

The Season of Ruby continues…

I am staying with the Ruby Koans for now, I really enjoy the layout as I learn the basics of the language and it’s syntax.  To this point I have covered asserts, the notion of nil (it really is an object), objects, arrays, hashes, strings, symbols, and my favorite…regular expressions.

I have a love-hate relationship with regular expressions.  Unlike many programmers who may deal with a lot of text, in my world of medical devices and laboratory automation I don’t need to rely on regex all that much.  To paraphrase the most interesting man in the world, “I don’t always use Regexp, but when I do, it is a powerful, painful, awful, and wonderful experience….every time”.

Things that I have found interesting or noteworthy about the most recent koans:

  • Array slicing and hashes feel a lot like Python.
  • The PERL-inspired “flexible quotes” are interesting and easy to use
  • I had a WTF moment with the shovel operator “<<” versus “+=”, but I am not alone there.  After Googling around it made sense and this article about the performance differences was a real eye opener.  I imagined “<<” would be faster than “+=”, but wow!
  • I want to play around more with heredocs.  Again, nothing Earth-shattering, just not something I have used in my day-to-day programming.  Can see where this would make working with text a lot easier

I was a little confused about Ruby symbols at first.  How do they get “initialized”, how do you use them, why don’t they take an “=”, what can you do with them once you’ve got them.  After some Googling, things were starting to take shape, but I was still not perfectly clear on them.  But wait….

Off to the REPL

NB: I realize if SOPA were to pass as is I could go to jail for this Dangermouse cartoon, but it is such a hack job by me, maybe I should…

I really love the ability to play around with ideas in a REPL.  Verdammelt had an interesting article about using a REPL and TDD and this seemed like a perfect place for some experimentation.  I was able to pretty quickly satisfy my curiousity and questions about Ruby symbols in the IRB.  I thought it was neat how one answer may lead to another question and so on…very exploratory.

Which brings us to the aforementioned regular expressions.  Some people love regular expressions.  Some people can whip a regex out of thin air to find the middle names of everyone with a blue house, between the ages of 38-43, with 2 dogs OR 1 ferret and 3 parrots.  I am not one of those people.  I always liked this joke

Some people, when confronted with a problem, think
“I know, I’ll use regular expressions.”   Now they have two problems.

But interestingly I had an “a ha” moment while doing the Regexp exercises.  It wasn’t some “the skies opened and I know all Regexp syntax by heart now”.  That unfortunately did not happen.  It was that it reinforced this notion of TDD:

A well-written test suite IS documentation.

A well written test suite IS a specification.

I love that about TDD and it is one of the reasons I am having so much fun with the Ruby Koans.  Every test clearly expresses a single, intended behavior.

Stay tuned for a retrospective on the first iteration, and if you have tips on good Ruby resources I would love to hear them.

So Begins The Season of Ruby

I wasn’t sure if from my last post, this would be a year of Ruby, a lifetime of Ruby, or 20 minutes of Ruby, so let’s start with the notion of a season of Ruby.

Lao Tzu said “a journey of a thousand miles begins with a single step”.  So as much as I would like to embark on this voyage on a shiny new Mac, running TextMate as my editor, I will stick a little closer to my comfort zone and start out running RubyMine on my Windows machine.  As a .NET developer, I am pretty entrenched in the IDE experience.  That is not to say I don’t want a shiny new Mac, but I also don’t want to get bogged down as I learn a new language.  The RubyMine experience is very familiar to me since I use Visual Studio with Resharper and for a mere $69 for a personal license it seems like a no-brainer.

So where to start….

I scoured various blogs and the Ruby docs for good places to learning Ruby.  I settled on starting with the Ruby Koans site.  I really like that this tutorial had a test-centric approach.  One of the draws to exploring the Ruby community is that testing is baked into the culture.  The Ruby Koans allowed for a lot of experimentation and I tried to take the approach of not just blowing through the problems, but really asking what are they trying to teach in this lesson.  I tried to cause tests to fail in different ways and added some scenarios of my own to try and investigate further.

Another resource was to just use IRB, the interactive Ruby shell.  Nil is an object, huh?  What methods does it have.  I suppose I could pore through documentation or maybe just…let’s see if this works

irb(main):001:0> nil.methods
=> [“inspect”, “&”, “clone”, “public_methods”, “display”, “instance_variable_defined?”, “equal?”, “f
reeze”, “to_i”, “methods”, “respond_to?”, “dup”, “instance_variables”, “__id__”, “|”, “method”, “eql
?”, “id”, “to_f”, “singleton_methods”, “send”, “taint”, “frozen?”, “instance_variable_get”, “^”, “__
send__”, “instance_of?”, “to_a”, “type”, “protected_methods”, “object_id”, “instance_eval”, “==”, “=
==”, “instance_variable_set”, “kind_of?”, “extend”, “to_s”, “hash”, “class”, “tainted?”, “=~”, “priv
ate_methods”, “nil?”, “untaint”, “is_a?”]
irb(main):002:0>

Good gravy, so simple even a .NET developer like me can do it 😉  I found myself playing a lot in the IRB when I wanted to just try something out.

I got though the basics of asserts, objects, nil, and arrays with the koans, diving over to various websites, StackOverflow, irb, and the Ruby core docs as I ran into questions.  I am using the Pomodoro technique to timebox my activities into manageable chucks and try to stay fresh.

The plan for next time will be to continue with the koans, probably for a while, to build up some core knowledge.  At some point I will dive into the Koans code itself as one of the goals of the last post was to read more code as well as write it.

In my experience, the best way to learn code is to write code, but I also reserved the following books from the library to have around as  references and for tips on style.

I also want to take a peek at Why’s (Poignant) Guide To Ruby