Is there ANY chance we can fix the bitwise operator precedence rules?

Leandro Lucarella luca at llucax.com.ar
Tue Jun 22 06:04:13 PDT 2010


Steven Schveighoffer, el 22 de junio a las 07:26 me escribiste:
> On Mon, 21 Jun 2010 20:40:14 -0400, Adam Ruppe
> <destructionator at gmail.com> wrote:
> 
> >What's the point of a switch without implicit fallthrough?
> 
> Maintenance.  Using if statements instead of switch, you have to
> repeat the value to test for each of the cases.  If you want to
> change the value being tested, it's one change.  And your workaround
> using a delegate is not very appealing.

And it's a bit comfortable when used with expressions that should be
evaluated just one:

switch (foo()) {
	case xxx:
	...
	case yyy:
	...
}

vs

auto tmp = foo();
if (tmp == xxx) {
	...
else if (tmp == yyy) {
	...
}

> I'll also point out that popular languages have a switch statement
> and don't allow implicit fallthrough, meaning that 100% of switch
> statements do not have fallthrough.  And switch is used quite often
> in those languages too, so at least some people think it has use
> besides allowing implcit fallthrough.
> 
> I think mostly it's because the meaning of it is so easy to
> understand when reading/writing it.  When you see a switch, you know
> what it is and what it isn't.  An if statement has many
> possibilities and must be read more carefully.

Like for/while vs goto and foreach vs while/for. They are
specializations for common uses. It helps both the programmer to
write/read more clear code and the compiler to generate more efficient
code because they have a more defined semantics and it can make more
assumptions.

-- 
Leandro Lucarella (AKA luca)                     http://llucax.com.ar/
----------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145  104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------
Creativity is great but plagiarism is faster


More information about the Digitalmars-d mailing list