It isn't. Not in the sense that "more keywords generate more complexity":
it more that the more complex language may need more keywords.
Which means that just reducing the keyword count doesn't make a
language less complex.
Chris
--
Chris "allusive" Dollin
The email's subject says it all.
Zipf's law applies.
>
> What about lexical sense?
> I'm not english but I would still understand what does continue do
> inside switch case's.
continue /already/ means something inside a switch case: it means
to continue the enclosing loop. [If there is one.] Your suggestion could
change the meaning of existing code. [You'd have to add labels to
all fors with nested switches.]
`continue` is a jump away (to the end-of-loop code). `fallthrough`
is a DON'T-jump-away. Using `contune` for `fallthrough` makes that
distinction harder to see,
It doesn't matter that `fallthrough` is a long keyword; you're not
going to be writing it often. If ever.
> switch k {
> case 4: fmt.Println("was <= 4"); continue;
> case 5: fmt.Println("was <= 5"); continue;
> case 6: fmt.Println("was <= 6"); continue;
> case 7: fmt.Println("was <= 7"); continue;
> case 8: fmt.Println("was <= 8"); continue;
> default: fmt.Println("default case")
> }
> }
Examples for new constructs should be sane.
The point of "fallthrough" is that in all languages with switch
support it is the exception rather than the rule, and it is a rare
case too, so having fallthrough spelled makes sense, and its length
isn't a problem in practice.
--
Gustavo Niemeyer
http://niemeyer.net
http://niemeyer.net/plus
http://niemeyer.net/twitter
http://niemeyer.net/blog
-- I'm not absolutely sure of anything.
Or, you can do what I do. Not care :-).
Such metrics are meaningless.
--
Aram Hăvărneanu
select{
case x := <-chanOne, x := <-chanTwo: // I can't see any potential problems with this, have the compiler expand into two duplicate cases
x.bar()
case x := <-myChan: // this one might have compiler lookahead issues, idk about that stuff though
fallthrough
case x := <-myOtherChan
x.foo()
}
to do this now you have to have to either define a helper function, define a closure or duplicate the case code (can get very messy)
select n := range mySliceOfChans {
case x := <-n:
n.foo()
}
Where mySliceOfChans could be type chan interface{}
Using fallthrough can only work when myChan and myOtherChan have the
same type. Otherwise x would have a different type in the two clauses.
In general this is a fairly special case, and of course you can handle
it in other ways. It's not clear to me that it's worth making the
language more complex for this.
Ian
here are the stats for $GOROOT/src at tip, sorted by frequency:
fallthrough 48
select 52
goto 144
go 196
chan 368
default 576
map 708
defer 778
break 857
continue 996
interface 996
import 1018
const 1054
package 1314
switch 1343
else 1627
range 2287
struct 3554
type 4278
case 4847
var 5055
for 5411
func 14215
return 17457
if 21544
total: 375032 chars in 90723 keywords, avg: 4.133814
a bit hastily written, i'm sorry:
I'm not arguing for the change, but isn't this also a reason why break
can't be used in a switch (even though it is)? If the change were
adopted it would require the use of labels, just as break does. So the
code above would be:
package main
func main() {
L:
for {
switch {
case 1 > 2:
continue L
case 3 < 4:
continue
case 5 > 6:
println("OK")
return
}
}
}
I think this is nasty, but not any worse than the situation with break.