3 ms·
The original implementation used ( .. ), which I found an unreadable mess of parentheses soup, but luckily that was changed. The problem with < .. > is that it
by arp242 5y ago
The original implementation used ( .. ), which I found an unreadable mess of parentheses soup, but luckily that was changed. The problem with < .. > is that it's ambiguous with the greater-than and lesser-than operators. From [1] (among many other discussions on this):
For ambiguities with angle brackets consider the assignment
a, b = w < x, y > (z)
Without type information, it is impossible to decide whether the right-hand side of the assignment is a pair of expressions:
(w < x), (y > (z))
or whether it is a generic function invocation that returns two result values:
(w<x, y>)(z)
In Go, type information is not available at compile time. For instance, in this case, any of the identifiers may be declared in another file that has not even been parsed yet.
[1]: https://groups.google.com/g/golang-nuts/c/7t-Q2vt60J8 https://groups.google.com/g/golang-nuts/c/7t-Q2vt60J8
- deleted 5y ago[deleted]
- adgjlsfhk1 5y agoWhy not {} That should be pretty easily parsable, and seems less ambiguous than [] (also Julia at least is prior art)
- mseepgood 5y agoYou can't get more ambiguous to parse than {} in the context of Go. > also Julia at least is prior art Julia doesn't use curly braces for blocks and structs.
- ethbr0 5y agoWhy not use characters from the Canadian Aboriginal Syllabics block? ᐸ & ᐳ
- mseepgood 5y agoAre we going to ask this for every Unicode character pair? They have answered all these questions in the design document: https://go.googlesource.com/proposal/+/refs/heads/master/design/43651-type-parameters.md#why-not-use https://go.googlesource.com/proposal/+/refs/heads/master/des... They thought about generics for 12 years. It's unlikely that someone who thought about it for 3 minutes on Hacker News has some epiphany that wasn't taken into consideration.
- thewakalix 5y agoIt’s a reference to a cursed Reddit post, at the top of this page.
- 0x500x79 5y agoI think this is a joke from another thread: https://www.reddit.com/r/rust/comments/5penft/parallelizing_enjarify_in_go_and_rust/dcsgk7n/ https://www.reddit.com/r/rust/comments/5penft/parallelizing_.... Also, I think it is fair to challenge the decisions here seeing as how there have been a few things chosen in Go's history that ignores prior art from other programming languages.
- deleted 5y ago[deleted]
- afiodorov 5y agomade my day
- eweise 5y agoLet's face it, <> is just ugly. whereas [] is beautiful :)
- tored 5y ago> In Go, type information is not available at compile time. Not a compiler expert, but I got confused when reading this, when is it available?
- typical182 5y agoI think they meant “type information is not available at parse time” (rather than “compile time”). There is a longer and more precise description of the problem as part of this FAQ of the generics proposal: https://go.googlesource.com/proposal/+/refs/heads/master/design/43651-type-parameters.md#why-not-use-the-syntax-like-c_and-java https://go.googlesource.com/proposal/+/refs/heads/master/des... …which includes an example and the statement “It is a key design decision of Go that parsing be possible without type information”.
- arp242 5y agoMost (if not all) languages are compiled or interpreted in two stages: first the code is parsed (a.k.a. lexed, tokenized) to an internal representation (usually called "Abstract Syntax Tree", or AST), which just means translating something like ">" to "GREATER_THAN_SYMBOL", "5" to NUMBER, etc. and storing this in some data structure. This is also where you usually detect syntax errors like forgetting to use " to close a string and such. In Go, you can do this fairly easily with the go/ast package. Then you take the AST and do something with it. That something can be compiling the code, but also writing some sort of tooling like a linter, or identifier rename tool, or generate documentation from it, or whatnot. When compiling the code you need the type information, for a lot of other purposes you don't really care. It's pretty valuable to keep the parsing as simple as possible; it makes it easier to detect errors, improves the quality of the error messages, and makes it easier to write tooling. It also keeps the code a lot simpler, easier to understand and modify, etc.
- dragonwriter 5y ago> Most (if not all) languages are compiled or interpreted in two stages: first the code is parsed (a.k.a. lexed, tokenized) to an internal representation (usually called "Abstract Syntax Tree", or AST) Lexing/tokenization doesn't produce an AST; it produces a token stream. Parsing (which may or may not be preceded by lexing) produces an AST.