Old Guy New Trick

An old guys journey to learn how to code.

An Unexcused Absence


Author: John on May 05, 2015

he dedicated and faithful reader of this old guy, would have noticed an extended silence in this corner of the web.  I have, as the automated voice message of my sons school would say, "an unexcused absence."  While I won't make any excuses, I would like to share what has kept me away from my writing.

Back in March I started to learn Swift by attending the Udacity iOS online program. Udacity has partnered with the company I work at.  After successful completion of the course, my company will reimburse me for the tuition.  About two weeks into my training, the family and I went on a cruise.  Though I brought my laptop and study material, I didn't spend much time Swift.

After our trip, and a hop-skip-jump over a week, it was time for Ancient City Ruby. I enjoyed this years ACR conference, though I would have preferred a bit more technical meat and less of the social fluffy stuff.  However, the most significant part of ACR for me was meeting with another Ruby developer and getting accepted to work part-time on a neat project.  

The part-time project is my first "real-world" Ruby app that I've been a part of. Though I've worked on some training apps or personal Rails apps, they have all been small in scale compared to this new gig.  Being new to the project, and not knowing much outside my experience with smaller apps, I've been spending a lot of time looking around and trying to get familiar with the applications structure.

And then came Rails Conference!  This year the conference was held in Atlanta, GA which is not too bad a drive from Jacksonville, FL.  I hadn't yet been to a Rails Conference, so of course I had to go.  Overall I enjoyed the time in Atlanta.  I ran into a guy, David, who I had meet in Miami at Ruby Conf 2013.  Also, I got to spend time with another developer that is working on the same project that I mentioned above.  

After the conference, I have been spending most of my evenings working on the part-time project.  There is a lot to learn, but I am enjoying every minute of it. The best part of my day is seeing my tests go green and being able to merge and push my changes.  

And that is my excuse, uh I mean my reasons, for not being active here for a while. I had set a personal goal to publish a new post each month, and I'm working to raise the bar and publish twice a month.  Keep me honest - smack me via Twitter if you feel I'm slacking.  :)

Ok, now I'd like to share a little snippet of code that illustrates something neat I have learned while working on the part-time gig.  A great benefit of working on a project with a mentor. The first example is my original code before refactoring to make it better and look a lot more 'Ruby-ish'.


def is_valid?(product)
  return true if @errors.nil?
  @errors.each do |error|
    if error.has_key?(product)
      return false
    end
  end
  return true
end<

def errored_price(product)
  return nil if @errors.nil?
  @errors.each do |error|
    if error.has_key?(product)
      return error[product]
    end
  end
  return nil
end

And now the reveal - the pretty version which accomplishes the same thing.  Note that during the refactor we re-named a few things, but the overall result was the same.


def is_valid?(product)
  return true if @errors.nil?
  return false if @errors.include?(product)
  return true
end

def clock_price(product, eor_price)
  return price if @new_prices.nil?
  return @new_prices[product]
end

Learn Something New Every Day

Last Edited by: John on November 14, 2015