Cor said:
Hi Paul,
That "then" I do also not like, however until now it was the only one
I could find in VB.net that is really needed (however I would like it
when the next and loop was one word)
That while C# has a lot of unused (), semicolons, unneeded enclossing
of an If statement, uses the == as a equalcomparer even when it is
obvious from the syntax that it can nothing else than an
equalcomparer when = is used.
There's no need to get political about this. What kinds of syntax people
like is purely preference and strictly their business. If anything, we need
to be glad these choices exist and we're not forced on one language and one
syntax. So keep your cool everyone. ^_^
And also, the "Then" does serve a purpose. It serves the same purpose as the
() in the C# if statement; seperating the conditional expression from the
statement that comes after it. This is because it is still possible
(although I don't know anyone who does that) to put the following statement
on the same line as the if.
In C# you can say:
if( y == 1 ) y++;
And in VB you can say;
If y = 1 Then y += 1
Without the () or Then the compiler wouldn't be able to tell where the
conditional expression ends and the statement begins.
In good old BASIC (and I mean OLD, as in before Quick Basic, as in MBASIC,
GW-BASIC, MSX-BASIC, the types that required line numbers) there were no
If...End If blocks. If statements had to be one line, and if you wanted to
execute multiple statements after the same if, you either seperated them
using a colon
) on the same line, or used goto. In those days, "Then" was
the only thing standing between the If and its result. Note that in an act
of equality, the Else also had to be on the same line. Great syntax that
was... ^_^
In those days you could actually put other things than "Then" behind an if.
There were three variants if I remember correctly:
IF Y = 1 THEN Y = Y + 1
IF Y = 1 GOTO 100
IF Y = 1 GOSUB 200
Thankfully the second form isn't allowed anymore, and gosub has long been
burried as it should be.
When using an If...End If block, the Then becomes unnecessary, because the
new line is enough seperation (in C# though you must keep the () *and* add
curly braces, so one could argue that's even worse), but it is kept for the
sake of consistency.
And in all honesty, does it matter? With modern editors like VS.NET you
don't actually have to type it anyway, it is inserted automatically when you
press enter after the conditional expression. So it doesn't matter anyway.
However those who are happy with all those useless characters in C#
and start a discussion here.
I think it is not that much work to make a precompiler for that using
VB.net, which will automaticly correct those needed special
characters in C# when you have not placed them.
Not possible in general, because newline isn't a seperator in C#. If there's
no semicolon, curly brace, () or whatever to seperate things, the statement
just continues on the next line, just as if the newline hadn't been there at
all. Without all those so-called 'useless' characters it becomes possible to
create unparsable constructs where such constructs would be valid when
they're there.