Quote:
Originally Posted by Gambet
Not true, Java's switch() does not only allow ints (it also allows char, byte, and short types), and for that matter, switch() works the same in just about every other popular language (such as C++ which was used largely in making Graal).
|
All the languages that do switch statements and only allow you switch on integral types do that on account of having copied the syntax pretty much verbatim from C.
D lets you switch on strings, perl does not let you switch at all unless you write your own switchiness, ruby lets you switch on pretty much goddamn anything that defines an operator for matching a switch case. In Haskell and Nemerle, a switch-like structure is the basic low-level control structure and works for everything as well.
Quote:
Regardless, though, I still feel that it was quite unnecessary in this case.
|
I think it is purely a matter of style, here. Checking a variable against a sequence of values looks neater if you do not have to repeat the "variable ==" over and over, but all the break;s are pretty annoying too, I guess.
Quote:
I agree that it isn't so important for this example, but when you're dealing with large scripts (such as the code for Windows that is well past millions of lines), it is quite important to shorten the number of lines as much as possible. Just a general tip.
|
No, generally you want to make sure your code is as readable and maintainable as possible. The number of lines should only enter it a whole lot after that.