Live data from Hacker News

Ask HN: How to make fewer mistakes?

news.ycombinator.com

21–30 of 75 posts

Re: Ask HN: How to make fewer mistakes?

#22

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…

Agreed. We learn by making mistakes. Also you have only 3 years experience. It takes more like 10 years to become a "good" developer in my opinion. And even they still make mistakes, they are just less obvious ones.

Re: Ask HN: How to make fewer mistakes?

#23
Find another developer like and try to find mistakes in his code while he tries to find mistakes in your code. Trying to find mistakes is not the same mindset as trying to produce good code. Maybe you can go as far as writing the unit test of each other. I have used this trick mainly to test GUI.

Re: Ask HN: How to make fewer mistakes?

#24
I think it's something you learn the more experience you have. I think the more mistakes, errors and bugs you see through your career, the better you get at recognizing pitfalls when you write code.

Also, I'm a big fan of and practice "defensive" programming. There's lots of articles written about that, but in short it kind of changes your mindset a little and steers it towards more robust code. What can fail? How can I limit and validate parameters most efficiently?

Re: Ask HN: How to make fewer mistakes?

#25
Not sure if this is exactly what you have in mind, but I have had good success with my method of "learning from my bugs". Whenever I encounter a difficult bug, I write a short entry in my bugs file. I detail what happened, what I overlooked, where I should have found the bug (coding, testing). I also write down lessons learned from it, and I try to regularly review the lessons.

More info here: https://henrikwarne.com/2016/04/28/learning-from-your-bugs/

and here: https://henrikwarne.com/2016/06/16/18-lessons-from-13-years-...

Re: Ask HN: How to make fewer mistakes?

#27
You already part of the way there just by asking. Wanting to get better and knowing you can learn more is the first and hardest step. I'd also suggest that you force yourself to become more introspective. When you make a silly mistake that breaks your code, spend time thinking about why it broke and why you didn't see it the first time. Find a mentor that is smarter and more talented. Talk to them, look at their code, etc.

Re: Ask HN: How to make fewer mistakes?

#28
Confirm results through orthogonal means where possible.

If it comes to it write two solutions (possibly one optimized, one not) that solve the same problem in different ways, and confirm the results against each other.

Don’t count on just picking good edge cases.

Re: Ask HN: How to make fewer mistakes?

#29
post #20

When I was getting my pilot's license, multiple times I started up without unchaining the tail. I joked about it with another instructor, and he basically said that it had literally never happened to him and that I should be doing a final walk around. I'd done even more embarrassing things, sitting at the runway ready to go and the tower tells me my baggage door is open. Since making that final walk around a habit, n…

The final walk around habit is great. It's even better if routine checks like these are part of a checklist you follow. When performing habitual actions it's possible to get a minor interruption/daydream and accidentally skip some check. Having an actual list of bullet points to go through helps against this.

Re: Ask HN: How to make fewer mistakes?

#30
One way that helps me is to read the code I wrote in several different contexts.

Most of my code reading is in my editor. I'm in a certain mode of thought there, mostly detail-oriented as I piece things together. When committing code, I use git diff to inspect everything going into the commit, making sure I agree with it. I do this in a terminal (I don't use a terminal-based editor) with a different color scheme. Lastly, I'll re-read it again (especially if I'm not 100% sure) on a web-based git server (Github/Gitlab) as a way to get some closure on the day/commit.

This works well for me because:

* Most committed code is read at least twice

* Each reading context is different, at least visually

* Time passes between each reading, which gives your brain space to surface doubts

Doubt is your friend here. With enough experience, you'll know when you've nailed something.

Post reply on HN