> That certainly clears up the absurdities. It still doesn't really workI don't think that's fair - our primary goal is to make the
> for me because while this is apparently a feature for the programmer,
> the rule is designed instead for the compiler.
language more pleasant for people, not for the compiler.
> I supported the new syntax initially, but now I'm not so sure. The problemBut Go isn't these languages. You can't write
> is, this new syntax invalidates some of the commonly used formatting styles
> used in C, C++, Java, C# etc.
for (i=0; i<10; i++) {
}
either, but that doesn't seem to bother anyone.
> End-of-line ends a statement except when it's between brackets.https://groups.google.com/group/golang-nuts/msg/db8018422f085592
Because every global declaration begins with a keyword, and because
global declarations don't nest, why are parentheses needed in factored
import and declaration blocks at all? What ambiguity would arise if
they were dropped? Isn't it sufficient to note that the next token is
import/const/type/var/func to determine that the factored import or
declaration block has ended? True, parsing is more complicated, but
it's simpler for the user.
Now, there would be problems in parsing such factored statements
inside functions without the parentheses. Is that the reason they are
included in all cases -- for orthogonality?
Go is now a programming language with curly brackets that is no longer
a curly-bracket-programming-language:
http://en.wikipedia.org/wiki/Curly_bracket_programming_language
And now I must join in the discussion: I believe this was a really bad
idea.
I don't object to syntatical advancements such as eliminating
parentheses around for expressions as Russ has discussed here, but
that's *very* different from imposing the ONE TRUE STYLE. It's also
been said here that Go should be easy for the programmer, and this
change is emphatically not that. As was stated in (many) previous post
(s), this now means wrestling with the compiler over the very type of
pedantism that much of Go was intended to release the C and C++
developer from.
Not only does it prevent my from my own style, it makes the compiler
act in non-orthogonal ways and violates many things already documented
about the language.
IMHO, whitespace is whitespace and designed to be invisible/immaterial
(except in string literals, etc.) in the input language, and this is
reinforced by the language specification:
Tokens
Tokens form the vocabulary of the Go language. There are four
classes: identifiers, keywords, operators and delimiters, and
literals. White space, formed from spaces (U+0020), horizontal tabs (U
+0009), carriage returns (U+000D), and newlines (U+000A), is ignored
except as it separates tokens that would otherwise combine into a
single token. While breaking the input into tokens, the next token is
the longest sequence of characters that form a valid token.
This is no longer true with the latest change.
Non-orthogonal? Yes:
words := []string { "one", "two", "three" }
words := []string {
"one",
"two",
"three".
}
Note the comma now *required* after "three". The two declarations are
not the same and they require the addition of a *non-whitespace* token
based on whitespace changes.
We also lost adjacent string literal concatenation, an convenient item
that even C supports:
words := "one " "two" " three" ;
words := "one "
"two"
" three"};
Neither of these can even be compiled under the new rules. One of the
major advantages of allowing auto-concatenation of string literals is
to allow multi-line specifications (imagine the string literals were
quite long),
Also non-orthogonal:
type struct s { a int; b int; }
x := s { 3, 5 }
x := s { 3,
5,
}
And what is this?!
if cond
{
do something
}
8g: cond not used
What?! Apparently the { is now *required* to be on the same line as
the if or you get this strange error.
I agree emphatically with all the folks here who think this was a
really bad change. Even those that don't object too strongly still
seem to be dubious. Unfortunately, it's not even fixable by changing
make to run "gofmt X.go | 8g" because of things like the adjacent
string literal concatenation above.
I *really* like Go, and I think it has a lot of useful things. Don't
link it to "religious" issues like formatting... that's not benefiting
anyone. Please enjoy gofmt for your code... don't *require* it for
mine.
If the go developers are unwilling to rollback this change can we
*please* have a command-line option to re-enable the older parsing
functionality?
http://groups.google.com/group/golang-nuts/browse_thread/thread/4bd59c16c8dde565/b6773221d5bcfb32
The only reason for this seems to be that the language designers had a
difference of opinion, so the grammar supports both styles.
Those of us who like to place our braces on new lines are told to
adapt for the sake of consistency, but when the issue matters to the
right people, consistency is compromised.
Rant over.