Programming Developing at the speed of thought

Here’s an idea: if you are spending more time writing code, than thinking about what code you should write – you are doing something wrong. Very wrong. Or it’s something trivial enough to not be of much importance. Or it’s Java.

Java has endless getters and setters. It’s a pushups exercise that could be replaced by auto-generated code.

Anything trivial enough to be memorized could as well be copied from elsewhere. Also of little importance.

This leaves us with everything else.

It’s a matter of thinking for 3 hours, writing 3 minutes worth of elegant code, versus thinking for 3 minutes, spending 3 hours typing up code. Even though it takes the same amount of time to arrive at a “solution”, the latter turns out to be a 1000 line long mess. Besides straining one’s fingers, and being unmaintainable, it will also end up buggy. 99% typing accuracy means that 10 lines of code will be completely off mark.

Keep it DRY – Don’t Repeat Yourself

Code repetition is the biggest tell (code smell) that something is going wrong. If you ever catch yourself copying a part of your code to paste it elsewhere in your application – stop. Refactor. Step back and think about your design.

I am absolutely amazed at students coming out with 5000 line long, text-based, trivia games for their year-end projects. The level of unique logic involved could usually be fit into 20 lines of code.

I think the fault might be with both students and teachers on this one. Lots and lots of repeated code does not deserve “effort” marks – in fact, it demonstrates the lack of many key concepts. wtd summarized the points well, in reference to this 4600 line Sudoku project:

Very little and poor use of methods. For that alone, were I your instructor, I have to say I wouldn’t be able to give you a passing grade. Of course, if your instructor hasn’t taught you any better, I’d give him/her a failing grade as well.

Spending more time typing than thinking likely means that there’s not enough thought behind the code being written. If anything seems tedious, there is probably a better way of doing that. Think.

Read more

Uhh... nothing else appears to be relevant enough.