The Dink Network

The importance of commenting your code

January 25th 2012, 11:41 PM
wizardg.gif
Paul
Peasant He/Him United States
 
It's not just so other people can make sense of it, although that's nice too, it's also in case you come back and try to read it yourself ten years later. Take this gem:
void main( void )
{
  if (&secret < 8)
    sp_active(&current_sprite, 0);
  if (&secret > 8)
    sp_active(&current_sprite, 11);
}	

January 26th 2012, 12:24 AM
anon.gif
Absolution
Peasant They/Them
The Dark Lord of the DN. 
Um... ok?
January 26th 2012, 04:38 AM
anon.gif
shevek
Ghost They/Them
 
in case you come back and try to read it yourself ten years later.

Make that ten hours. Or, in case of DinkC, where you had to torture your brain a lot more than with other languages, perhaps even ten minutes...

The code you show seems buggy, but indeed, if there would be comments they could show that it was done on purpose (which doesn't mean it was sane ) According to the docs, the active attribute can be read back. So you can use it as a variable, as long as you don't set it to 0.

The fact that &secret == 8 is skipped is most likely a real bug, though. If there's on sp_active (..., -1) in this or any other script, then you may conclude that the 11 is a typo and it would have been useless anyway to set it to 1...
January 26th 2012, 06:26 AM
custom_fish.png
SabreTrout
Noble He/Him United Kingdom
Tigertigertiger. 
Never go back, Paul.

Never go back!
January 26th 2012, 07:44 AM
spike.gif
Yeah, I know what you mean. I used to dislike comments for some reason (no reason), and actually purposefully erased all comments from my scripts. Nowadays that I dabble with Dink once maybe every few months if the mood strikes me, I've repented this decision fully. Even some really basic organizing (like adding a short description of where the script is used in the beginning) goes a long way at preventing self-induced hairloss.
January 26th 2012, 08:33 AM
custom_skull.gif
Skull
Peasant He/Him Finland bloop
A Disembodied Sod 
You either drink fifteen cups of coffee per day, or comment your code. Which ever you'll find easier.
January 26th 2012, 10:37 AM
wizardg.gif
Paul
Peasant He/Him United States
 
In case anyone is wondering, as best I can tell. The < part is correct (it should not be active until secret is at least eight), and the > part does absolutely nothing, which is probably also correct. But I have no idea why I wrote that, and I can't help worrying that there might have been a reason.
January 26th 2012, 11:57 AM
anon.gif
shevek
Ghost They/Them
 
But I have no idea why I wrote that, and I can't help worrying that there might have been a reason.

As I wrote, it is a way to store a number. But to use it, you must use sp_active (..., -1); If there is any script using that, it may be using this feature, and you can explore it. Most like there is no script doing that. In that case, if there ever was a reason you wrote it, it no longer exists.