Handmade Hero » Forums » Game » Structuring of code (general question)
r2d2
20 posts
#11374 Structuring of code (general question)
4 months, 1 week ago

Hi, folks!

Perhaps Casey himself or people who are following the project closely can comment. I am at day 067 right now. During the stream Casey embeds the whole update & render part of the GAME_UPDATE_AND_RENDER function inside the Updatable check:
1
2
3
if(Entity->Updatable) {
...
}

This leads to 200 lines of codes moving deeper one level of indentation. Why not instead do the following:

1
2
3
4
5
if(!Entity->Updatable) {
  continue;
}

...

This would lead to the code that is much cleaner and understandable, as well as easier to read via diff.

Was this question ever discussed on the stream? Is there some reasoning behind this approach or is it just a habit?
ratchetfreak
276 posts
#11376 Structuring of code (general question)
4 months, 1 week ago

Casey finds early returns and break/continues harder to follow so he doesn't use them. He prefers the single flow down to single point of return.

On a wide enough screen the extra indentation doesn't matter and in a single-dev project file diffs don't really matter. And even them most diff tools let you ignore whitespace/indentation.

r2d2
20 posts
#11378 Structuring of code (general question)
4 months, 1 week ago

Fair enough, thank you for the reply. I am used to the completely opposite approach: discarding everything that's not fit right in the beginning allows me to follow the rest of the logic easier. But I'll adjust for this project.

And yes, the diff issue could be managed by ignoring whitespaces in the diff tool.