News for hackers. Stuff that matters.
Re:Go generics draft design: building a hashtable by twblalock on Wednesday June 17, 2020 @03:46PM (#23555855)
On the <> syntax, why not improve the parser? Every language that uses <> for generics has a parser that is able to distinguish between generics and the "less than" operator, and it seems odd that Go developers think it can't be done efficiently.
Re:Go generics draft design: building a hashtable by Sharlin on Wednesday June 17, 2020 @04:25PM (#23556293)
C++ and Rust require extra disambiguating syntax in some contexts (C++ the `foo.template bar<T>()` syntax, Rust the "superfish operator" `foo.bar::<T>()`. Java works around the problem by awkwardly putting the generic argument list in front of the method name (`foo.<T>bar()`). I don't know about C#.
Re:Go generics draft design: building a hashtable by DougBTX on Wednesday June 17, 2020 @04:35PM (#23556415)
C# is `foo.bar<T>()`, I’m not sure what compromises that had to make for that to work but from an end-user perspective it works well.
Re:Go generics draft design: building a hashtable by oxnrtr on Friday June 19, 2020 @01:39AM (#23571331)
They parse it one way, and if they figure out the other parse option was right, they go back and fix the parse tree.

Basically, unlimited look-ahead.

Re:Go generics draft design: building a hashtable by lostmsu on Sunday June 21, 2020 @03:15AM (#23590436)
Is it somehow a problem?
Re:Go generics draft design: building a hashtable by steveklabnik on Wednesday June 17, 2020 @05:59PM (#23557277)
(teeny tiny note: turbofish, not superfish)
Re:Go generics draft design: building a hashtable by Sharlin on Wednesday June 17, 2020 @06:45PM (#23557701)
Oops :D
Re:Go generics draft design: building a hashtable by oxnrtr on Friday June 19, 2020 @01:40AM (#23571339)
Using [] is the optimal choice for languages in general, but they can't even use that because they blew away that syntax for indexing.
Re:Go generics draft design: building a hashtable by Sharlin on Saturday June 20, 2020 @08:13AM (#23583507)
Scala uses [] for generics and () for indexing, which sort of makes sense given that in the end arrays are just functions.
Re:Go generics draft design: building a hashtable by lostmsu on Sunday June 21, 2020 @03:16AM (#23590438)
So are the uninstantiated generic types ;-)
Re:Go generics draft design: building a hashtable by 8192kjshad09- on Wednesday June 17, 2020 @03:50PM (#23555914)
Go developers like to claim that the reason the Go compiler is fast is because it's "simple to parse". Unfortunately this doesn't make a lot of sense as parsing is typically only 1-5% of the total compile time.
Re:Go generics draft design: building a hashtable by sacado2 on Wednesday June 17, 2020 @06:10PM (#23557411)
It's not only about the main compiler. Go has tons of third-party tools (linters mainly) that can parse go code, because it's so easy to write one. Most of them wouldn't exist if parsing was a PITA.
Re:Go generics draft design: building a hashtable by Groxx on Wednesday June 17, 2020 @10:05PM (#23559058)
Those almost universally use the "ast" package provided by the stdlib.
Re:Go generics draft design: building a hashtable by qtplatypus on Wednesday June 17, 2020 @08:34PM (#23558534)
It is not a question of "Improve" but a question of dealing with tradeoffs. The Go parser is built so that at every stage it is totally unambiguous what the parser has to do.

This reduces the amount of state that the parser has to carry around and makes the error messages for syntax errors easier to generate.

Languages that use <>'s for generics have to look at a larger amount of the code when parsing to work out what to do.

Re:Go generics draft design: building a hashtable by monkeyfacebag on Wednesday June 17, 2020 @03:57PM (#23555990)
In my opinion, the new design doc clearly characterizes this as a design goal of the parser, rather than a hard constraint that cannot be resolved.

"Resolving that requires effectively unbounded lookahead. In general we strive to keep the Go parser simple."

It's totally fair to question the tradeoff - should having a simple parser outweigh the potential ergonomic benefit of <>? I don't know. The forum for this is probably the golang-nuts group.

Re:Go generics draft design: building a hashtable by nemetroid on Wednesday June 17, 2020 @04:19PM (#23556231)
The design doc doesn't say "simple", it says "efficient".

I think "simpler" would have been a stronger argument. While using <> would make the parser more complex, I have a hard time seeing that making a meaningful performance difference in a compilation context. Maybe if you're parsing a lot of Go without actually compiling it, but that doesn't seem like a use case to optimize for.

Re:Go generics draft design: building a hashtable by mpoteat on Wednesday June 17, 2020 @04:02PM (#23556049)
It's all a matter of where you accept the complexity - in the compiler, in the language, or in the downstream applications. In my view it's an obvious choice to choose a more complicated compiler on exchange for simpler downstream applications...
Re:Go generics draft design: building a hashtable by teleforce on Thursday June 18, 2020 @04:25AM (#23560992)
The main reason is probably that by omitting <> for generics makes the symbol table unnecessary as part of the compilation stage. Go and D are the two modern languages that are avoiding symbol table like a plague for faster compilation time, i.e. the code should be parseabled without having to look things up in a symbol table .
Re:Go generics draft design: building a hashtable by apta on Thursday June 18, 2020 @02:12AM (#23560263)
The golang approach has been to dumb down the parser, at the expense of making it more complex for users.
Re:Go generics draft design: building a hashtable by jatone on Thursday June 18, 2020 @01:25PM (#23565357)
there is no complexity tradeoff for users here.
Re:Go generics draft design: building a hashtable by apta on Tuesday June 23, 2020 @01:34AM (#23610234)
Angle brackets are easier to parse for humans.