Trevor Burnham

Sure, it works in practice…

Always Be Exploring

December 29th, 2009

Anti-syphilis poster: Get tested!This post by math/​CS prof Peter Boothe caught my eye:

What I am claiming here is not just that if you code faster, you will get your solution written faster. I am claiming if you code faster, you will get your solution done MUCH faster. The speedup is greater than linear.

I agreed with the sen­ti­ment, but I wasn’t sure about his expla­na­tion. Then I read this comment from Matt Kangas:

IMO, the key point is: teach exploratory programming.

That’s the answer! Here’s my expe­ri­ence: I took exactly one CS class as an under­grad; it was so arduous, so time-​​consuming, that I vowed to myself: Never again. But I kept being drawn to various pro­gram­ming projects, so I learned to code com­pe­tently on my own time. At some point last summer, I think I hit the 10,000 hours of practice that Malcolm Gladwell posits as a heuris­tic pre­req­ui­site for being really good at some­thing. One thing I learned around hour #7,500 was the impor­tance of testing pieces of code inde­pen­dently as much as possible when building a larger project. Begin­ners always work at the appli­ca­tion level: Change some­thing, re-​​run the appli­ca­tion, see if it works. This is some­times nec­es­sary (if, say, you’re changing the UI), but should be avoided whenever possible. Experts tend to write code in small, unit-​​testable pieces. Many are test-​​driven.

Not every test has to be a formal unit test. Just trying out a line or two of code on its own and watching what happens is often useful. This is yet another reason why Java is dead to me as a language. Java is so slanted toward BDUF that when it sprang forth Athena-​​like from the head of James Gosling, it was blessed (?) with a formal standard for doc­u­men­ta­tion, but no command line interpreter—a feature offered by just about every other language, includ­ing Java’s spritely yet statically-​​typed spawn, Scala.

For those of you building anything big enough for Hofstadter’s Law to apply, my #1 piece of advice would be this: Get your code tested, today!

Tags:   2 Comments

2 responses so far ↓

  • There is some truth here, also some truth in Pete’s post.

    Coding fast is a good thing no doubt, but it’s hardly a be all end all.

    I rank the fol­low­ing as far more important:

    Thinking clearly about your problem and the abstrac­tions you will use for solving it is the first and foremost task for a software engineer.

    Decom­po­si­tion, which is related to good abstrac­tions, is the ability to find the relevant (inde­pen­dent) sub-​​problems and solve them (independently).

    This ability then goes hand in hand with inter­face design, and here I do not mean UI design, but API design. Con­sis­tent, well-​​thought through inter­faces that are easy to learn, easy to remember, antic­i­pate a client’s needs, and are easily com­pos­able, are a key to good software.

    Coding is the thing you do at the end when the problem is solved.

    That said, you and Pete give a good descrip­tion of how I pro­to­type. This is almost always under­stood to be throw away code though, and is not always necessary.

    The “fast coding” thing is nice when:
    1) I don’t under­stand the tech­nol­ogy I’m working with very well.
    2) When there is a tricky algo­rith­mic aspect to what I’m doing.
    3) When I’m devel­op­ing a new tech­nique or idiom.
    4) When I’m not exactly sure where I’m going or don’t feel like thinking through a problem. After all it is fun to hack sometimes.

    Clearly #1-#3 imply smaller chunks of code, while #4 is basi­cally cowboy coding and probably should be dis­cour­aged for “real” projects.

    And yes, test-​​driven code is an asset. It should be obvious that good abstrac­tions, good decom­po­si­tion, and good inter­faces aide the test-​​driven methodology.

  • I’m glad you liked it, and espe­cially glad that it stirred up some­thing in your brain!

    I think I agree with you in broad strokes — testing and exper­i­men­ta­tion and exploratory pro­gram­ming are large reasons for increased speed. But it’s impor­tant to empha­size that it’s the under­ly­ing fluency and ability to make small changes quickly that makes those tech­niques useful. You can’t be agile if you aren’t small and quick. If that quick­ness weren’t there, then exploratory pro­gram­ming would have a *huge* time cost, and would not be nearly so useful. With larger time costs comes an increas­ing tendency to do a BDUF and that leads to decreased speeds, which leads to larger time costs, which leads to a greater tendency to do a BDUF, which leads to.…

    Anyhow, it’s exactly the native fluency and will­ing­ness to exper­i­ment that I need to impart to my students, but I am unclear how to teach it. It seems like a “knack” more than a tra­di­tional body of knowl­edge or a skill, which means that the best I can cur­rently do is repeat­edly throw students at problems which benefit from that knack until they start to develop the knack. But that’s basi­cally hazing, and surely there is some less cruel way to go about impart­ing an exploratory attitude and fluency…