Meaningless Drivel is fun!*
The moose likes Cattle Drive and the fly likes The general effect of the cattle drive :) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "The general effect of the cattle drive :)" Watch "The general effect of the cattle drive :)" New topic
Author

The general effect of the cattle drive :)

Katrina Owen
Sheriff

Joined: Nov 03, 2006
Posts: 1364
    
  17
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 ]
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9048
    
  10
What a wonderful testimonial to read! Thank you for sharing.


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Pauline McNamara
Sheriff

Joined: Jan 19, 2001
Posts: 4012
    
    6
Wow. Real world payoff, cool, thanks for showing us such a great example.

That application can be happy it found you.
paul wheaton
Trailboss

Joined: Dec 14, 1998
Posts: 20660
    ∞

Thanks for the kind words Katrina.

Not bat for 200 smackers, eh?


permaculture Wood Burning Stoves 2.0 - 4-DVD set
Katrina Owen
Sheriff

Joined: Nov 03, 2006
Posts: 1364
    
  17
It is so very worth the smackers, Paul. I can't believe this place hasn't been overrun.
Jon Anslow
Greenhorn

Joined: May 05, 2006
Posts: 16

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

Jon
 
Consider Paul's rocket mass heater.
 
subject: The general effect of the cattle drive :)