3 ms·
Go is NOT C-like. The same semantics could have been achieved by making minimal changes to the existing C syntax. For me, Go seems to be suffering from the NIH
by zvrba 15y ago
Go is NOT C-like. The same semantics could have been achieved by making minimal changes to the existing C syntax. For me, Go seems to be suffering from the NIH syndrome -- they made many syntax and cosmetic changes to C just for the sake of change itself. (Using {} for compound statements is not enough to qualify the language as 'c-like'.)
I have no doubts that Go authors think that their syntax is superior, but they'll have a hard time convincing me that
switch nr, er := f.Read(buf[:]); true {
is understandable (snippet taken from Go tutorial).
- deleted 15y ago[deleted]
- enneff 15y agoEven the simplest phrase in Mandarin Chinese is incomprehensible to someone who hasn't learned the language. That construct is easily understood by anyone who has learned some basic Go. I have taught Go to many classes of complete novices and none of them found the syntax difficult. On the contrary, many complimented its simplicity and consistency.
- chrisjsmith 15y agoIt is perfectly understandable from my perspective, but the caveat is that I'm used to Go's syntax and idioms and they are quite different from the usual. It has taken a while to unlearn the old way to be honest but I prefer it like this now.
- zvrba 15y agoCan you explain the " ; true" part?
- chrisjsmith 15y agoStraight from the tutorial: "Since the switch value is just true, we could leave it off—as is also the situation in a for statement, a missing value means true. In fact, such a switch is a form of if-else chain. While we're here, it should be mentioned that in switch statements each case has an implicit break." The basic outcome is that: 1. The assignment to er, nr is an initialization statement for the switch. 2. The true (default value if not specified) is used to configure the switch as an if-else chain which is required as the assignment above makes the purpose of the switch ambiguous (is the result of the assignment configuring the switch - how do you do that as multiple values are returned?). You could rewrite it: nr, er := f.Read(buf[:]); switch true { ... } or even: nr, er := f.Read(buf[:]); switch { ... } But the switch initializer scopes it to the switch block cleanly.
- zvrba 15y ago"switch true {...}" or "switch {...}"? really? So how would switch 3.141592654 { ... } affect the case-statements inside?
- chrisjsmith 15y agoNo idea as I wouldn't do it :) (sorry - cop out that)
- supersillyus 15y agoWhen you say "switch <value>", it matches the "case" statements based on if the value after "case" is equal to <value>. So, if you say const P = 3.141 switch 3.141 { case P: fmt.Println("This prints") } When no value is specified after "switch", the value of "true" is implied, which is why you can do: switch { case a && b: .. case something(): }