Sorry Russ, I can't help myself. :)
On Dec 5, 1:08 am, Ben Tilly <
bti...@gmail.com> wrote:
> If you expect the else to be a block, and don't add a special case to
> the grammar, you would need to write your example as:
>
> if left > right {
> result = 1;
> }
> else {
> if left < right {
> result = -1;
> }
> else {
> result = 0;
> }
> }
>
> As much as I would never leave the {} off the final else, I can
> certainly understand the decision that was made.
Another possibility is to add elif
if left > right {
result = 1;
}
elif left < right {
result = -1;
}
else {
result = 0;
}
where if, elif and else all take blocks. But then I'd write this as a
switch:
switch {
case: left > right
result = 1;
case: left < right {
result = -1;
default:
result = 0;
}
I should say that I'm commenting from experience rather than language
design knowledge. Go has some different ideas that cause you to
rethink the way you program. This is one of those. When you need to
decide between 2 or 3 options you reach for an 'if else' statement.
The switch statement is SO general purpose that you don't really need
'if else' at all other than being syntactic sugar for:
switch {
case: left > right
result = 1;
case: left < right {
result = -1;
default:
result = 0;
}
I've written some code where I use switch to choose between 2 options
and the second option is default:.
geoff
P.S. OK Russ, I'll shutup now. :)