JOB REFERRALS
    ON THIS PAGE
    ARCHIVES
    CATEGORIES
    BLOGROLL
    LINKS
    SEARCH
    MY BOOKS
    DISCLAIMER
 
 Monday, January 15, 2007
The Root of All Evil

At a No Fluff Just Stuff conference not that long ago, Brian Goetz and I were hosting a BOF on "Java Internals" (I think it was), and he tossed off a one-liner that just floored me; I forget the exact phrasology, but it went something like:

Remember that part about premature optimization being the root of all evil? He was referring to programmer career lifecycle, not software development lifecycle.

... and the more I thought about it, the more I think Brian was absolutely right. There are some projects, no matter how mature or immature, that I simply don't want any developer on the team to "optimize", because I know what their optimizations will be like: trying to avoid method calls because "they're expensive", trying to avoid allocating objects because "it's more work for the GC", and completely ignoring network traversals because they just don't realize the cost of going across the wire (or else they think it really can't be all that bad). And then there are those programmers I've met who are "optimizing" from the very get-go, because they work to avoid network round-trips, or write SQL statements that don't need later optimization, simply because they got it right the first time (where "right" means "correct" and "fast").

It made me wish there was a "Developer Skill" setting I could throw on the compiler/IDE, something that would pick up the following keystrokes...

for (int x = 10; x > 0; x--)

... and immediately pop Clippy up (yes, the annoying paperclip from Office) who then says, "It looks like you're doing a decrementing loop count as a premature optimization--would you like me to help you out?" and promptly rewrites the code as...

// QUIT BEING STUPID, STUPID!

for (int x = 0; x < 10; x++)

... because the JVM and CLR actually better understand and therefore JIT better code when your code is more clear than "hand-optimized".

And before any of those thirty-year crusty old curmudgeons start to stand up and shout "See? I told you young whippersnappers to start listening to me, we should have wrote it all in COBOL and we would have liked it!", let me be very quick to point out that years of experience in a developer are very subjective things--I've met developers with less than two years experience that I would qualify as "senior", and I've met developers with more than thirty that I wouldn't feel safe to code "Hello World".

Which, naturally, then brings up the logical question, "How do I know if I'm ready to start optimizing?" For our answer, we turn to that ancient Master, Yoda:

YODA: Yes, a Jedi's strength flows from the Force. But beware of the dark side. Anger, fear, aggression; the dark side of the Force are they. Easily they flow, quick to join you in a fight. If once you start down the dark path, forever will it dominate your destiny, consume you it will, as it did Obi-Wan's apprentice.
LUKE: Vader... Is the dark side stronger?
YODA: No, no, no. Quicker, easier, more seductive.
LUKE: But how am I to know the good side from the bad?
YODA: You will know... when you are calm, at peace, passive. A Jedi uses the Force for knowledge and defense, never for attack.

What he refers to, of course, is that most ancient of all powers, the Source. When you feel calm, at peace, while you look through the Source, and aren't scrambling through it looking for a quick and easy answer to your performance problem, then you know you are channelling the Light Side of the Source. Remember, a Master uses the Source for knowledge and defense, never for a hack.

(Few people realize that Yoda, in addition to being a great Jedi Master, was also a great Master of the Source. Go back and read your Empire Strikes Back if you don't believe me--most of his teaching to Luke applies to programming just as much as it does to righting evils in the galaxy.)

All humor bits aside, the time to learn about performance and JIT compilation is not the eleventh hour; spend some time cruisng the Hotspot FAQ and the various performance-tuning books, and most importantly, if you see a result that doesn't jibe with your experience, ask yourself "why".


Monday, January 15, 2007 2:51:37 PM (Pacific Standard Time, UTC-08:00)
When was the last time you met a 30 year old COBOL programmer? ;-)
Anonymous
Tuesday, January 16, 2007 11:57:46 PM (Pacific Standard Time, UTC-08:00)
Optimize for what?

I really don't want such a feature in my IDE. The fact that the JVM or CLR is faster to handle incremental loops than decremental loops should not be my concern. This might be different in the next version of JVM and CLR.

Optimization for performance and understandability can't come from a tool. It comes from overview by the developer. I think the only way to avoid such code is lots of review etc. :)
Thursday, January 18, 2007 10:08:28 AM (Pacific Standard Time, UTC-08:00)
>>... I simply don't want any developer on the team to "optimize", because I know what their optimizations will be like ...<<

Sounds like you have little confidence in the ability of those developers - so what are you doing to bring them up to standard or weed them out?

Do they even get as much on-the-job training as a Starbucks barrista?

Do they have mentors?
Isaac Gouy
Saturday, January 20, 2007 5:05:31 PM (Pacific Standard Time, UTC-08:00)
I love the Yoda reference. There is a world to learn from Yoda. I have a quote on my website (http://www.StupidProgrammer.com) that I could see him saying.

"Stupid Programmer You Are" --Master Programmer Yoda
Wednesday, January 24, 2007 8:27:30 AM (Pacific Standard Time, UTC-08:00)
Rune, you totally and completely missed Ted's point (but that didn't stop you from commenting!). What he wants is for the IDE to provide feedback to the bad programmers telling them "Stop programming like that!"
Brian Goetz
Wednesday, January 24, 2007 8:28:14 AM (Pacific Standard Time, UTC-08:00)
One of my favorite premature optimization stories:

http://www.flounder.com/optimization.htm
Brian Goetz
Comments are closed.