We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I'm starting a bigger project and wanted to make sure it would be understandable, so I started adding comments but I feel like I'm way over doing it after looking around a bit.
Here's a snippet
//This is the start scene.
void sceneZero() {
boolean returnButtonDisappeared = true;
boolean usernameBoxDisappeared = true;
//If the previous scene was the menu scene.
if (previousScene == 3) {
//The booleans will be set to false if the objects haven't disappeared.
returnButtonDisappeared = returnButtonDisappear();
usernameBoxDisappeared = usernameBoxDisappear();
//If either of the objects haven't disappeared keep drawing that object.
if (!returnButtonDisappeared) returnButton();
if (!usernameBoxDisappeared) usernameBox();
}
//If both the objects have disappeared draw the new objects and make them appear.
if (usernameBoxDisappeared && returnButtonDisappeared) {
specialThanksAppear();
pressHereAppear();
specialThanks();
pressHere();
}
}
Or is this a normal amount of comments?
Comments
How long is a piece of string?
There is no correct answer. Your comments should explain what the program does so that you can maintain the source code. If you come back to your code after a six month absence and understand it, then you have enough comments.
The comment above becomes unecessary by defining state constants: *-:)
Try to avoid negative names for flags because you end up writing statements like
When in doubt, add comments.
Good variable naming can make some comments redundant -- it is obvious what is happening from the code. This might need multiple comments:
vs. this doesn't need any comments:
You can also use functions and methods to make code more readable without comments. This code might need every line explained:
vs. this, with function names doing the labeling, and making the code itself concise and easy to read: