6 ms·
Ask HN: How can I use the scientific method to write better code?
Highly enjoyed this previous post on empirical evidence available for dev practices (https://news.ycombinator.com/item?id=28178257)
This made me start thinking about my own practices, and what processes I could adopt to improve. What suggestions do you have where I can adopt the scientific method to my daily coding, research and software architecting work?
- giantg2 5y agoBasically try things and select the ones that work. Make a note of what worked or didn't work. Then automate the working solutions to avoid human error when implementing them in th future. Use this process recursively to refine your hypothesis/results for further enhancements.
- atmosx 5y agoSince there's no clear definition of _better_ you can't. The point of the scientific method is to test a theory against natural laws. Assume you write a function using all the tricks in the book. It's fast(er) than the proposed solution on the PR review, but unreadable. If merged, future team members might have a hard time understanding what's happening. If not merged, the code will be slower (milliseconds x thousands of requests). Which way to go? :-)
- djmips 5y agoOptimizing is perhaps one of the best applications of scientific reasoning in programming since the 'natural law' in this case is how the hardware actually works as opposed to whatever wrong abstraction you start with. Sometimes it is more important to be fast so in that case you know which way to go.
- djmips 5y agoLike others say, keep a journal of your work. Measure things and write them down. Do experiments. There is a lot of extra effort involved and just like in real science, you can be fooled by bad data.
- agomez314 5y agothanks! will start doing that.
- hidden-spyder 5y agoDo you have any examples to further elaborate your points? I can't think about how to actually apply those and would like some help visualizing it.
- muzani 5y agoScience isn't always better. It's unstoppable - you don't lose ground and you will always inch closer to the truth. But it's the slowest approach. It's usually best to leave it to academics like this rather than applying it daily. (Is there a scientific study to how effective science is in daily work?) I'd recommend reading Zen and the Art of Motorcycle Maintenance though. It covers exactly this topic, the advantages of the scientific method, and where philosophical methods can work better.
- gitgud 5y agoDefine "better"... Do you mean, better readability, better performance, better extensibility, better reliability... It's immensely difficult to get better in all directions. But if you focus on what you want to get better at, then it's easy to find resources to help.