The Avid Apprentice

New tricks, manual refactorings, and sharing the knowledge.

with one comment

Today I didn’t hit my goal that I stated during my stand-up with Jim, and that is always a bummer. I did learn to use a few new tricks including the ternary operator in Ruby and the value ||= value_to_assign_if_nil idiom. I was actually playing with them in this method.

Why did I go with the ternary operator instead of ||= The first one I wrote was the ternary but I really didn’t like having the two ?’s so close to each other. It just really didn’t seem to read well. Then I wrote the other line and I really liked how clear it looked. But then I realized that I was doing an assignment for no reason. It produced the same results (my tests reinforced that), but it just didn’t feel right. So ternary it was. I’m not exactly sure what the bigger lesson here is, but even I know that assigning something and never using it is just silly.

I also learned that having a refactoring IDE like IntelliJ is great, but you actually need to know how to manually perform the refactors sometimes. My situation today was extracting a class in Ruby. Needless to say, it took much longer than it should have and I was not green for awhile. That is a good sign that you took a wrong turn somewhere.

I’ve also began to mentor a friend of mine who is learning to program. I take great satisfaction in helping others and it’s a nice feeling to be able to pass on some of my knowledge. I imagine that this is how the craftsmen feel when they help us over a hurdle or show us something new and cool. I also was able to help one of our interns find a bug where they were setting a reference to an array instead of creating a copy of it. I’ve chased my tail on that a few times so I was pretty quick to realize the issue but we still had to track down where the culprit was. The satisfaction of helping someone else instead of constantly needing help was great. There is always something you can teach someone and there is always something you can be taught.

Written by Caleb

July 8, 2009 at 9:36 PM

One Response

Subscribe to comments with RSS.

  1. space || ” ” would also work (sans assignment). I hear you on the question marks. Ordinarily I like the ternary operator for stuff like this, but the ? ? does look funny to me too.

    trptcolin

    July 8, 2009 at 10:01 PM


Leave a comment