TLDR; being forced to manually add a colon when the parser already knows there should be a colon is intrinsically pointless labour.
I have 40 years programming experience, so I understand tokens, parsers etc. I understand { }, if /then/endif etc etc. But, so far, I haven’t got in the habit of using a : on the end of an if statement in Godot, and it annoys me when I forget it and the editor throws an error. Let me explain why:
In C, the tokens are needed because whitespace is ignored, ie
if (a==2)
{
printf("inside if");
}
printf("after if");
is equivalent to
if (a==2) { printf("inside if"); } printf("after if");
But Godot uses EOL and indentation to replace tokens. Comparing GDScript to C:
if a==2: # : is equivalent to {
print("inside if") # EOL implies ;
# change in indentation implies }
print("after if") # EOL implies ;
So, why doesn’t GDScipt use if + EOL to imply { ? ie
if a==2 # if + EOL implies {
print("inside if") # EOL implies ;
# change in indentation implies }
print("after if") # EOL implies ;
@gertkeno argues that requiring the parser to identify ‘if’ so that EOL implies ‘{’ would add more complexity, but the parser must already do this to be able to complain about the missing colon!
I hate using indentation to denote scope, but it grates even more that, even though I must get the indentation right I also have to use a token, but only at the top of the block. For goodness sake, use indentation or tokens but not both!
@wyattbiker makes a valid point that without the colon there’s room for error. Yes, that’s why languages have used tokens for 50+ years. Using whitespace and EOL as tokens is A Bad Idea because it means you can easily slip up. For example, instead of
if (a=2):
print("a was two")
a=5
print("a is 5")
you could end up with
if (a=2):
print("a was two")
a=5
print("a is 5")
(which is far more likely than missing “and \” off the end of an if statement) but GDScript uses whitespace and EOL as tokens and to denote scope, and we have to live with that. The problem is that it doesn’t use them consistently.
But mostly I am annoyed because the parser knows there should be a colon, so there is no need for the colon, yet I am forced by an inanimate object to manually add it. It’s not “advice”, it’s an intrinsically pointless task I am forced to do - the definition of punitive labour.