263 points · by smasher164 · 5y ago · 200 comments
[0]: https://www.reddit.com/r/rust/comments/5penft/parallelizing_...
type ImmutableTreeListᐸElementTᐳ struct
"If you look closely, those aren't angle brackets, they're characters from the Canadian Aboriginal Syllabics block, which are allowed in Go identifiers. From Go's perspective, that's just one long identifier."Simultaneously amusing and disturbing. Is there an award for which one might nominate this person?
At the very least they could have used the cute Japanese 「quotation marks」 to avoid confusion.
Definitely the correct response.
Also,
> c++ allows 0-width spaces in variable names. Where's your god now?
Nowhere. We have strayed maximal distance from god's light and are currently in orbit around Satan.
Is that true though ?
> A valid identifier must begin with a non-digit character (Latin letter, underscore, or Unicode character of class XID_Start) and may contain non-digit characters, digits, and Unicode characters of class XID_Continue in non-initial positions. Identifiers are case-sensitive (lowercase and uppercase letters are distinct), and every character is significant. Every identifier must conform Normalization Form C.
Upon further investigation(I think IntelljIDEA reported Unicode value) I've found out that the 'semicolon' I copied is a Greek character that looks exactly like semicolon.
I wonder how people on vim/emacs deal with situation like this.
Maybe the Unicode Consortium should change it, but for now, Canadian Aboriginal is the correct term.
[0] http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p194...
I guess that's a lot of ifs/ands but it's interesting that one could have future proofed their code if their bet on syntax paid off
It might be useful for editors and compilers to check for tricky Unicode (lookalikes for common characters, atypical changes in direction, invisible spaces or other formatting control codes, etc.) in this era of copy/paste coding.
But Go having actual generics, and accordingly removing some need for codegen, is not a bad thing at all.
def traverseImpl[F[_], A, B](fa: Option[A])(f: A => F[B])(implicit F: Applicative[F]) =
fa map (a => F.map(f(a))(Some(_): Option[B])) getOrElse F.point(None)That's the type. The expression makes little sense to me, but I suspect you removed a bunch of dots and maybe some parens, and it should actually look like this:
fa.map (a => F.map(f(a))(Some(_): Option[B])).getOrElse(F.point(None))
So this function essentially just operates on an option value inside of some functorial context. This seems like a building block function that you might use often, but probably not write very frequently.(If you didn't remove anything, then I suppose this language has infix 'map' and 'getOrElse' operators. I think that's bad, but it's not related to the type system.)
Oh gosh oh gosh zaglo variables please no
If you are interested in generics in Go 1.18 please read https://go.googlesource.com/proposal/+/refs/heads/master/des...
Personally, I'm super excited for the potential generics has to make error handling in Go less noisy, so I'll be attempting to use it ASAP.
The previous try() proposal added new control flow. That's part of the reason it was criticized so heavily -- it hid a control flow construct in something that looked like a function.
It's both. Adding only concise flow control, such as with the ? operator, works poorly if all you can return is multiple non-generic values; various common permutations get awkward in that case. And as you point out Result<> doesn't achieve much without the concise operators. Rust has very successfully shown the benefit of the combination.
People can now create Try or Option monads instead of returning the error.
This was the one of the reasons anti generics people were anti generics
At the very least, I'll appreciate having some more sugar over loops that are essentially just map/filter.
Before Rust 1.12, Rust has a macro, named try! which does a similar thing to its argument although the built-in operator has some fancier features.
Yes, it was the second proposal by the Go team for shorter error handling: https://github.com/golang/proposal/blob/master/design/32437-...
> I'm really curious what happened to the proposals for shorter Go error handling
The community didn't like it and it was declined: https://github.com/golang/go/issues/32437#issuecomment-51203...
go: don't change the libraries in 1.18
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.
> also Julia at least is prior art
Julia doesn't use curly braces for blocks and structs.
Not a compiler expert, but I got confused when reading this, when is it available?
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/des...
…which includes an example and the statement “It is a key design decision of Go that parsing be possible without type information”.
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.
Yes: https://go.googlesource.com/proposal/+/refs/heads/master/des...
So for C# it's resolved "by examining the token after the closing >: If it is one of (, ), ], :, ;, ,, ., ?, == or !=, the expression is parsed as a generic method call."
I assume this works reasonably well; however, it's not hard to see how this might be a problem in some cases where the parser gets it wrong.
let (a,b) = w::<x,y>(z);Well, you could... take a look at languages created these past twenty years that support generics, learn lessons from that, and see how these lessons could apply to Go.
But well, the Go team is not exactly known for paying much attention to the state of programming language theory, so I guess that's out.
Reasoning by analogy in a sneering way doesn't make it work better.
In fact, why stop at generics? Why not go back and question structured programming? Or strong typing? Because structured programming and strong typing has proven to be extremely useful. Same as generics in statically typed languages.
How much you should rely on others' experience, and when you should consider it a positive example versus something to learn from by avoiding, is going to be a judgement call.
Milner, R., Morris, L., Newey, M. "A Logic for Computable Functions with reflexive and polymorphic types", Proc. Conference on Proving and Improving Programs, Arc-et-Senans (1975)
(And of coures we've been able to write generic code in dynamic languages for a long time as this is a static typing concept)
Compile time? With template expansion like D and C++?
The upside is there is no runtime cost to using generics, the downside is there is significant compile time and link time cost to generics.
The downside is you can't do something like have a function pointer to the generic itself or specify generic members of a dyn trait/interface or otherwise treat the generic as a first class value (although you can treat specific instantiations of it as first class). The generic is basically syntactic sugar for a macro like substitution system. C++ and other languages that take the monomorphization route all have this restriction, whereas languages with more "first-class" support for generics like C# don't and hence do allow the moral equivalent of a virtual template.
Even in C#, generics are sort-of second class:
interface IMyLovelyADT { R Accept<R>(IMyLovelyADTVisitor<R> visitor); }
is not isomorphic to Func<IMyLovelyADTVisitor<R>, R>
The interface is strictly more flexible because it's non-generic, see my comment at [0] for an actual code example (it's quite long) if you're interested, but the gist is "you need a non-generic wrapper interface IMyLovelyADT: it essentially does the same job as Haskell's forall, since generic types are not quite proper types in C#'s type system. Interestingly enough, upcoming Go 2's generics will not support this scenario: a method inside an interface will be able to use only the generic parameters that the interface itself declares."[0] https://blog.ploeh.dk/2021/08/03/the-tennis-kata-revisited/
It will be Go 1.18, not Go 2.
Generics have the potential to impact a decent amount of the standard library. Although I’m not surprised that they are not doing a major version bump given the isolation of the feature at this stage, it will be interesting to observe its uptake in the community and whether fragmentation occurs over what is supported and what isn’t given their recommendation of isolating generics-related code in third party libraries.
With the addition of generics to Go, they've been careful to ensure it's fully backwards compatible, so all existing code will still work as is. Major version bumps are for incompatible changes (like Python 2.x to 3.x).
What they're recommending with isolating generic code in existing libraries is so users of older versions of Go (1.17 and prior) can still use those libraries, just not any new functions/types the libraries have added that use generics, and hence require Go 1.18.
https://golang.org/doc/go1compat
The fact that they can release generics and NOT bump to 2.0 is a triumph of the language designers and implementers, a testament to how much effort has been put into keeping this commitment.
I have a feeling this won't happen.
My plan is to not use generics for quite a while, as it's pointless to have two separate implementations, one for 1.18 and one for < 1.18, which is difficult, because I really like the feature.
I hope that the publicity caused by generics doesn't taint this release causing people to unnecessary procrastinate a toolchains update they would have otherwise done if it wasn't for generics.
Hacking on some projects or experiments is one thing, but say you're providing code for the automotive industry or the payment card industry; you're in for a world of regulatory hurt.
Meanwhile, as a non Java programmer, I've never seen a Scala app. I know about R, but nothing on my PC is written in it.
Agreed that PHP is massive in comparison to all of them.
I guess it is a thing, after all Go folks tend to ignore the experience from other programming communities.