Live data from Hacker News

Don't write bugs

teamten.com

41–50 of 113 posts

Re: Don't write bugs

#41

Use tools that make it harder. Immutable datastructures, side effects constrained to a few places, good static typing etc. Where I worked before we had 100k LoC Elm projects with virtually no bugs. Now I'm working in a python/django codebase with probably thousands of small hidden bugs.

Use tools that make it harder. Immutable datastructures, side effects constrained to a few places, good static typing etc.

Those are good things, but they only eliminate the class of bugs where the code is wrong. Some bugs, and most important bugs, are problems where you've written entirely valid and working code that does the wrong thing. That is where going back and reading your code again, and having layers of review from your peers, will help most.

Re: Don't write bugs

#42
post #41

Use tools that make it harder. Immutable datastructures, side effects constrained to a few places, good static typing etc. Where I worked before we had 100k LoC Elm projects with virtually no bugs. Now I'm working in a python/django codebase with probably thousands of small hidden bugs.

Use tools that make it harder. Immutable datastructures, side effects constrained to a few places, good static typing etc. Those are good things, but they only eliminate the class of bugs where the code is wrong. Some bugs, and most important bugs, are problems where you've written entirely valid and working code that does the wrong thing. That is where going back and reading your code again, and having layers of rev…

Yes, but eliminating those classes allow you to spend more time where it matters.

Re: Don't write bugs

#43
I have a problem with this way of thinking.

Yes, you can actually focus on not writing any bugs, but should you?

We have limited attention and mental resources.

If you're fixing your car, should you focus on not getting any oil on yourself? Yes, you take precautions but that should not be your main focus.

Re: Don't write bugs

#44
post #43

I have a problem with this way of thinking. Yes, you can actually focus on not writing any bugs, but should you? We have limited attention and mental resources. If you're fixing your car, should you focus on not getting any oil on yourself? Yes, you take precautions but that should not be your main focus.

In pro kitchens, the chefs DO spend time and effort NOT getting spills on themselves, on cleanjng their surfaces often, on tidying up as they go. This keeps the kitchen running smoothly and the food safer and more presentable. The process allows their creativity with flavour to come to the fore.

Re: Don't write bugs

#46

When writing code you have a mental model of the machine, and the language and libraries. Back in the day those mental models could be close enough to reality that writing bug free code could be a choice. It would take time but you can essentially run the program in your head. This is an old timer, back when machines and abstractions were simpler. The post makes sense in that context, but today you can't have a compl…

You can get that same effect today, just work in the same stack with the same libraries for years and you will learn exactly how everything works. Just need a stack that doesn't do breaking changes that often.

If programming worked like the more manual jobs like plumbing then you'd work 5 years on a stack before they'd call you proficient at it. But nowadays you work 2 years before changing jobs to another stack, and after 5 you are expected to manage people and no longer write code. So the problem is mostly organizational and not technical.

Re: Don't write bugs

#48
Most of my bugs are the result of the wrong punctuation. Get a period instead of a comma after that array element, it's head-smacking and squinting time again.

Written human language is much more forgiving. Just periods and commas are enough most of the time. But with computer languages, it's most of the keys on the \*&#|}|"|{:"?><,./#$(! keyboard.

Re: Don't write bugs

#49

During the early part of my career I decided to just not write bugs. Was the best decision I made, I've saved myself countless hours

Not sure if you are serious or not, but I agree with that statement. Of course you cannot write completely bug free code, but practicing competitive programming until I could write complex 100 line programs bug free in 10 minutes is probably the most well spent time I've ever done in life.

Being able to write big bug free chunks means that if I think of something I want to do, then write the 500 line implementation without even compiling or running the code it tend to work the first time I run it. Of course that code isn't production ready, but it helps immensely in writing prototypes and mapping out problem spaces. So when another person does their thing and implement 1 solution, I've written 10 different solutions testing a lot of different architectures and picked the best one.

Edit: I think the biggest win from doing this is that although writing code is the easy and effortless part, debugging your code afterwards is extremely mentally draining and takes away mental energy you could be using to think about architecture etc. Think like this, how much high quality thinking have you wasted on debugging your code? Now imagine if you with a little bit of deliberate practice could eliminate most of that waste, wouldn't you do it?

Re: Don't write bugs

#50
This is like telling a poor person: Just earn a million dollars!

Then you can try with an smoker: Just don't smoke!

Finally you can tell an obese person to loose weight.

They are such high level statements that it is completely useless advice without implementation details.

Neither me or anyone on my team write significant bugs. We spend a very small part of our time dealing with bugs. But for this lots of knowledge, discipline and practice is needed.

You can fill several books just with that knowledge alone.

Rereading your code for me is completely useless. When I was a kid I reread code for days without finding the bug because I just make the same (wrong and most of the time subconscious) assumption over and over again. Then I learn better strategies.

A simple tool that checks for wrong assumptions finds those bugs in seconds.

You can log your bugs so you identify recurring patterns and can correct those patterns.

With just a team of three, I wrote a tool that gave an error for any "one line if" without parenthesis after fixing the nth time the recurring bug: People will write a one liner if without parenthesis and then a year from that will add an additional line to the if without adding a parenthesis because they were just so focused in the new problem they just could not see anything wrong while rereading the indented line.

We even use statistical Bayesian analysis of code that automatically highlights any code that goes against the style of her author. In that code she is not experienced and could make the wrong assumptions so must be careful.

Asserts everywhere in developer code that are automatically eliminated in production code(but remain in developer). We assert everything because bugs just pop up from the asserts again in seconds.

Also incremental tests between revisions is extremely useful. Your test work flawlessly in last revision, you changed 20 lines. It doesn't work, the error is in those lines. The smaller the increment, the easiest to find the problem.

Those things are obvious for experienced programmers, but for other people could be magic and sorcery, because there are many details needed to make it work.

Post reply on HN