4 ms·
I really wish they went with angle brackets like everyone else does. I get the argument about not wanting to break existing parsers but this is a significant en
by hnlmorg 6y ago
I really wish they went with angle brackets like everyone else does. I get the argument about not wanting to break existing parsers but this is a significant enough language change to warrant that.
- kyrra 6y agoIt actually causes ambiguous syntax that isn't easy to solve. See: https://go.googlesource.com/proposal/+/refs/heads/master/design/go2draft-type-parameters.md#why-not-use-the-syntax-like-c_and-java https://go.googlesource.com/proposal/+/refs/heads/master/des... a, b = w < x, y > (z) Is this code doing 2 boolean compares, or is it calling a function with "w" with types x and y?
- hnlmorg 6y agoI know it’s not a popular opinion, but one thing I love about Perl and wished more languages adopted was the way how variables and functions could be prefixed by a special character (‘$’ for scalars, ‘%’ for hashes, ‘@‘ for arrays and ‘&’ for functions, though the latter was optional). Perl had a lot of properties that made it look a lot like executable line noise but those prefixes did help with readability in a way that a lot of more readable languages lack. In the case of Go and the example you’ve given, if ‘W’ were a function then the code should read like this: a, b = w() < x, y > (z)
- Jtsummers 6y agoIn the example, we can't tell if w is a generic function or not (by looking at this line of code). Remove the spaces, as would be more conventional: w<x,y>(z) Is this two expressions on one line or one expression with two type parameters? Possible groupings: (w<x,y>)(z) // w is a generic function (w<x),(y>(z)) // two comparisons
- blandflakes 6y agoThe parens look like "helping ambiguous syntax" rather than "should read like this" here - if z is an argument to w, there was already a set of parens signifying the function call.
- robocat 6y agoCould they not make the space (or no space) part of the syntax after the <. gofmt means that white space could be made significant... which is the lesser evil: syntactic whitespace or inconsistent semantic meaning (compared to most other languages)? I detest how syntactically overloaded our few ASCII symbols are, and using square brackets for templates seems wrong. Edit: Even better, use gofmt to convert each ASCII symbol into several unique Unicode symbols depending on usage, to show the semantic meaning. So [] as array is represented differently from [] as the template operator. Edit 2: I suspect this one decision will prevent some developers from investigating golang and thus affecting uptake - choice of syntax matters.
- hnlmorg 6y agoThe << / >> characters (sorry on phone so can’t post the actual Unicode characters) was proposed and, like yourself, the Go team decided it might put people off. But to be honest I actually would have been ok with it.
- eweise 6y agoScala uses square brackets. Never liked the look of angle brackets
- geodel 6y agoSo you know languages which use angle bracket and now wish every other language should follow that. This seems more stuck-up that Go team's alleged opinion on not implementing generics.
- hnlmorg 6y agoWoooah steady in there with the conclusion jumping. The reason I prefer angle brackets is just because I think it’s a little more readable. For me square brackets and parentheses look too similar in long function declarations. This might be a symptom of my dyslexia but the fact remains it’s a real readability issue for me. I actually wouldn’t have minded if they used another visually distinct character either. Like the << / >> characters that were also proposed (even though non-ascii characters have usability drawbacks when typing code).
- pjmlp 6y agoNim, CLU, Eiffel and Scala use square brackets. D, Modula-3 and Ada use parenthesis. ML based languages use quoted letters. There is no everyone else.
- hnlmorg 6y agoYou've taken my comment too literally. The point I was making here wasn't "angle brackets are used without exception" (clearly that's never going to be true given the rich tapestry of programming languages out there) but instead "I don't like the aesthetic of square brackets". Really it was a statement expressing a personal opinion rather than an empirical fact. Is it a little misleading? Perhaps, but that's natural languages for you (I would have edited my own post to make my point clearer but I was outside the edit window by the time I had realised how ambiguous said point was). I have gone into more detail about why I don't like the square brackets notation for generics to one of the other replies so I wont reiterate myself here and simply suggest you read the replies before commenting.