I'll actually bite on the below since I have some input. There was a Java
to IL compiler written before C# made it's first test runs, so I can't see
Java being the *look*. Managed C++, while syntactically appearing to
be a hack, was powerful enough to handle the C++ style syntax.
The reason for the way the switch statement in C# is works is the manner
in which the underlying IL construct works. In IL a switch is nothing more
than a simple jump table. They don't provide fall through because that
would require automatic generation of goto statements within the case
statement body. In most cases fall-through in C led to unexpected results
as users failed to close the syntax when that is what they meant to do.
As for the strange look of a switch, it is a balance of verbosity and function.
You might say that each case statement could indeed be it's own block and
should use french braces the way the rest of the language does, but that
doesn't allow for any form of fall-through.
case 10 { block } case 20 { block }
Where do you fall through in the above block? How do you have the
equivalent limited fall through syntax that C# does allow?
case 10:
case 20:
break;
Note, you are also building from the concepts of a label, each case
statement is terminated by a colon, something you don't find anywhere
else in C#, yet it is there. Each case statement semantically becomes a
label of some sort, a jump table label if you will. No different from having
an OUTER: label within a loop so that you can break out of the internal
loop and continue processing the outer loop.
What I'd highly recommend is write a lexer/parser that targets C# and then
change the language the way you'd like to see it changed. See how hard/easy
it is to format the code in your new manner and see how scalable that is for
adding new features. Would, for instance, you changes to the language have
affected the almost transparent addition of generics? What about namespace
aliasing and anonymous delegates? The future of the language is just as
important
as it's past, and C# is quickly becoming a very unique and promising language in
many ways.
--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog:
http://weblogs.asp.net/justin_rogers I also wonder to what extent he was required to keep the language
looking like C++/Java, and therefore attractive to current C++/Java
programmers. This is pure speculation on my part, of course; but I see
signs of it in the language, with an example being the 'switch'
construct. The syntax of 'switch' constructs is very different to that
of other syntactical elements of C#, and it seems to stick out like a
sore thumb. It appears that it was copied straight from C (although
with a difference in that C#'s version doesn't allow implicit fall-through).
<snip>