Live data from Hacker News

Ask HN: How to reduce sloppy mistakes?

news.ycombinator.com

21–30 of 40 posts

Re: Ask HN: How to reduce sloppy mistakes?

#21
post #8

Don't use a debugger - think when something doesn't work. The feedback you get by thinking about your own code teaches you much faster than anything you get with compile/run/debug cycle. "I think that without a debugger, you don't get into that mindset where you know how it behaves, and then you fix it from there. " http://linuxmafia.com/faq/Kernel/linus-im-a-bastard-speech.h...

I have downvoted you by accident while using an iPhone. This is terrific advice though!

Re: Ask HN: How to reduce sloppy mistakes?

#22
I'd say even more F5s (assuming that's how you compile/run). There's nothing wrong with using the computer to catch a missing semicolon or parenthesis. If it takes you 20 minutes to find the error, maybe it's because you haven't been running your code often enough, rather than the reverse.

Coding is debugging just like writing is revising.

Re: Ask HN: How to reduce sloppy mistakes?

#23
Try to consider all possibilities for failure and all inputs or contingencies. If you are still coding and don't want to interrupt your "flow" to go write an error handler, just put an assertion or a comment or something that will force you to go back and write it before you compile. That way you'll know when the problem is actually solved.

With that in mind, perhaps also think about the way you are structuring your development. Do you have a mental (or physical) sketch of the code before you write it? There's something to be said for having a bit of paper to scribble on before and during the coding process. Map out little examples (e.g. "test cases") and think about how you will deal with all of them.

Finally, writing stubs (i.e. functions or modules that are basically empty) when you first start can be great. If you know you're going to need some pieces of functionality in order to solve your problem, then write stubs for those and then solve the problem (i.e. write the main program flow). Hopefully then when you come to write the supporting functions that do most of the heavy lifting, you will have clarified your intuitions around how they are supposed to work.

So my advice would be to be a little more rigorous in your approach _before_ you get to the point of having screenfuls of code in front of you.

Re: Ask HN: How to reduce sloppy mistakes?

#24
post #17
post #13

...the number of sloppy mistakes I make is still way too high... Compared to what? You may not have a problem. Sometimes "code, mistake, fix, code, mistake, fix, code, mistake, fix,..." is faster than "code it perfectly once". For me it usually is. I'd rather crank stuff out quickly and fix it than drive myself nuts thinking it through. Stupid syntax and typing errors will go away with repetition. Otherwise I wouldn'…

Why would syntax highlighting, etc. be "training wheels"? I understand that training wheels restrain what you can do with your bike, but what's the downside to coding in an IDE?

My experience is that when I code in a simple monochrome text editor, I have instinctually learned and internalized syntax, reserved words, etc. much more quickly. Kinda like shooting a basketball into a smaller hoop or driving a stick shift. Everything just flows better and I rarely have OP's problems.

Re: Ask HN: How to reduce sloppy mistakes?

#25
This sounds like a symptom of typing too much and thinking too little.

This may be a little old fashioned of me, but any time I try to solve a problem that isn't immediately obvious, I write it down on paper first (or whiteboard it).

If you can't hold the solution in your head and visualize it, then you should try to break the problem down into smaller chunks so that you can at least fully visualize all of the moving parts.

Around my office, I have a set of maxims that I always emphasize in order to keep our quality high - #2 on the list is to always measure twice before cutting (or writing, in this case); rule #1 is to pick the low hanging fruit first. There's no point in starting to code a solution until you know with a level of certainty what it is you're trying to achieve. Lots of people with debugger syndrome don't know where they're going until they happen upon a solution by coincidence instead of by intention.

Re: Ask HN: How to reduce sloppy mistakes?

#26
post #10

Using a statically typed language might also help, as the compiler can catch a lot of really stupid errors.

exactly. when i read the question i thought: i bet you are using some dynamic scripting language.

use a language a programming style that lets you catch errors early. it's amazing how much time i've wasted testing for errors after small changes in ruby programs. errors that a decent language & compiler wouldn't have allowed or detected much earlier. some languages just weren't designed with this in mind. i no longer program in ruby.

related: once upon a time, i had the idea that i should be able to write a program and have it compiler & work at the first & final attempt. code was in c. of course that failed miserably. especially with the lack of c coding experience. the lesson: don't try to be silly/"smart", use the tools to your advantage. (if your tools don't have advantages, don't use them).

Re: Ask HN: How to reduce sloppy mistakes?

#27
Speculation: Based on the principal that you can't improve what you don't measure (or, what you measure you improve), you could keep a log of the sloppy mistakes you make. After a while, maybe patterns will emerge and you can attack 'mistyping numbers' separately from 'missing cases in a switch block' and 'correct behaviour of nested-if took 5 attempts'.

Re: Ask HN: How to reduce sloppy mistakes?

#28

tests tests tests I use a little tool that runs unit tests on compilation, when Im doing something new that unit tests works well with, I write a bunch of tests and just code until I have 100% tests passing.

Exactly. We aren't writing code on punch cards, getting it right the first time isn't a huge deal.

If you make a lot of mistakes, have sanity tests cover your ass.

Post reply on HN