22 ms·
To me, the second one loses the readability of the first. The second one makes it clear that this function changes the state of something by writing to certain
by dagw 8y ago
To me, the second one loses the readability of the first.
The second one makes it clear that this function changes the state of something by writing to certain memory locations, the first one doesn't. To me that makes the second one more readable.
- Nursie 8y ago> The second one makes it clear that this function changes the state of something by writing to certain memory locations Seriously? So all state changes need to be made in 'main'? Pretend there was no explicit state change in there, does that change your mind? What if doHighlevelThing3 is actually called "changeTheThing", and the actual write to the memory location is simply the low-level implementation of that? That's a really weird objection (to me, I acknowledge this is all style and I am opinionated).
- latch 8y agoCarmack has been consistent for a long time that state changes are a major source of bugs. It's true that video games might be more susceptible to this. I think all things considered, readability should generally take a back seat to correctness. I mean, the code is readable, yay!, but the game crashes randomly...not so yay... Also, he does offer a suggestion to help address your concern: "Using large comment blocks inside the major function to delimit the minor functions is a good idea for quick scanning, and often enclosing it in a bare braced section to scope the local variables and allow editor collapsing of the section is useful." Finally, note that he's only suggestion that you CONSIDER it, which was my original point. It's hard to say his suggestions are wrong, when his suggestions are merely that you consider it.
- Nursie 8y ago> I think all things considered, readability should generally take a back seat to correctness. I think that lack of readability is a sure path to lack of correctness, personally. Carmack may have had the luxury of working with consistently great engineers... I do not :) I'm not saying his suggestions are wrong, merely that there are times when encapsulation makes sense. Code can be readable and correct.