Live data from Hacker News

Ask HN: How to make fewer mistakes?

news.ycombinator.com

1–10 of 75 posts

Ask HN: How to make fewer mistakes?

#1
I'm a developer for almost three years, i (like) to think that i'm good, i have deep knowledge of my stack and i can design and implement almost any feature that the seniors at my team can implement, but i have i problem with the final quality of my code.

My code is clean and follow the guide-lines, but i feel that i make to much mistakes, there is always a corner case that i don't think about or some test that is trivial to the QA team but i didn't do, and my code end up being broke.

This 'behavior' also happen with maths, i know the theorems and the content that i need to know to solve questions but i always miss calculate something and end up with the wrong result, one clear example of this was my last "calculus 2" exam, all the steps were right, but all the results were wrong;

TL, DR: I know my stack and the tools but i make silly mistakes that end up breaking my code; how can one get better at this?

Re: Ask HN: How to make fewer mistakes?

#3
This may not be what you want to hear.

Making mistakes properly is progress. Make the exact same mistake multiple times? You might need to write them down as you find them.

At one startup we had a motto: Measure once, cut twice. Being fix the bug, then write code to mitigate that risk in the future. Fix it twice.

Now in critical systems like traffic lights and the like, mistakes kill people, so you test the everloving crap out of everything, then another person does, and another.

If your code doesn’t kill people, ease up on yourself a bit.

Re: Ask HN: How to make fewer mistakes?

#4
I have the exact same problem as you. The reason why I behave like that is always due to some sort of anxiety in finishing the task at hand, together with a flawed protocol to design and review it.

So what seems to help me is:

- slow down, more time equals more time to think

- write specifications as neatly as possible and review it with the requester (even if it is only your self, review it many times). The more bullet points (checks, and tasks) the better. (Come to think of it, the number of checkable bullet points in an specification may be a good proxy for how much you are thinking on corner cases and etc)

- write extensible tests, read some nice TDD books (I haven't done that myself, but having some canon way of thinking about tests, together with reviewing tests can help you)

- incorporate the expectation that there will be mistakes onto yourself, onto the client and into your planning

- practice practice practice

Re: Ask HN: How to make fewer mistakes?

#5
Knowing edge/corner cases is experience based. You have to understand the business domain to really understand how those types of things come up. As a senior dev starting at a new company less than 2 years ago, I still don't recognize edge cases as often as others that have been there longer.

I would suggest checking your work might help. Put it down and do something else, then come back to it and pretend you are doing a code review of it.

When you state final quality of code, your work doesn't need to be perfect before another human looks at it. That is why we work in teams. I'm not saying be sloppy on purpose but if QA is coming up with trivial test additions, just add them. People should have feedback on code reviews.

If the mistakes you are making are trivial, we've all made them and all still make them. Syntax errors and mis-typed variables trip me up all the time. Those are usually easy to find because the code doesn't work. If the mistakes are more design related then get some software design reviews from a senior dev before going deep into having code written.

Re: Ask HN: How to make fewer mistakes?

#6

This may not be what you want to hear. Making mistakes properly is progress. Make the exact same mistake multiple times? You might need to write them down as you find them. At one startup we had a motto: Measure once, cut twice. Being fix the bug, then write code to mitigate that risk in the future. Fix it twice. Now in critical systems like traffic lights and the like, mistakes kill people, so you test the everlovin…

Thank you for your comment, sometimes im bit to hard on myself;

I can learn from my mistakes, but some of them are really trivial, i can find better examples in math, like:

In a calculus question, I need to find the volume inside some functions, this type of question is not new, i know how to solve, but somewhere deep in the calculation i change 'integral of sin' to be `cos` instead of `-cos` making the everything more hard to solve and obviously getting the wrong answer.

This kind of thing is currently my biggest problem and i cant find a real way to improve.

Re: Ask HN: How to make fewer mistakes?

#7
post #4

I have the exact same problem as you. The reason why I behave like that is always due to some sort of anxiety in finishing the task at hand, together with a flawed protocol to design and review it. So what seems to help me is: - slow down, more time equals more time to think - write specifications as neatly as possible and review it with the requester (even if it is only your self, review it many times). The more bul…

I'm gonna start writing more, i giving myself more time to code and review.

Do you have any recommendations on TDD books?

Re: Ask HN: How to make fewer mistakes?

#8
I would like to sum up the comments + my thoughts:

1. The more time you put on a task, more mistakes you find and fix.

2. When finished with a task, come back to it after some time you will find more mistakes with fresh thoughts.

3. This means you have other good qualities like imagination and creativity, which is a side effect of mistakes (internal mind random mistakes).

4. Find mistakes ancestors - patterns - write them down in a short list, my top 10 mistakes patterns. When finished with a task review that you didn't repeat those 10 mistake patterns.

Re: Ask HN: How to make fewer mistakes?

#9
I believe my #1 defense against mistakes is the faint unease in the back of my mind that arises when I don't completely understand the problem. If I become aware of this nagging doubt, and follow it, it leads to the part I don't completely understand, where mistakes are likely. You can spend quite a long time seemingly immersed in a problem space without really understanding all of it. I think I may unconsciously flinch away from specific areas I understand least, because it's more comfortable to re-analyze the parts I have a good grasp on. I find once I understand a problem well enough that I have any business checking in code, and there's none of that nagging unease, then it's usually mostly correct.

Re: Ask HN: How to make fewer mistakes?

#10
post #6

This may not be what you want to hear. Making mistakes properly is progress. Make the exact same mistake multiple times? You might need to write them down as you find them. At one startup we had a motto: Measure once, cut twice. Being fix the bug, then write code to mitigate that risk in the future. Fix it twice. Now in critical systems like traffic lights and the like, mistakes kill people, so you test the everlovin…

Thank you for your comment, sometimes im bit to hard on myself; I can learn from my mistakes, but some of them are really trivial, i can find better examples in math, like: In a calculus question, I need to find the volume inside some functions, this type of question is not new, i know how to solve, but somewhere deep in the calculation i change 'integral of sin' to be `cos` instead of `-cos` making the everything mo…

Everyone makes mistakes, the trick is catching them before you release to QA. In your math example, you should have some sort of test harness that tests your method against known inputs and outputs. It can be as simple as a throwaway console app.
Post reply on HN