Wednesday, February 11, 2009

Ninja Vs Samurai

Wil Shipley wrote a little piece about software about a year ago.  The line that caught my eye was
"* The Way of the Code Samurai *

Now, I don't actually know much about real samurai, but the basic thing I've heard is they stand and stare at each other for hours, and then suddenly BAM strike once and the other guy is down.

That's how you should code."

Of course, I cannot let such a line go past unanswered.....

His points are excellent - think before you code, plan to do it over, write it clean as you go, and optimize later on.

Where he runs afoul of the Ninja Way is that he writes all this as if there are no managers breathing down your neck to get something written and delivered, or a Project Leader who will squash your raise if you are modifying code outside the area of the bugfix you are supposed to be doing.  The Samurai were a favored class in their world, so they thought little of how to do things against the Powers That Be.  The Ninja had to work from the bottom up.

So to get the time to think before you code the Ninja must start coding something - the spike solution Wil mentions, but even if you don't have an idea, start writing your test harness.

To get the chance to do it over, leave off a necessary, but tangential part of it - the UI, or the fringes of the API - stuff that is not necessary for the proof of concept, but expected in the final delivery.

To write it clean, adopt habits that support this - check flags with method calls if you expect conditions to be based on non-boolean values or several different flags; keep methods small, so that they can be refactored/rewritten quickly as you need to; learn the GoF patterns in your langauge, so that you can implement them quickly [heck, write them up as templates in your worksapce, so you can drop them in easily].




Technorati Tags --
, , ,
HTTP

No comments: