why ; ?

Nick Sabalausky a at a.a
Thu May 8 10:40:21 PDT 2008


> Really. You are telling me that is ugly to have a '\' in 0.6% lines of 
> code
> but is pretty to have ';' in 100% of them??? It doesn't makes any sense to
> me...
>

I think we're starting to get more into an issue of preferences here, but:

Aside from the fact that ";" is only used on statements that don't end in a 
"{}" code block, I would have to say: yes, definitely. Personally, I find 
the rule "A statement is ended by either a semicolon or a curly-brace code 
block (where applicable)" to be cleaner and more consistent than "Statements 
end with a newline unless a "\" is used or the compiler is able to infer the 
statement shouldn't end", plus it allows me to rearrange portions of a long 
statement for readability without messing with adding/removing/moving "\" 
operators. Of course, in some cases, I can omit the "\", but that means I 
have to worry about "Do I need it here, or not?". Which first of all 
violates "don't make me think", and secondly leads to:

FormatString("This ({}) is a number, and this is a very," \
             "very, very long string. Yes it is, yes it is.",
             thisIsA + (rather() * longComputation) + orAtLeast \
             IAmTrying(toMakeItSo) - (yesIam * 2))

The use of multiple lines in that is very ugly. Of course, this can be 
solved by either trying to arrange parentheses in a way that side-steps the 
need for "\" (ie, very kludgey), or by saying "screw it, I'm using '\' on 
all the lines" (ie, effectively eliminating the "don't need it on parameter 
lists" feature), or by doing "FormatString(preComputedStr, 
preComputedValue)" (but why should I have to?)

Also, I've seen a lot of ECMAScript code that has semicolons on some lines 
and lacks it on others, just on the whim of the coder - that strikes me as 
very messy. Consistency is pretty.

Regarding remembering the semicolon, I haven't found that to be a problem. I 
find I do it naturally without even thinking about it, at least whenever I 
haven't been spending a lot of time in a language like VB which outright 
forbids semicolons. But even then, the compiler will tell me exactly where I 
went wrong until I can get the VB out of my head, so no big deal. 





More information about the Digitalmars-d mailing list