Wednesday, April 12, 2017

Code Slow Finish Fast

Looking through student code today brought this quote to mind.

“I didn't have time to write a short letter, so I wrote a long one instead.” Mark Twain

Students are always in a hurry to write the code for programming projects. No matter how strongly I suggest they think about the problem and design their code most of them start coding right away. This often results is a lot of code where a small amount of code will work just as well if not better.

Often the techniques for less code require a bit more thought. Setting up a long set of if statements with a bunch of different variable names is tedious but doesn’t always require as much planning as setting up an array and loop solution does. Students are in a hurry so they take what they think are shortcuts.

Experience tells of course. My version of Whack A Mole (our current programming project) can be changed from 5 possible “moles” to 6 by changing one 5 to a 6. Some of my students would have to write, well let’s just say I don’t want to do the math.  We’ll go over the options during our next class. The theme will be to think more before starting to code though.

4 comments:

  1. A never ending struggle.

    Am I just doing a quick script to massage some data or will I have to use it again? Just once? Ok, I'll do it quick and dirty.

    Months later -- doing it again?

    How many times before it's time to refactor?

    Even experienced programmers can have a hard time knowing when it's best to bang it out and when it's best to be more clever or general.

    Great topic for ongoing discussion with a class though.

    ReplyDelete
  2. It's interesting that coding competitions reward quick and dirty rather than well thought out, designed, and implemented.

    ReplyDelete
  3. The quick and dirty is one of my problems with most coding competitions. I prefer events that have a longer time frame and involve more significant projects.

    ReplyDelete
  4. Garth1:18 PM

    Doing it right takes all the fun out of it. How does that saying go? "Two hours of code hacking prevents five minutes of thinking."

    ReplyDelete