Hacker News new | ask | show | jobs
Ask HN: Is it inefficient to execute programs while working?
2 points by abhnv 1375 days ago
tldr; I execute my programs without dry running them in my head first, is that inefficient?

I have a habit of executing the entire program, after I implement a feature to check if it's working correctly.

I usually isolate my functions, in a small test environment, so the feedback loop is fast enough to highlight issues, if any.

But since I started working with a larger code bases, this approach feels inefficient. So my question is, would it be more efficient to read through the code and find out any typos or logical issues before actually executing the code?

2 comments

Depends on your environment. When writing C/C++ code, I rely on the compiler to find many problems. Once a module compiles cleanly, I link with tests to verify and then the app. When using Python and Javascript, I just repeatedly run the tests and program. Of course, I do sort of dry run the function / method / class as I write it. I'm probably in the minority, but I do write copious comments to remind myself in the future why I did things the way I did.
I think I'll try this way. I don't dry run the code enough while I write it. And I've only recently started adding comments for myself. Thanks for the tip.
It seems difficult to say, one idea is you could proceed with this approach but then write tests for any failing conditions when they arise. It seems inefficient to check every line of code works after writing it as well - especially for larger systems with complex state setup.

Probably somewhere in the middle is right but will be different for everyone/is variable

I never seem to get it. I guess trial and error is the only way then.
It makes me think of the quote something along the lines of “the master has failed more times than the beginner has even tried”

Good luck