Last night I was working on some code (not java) that was written by someone not me (thank God!). It is a part of an application that I have been messing with (updating, maintaining, bug-fixing, whatnot) for the last year or so. When I finish the cattle drive I am going to rewrite the whole application in java.
Anyway, I came across a section of code with multiple variations on the following one-liner in a switch statement. I've broken it up here so that the page doesn't scroll horizontally.
All sorts of warning bells went off in my head (excessive array dereferencing, redundant code, unreadable tertiary statement, a method called q() - yeah, well q() you, too! - and then the f prepended to the identifiers... what's that supposed to be? I actually think it has something to do with it being 'fetched' from the database, but jeez!
After a bit of fiddling (via a version with an if/else statement just to see what exactly was going on) I ended up with the following:
Thank you, thank you cattle drive and nitpickers! You have been infiltrating my brain, and the results are tangible! [ June 18, 2007: Message edited by: Katrina Owen ]
Nice post, Katrina. My experience of the cattle drive have also been productive and an enjoyable learning experience, which I try to encompass in my coding at work and also in my studies. Some of the feedback I have received from my tutor from assignment work outside of the cattledrive are 'clear code', 'easy to read' and this has come from taking part in the drive. As a newbie into programming it has helped me gain a mindset early on how it is important to maintain readability of code, not only for myself when I come to look at my code a few months later on, but also for the fellow coders looking at my work in the future.
Even from the first assignment, I learnt something (array de-referencing), I think, like fellow cattle drivers I thought I had submitted the perfect first assignment until I received that nitpick! But this lesson helped me to understand and to sometimes rethink that although my code is doing as expected, is it as efficient as it could be?
I am glad I have been fortunate enough to learn these valuable lessons at the start part of my programming career