News for hackers. Stuff that matters.
Re:Expectations for generics in Go 1.18 by Benjammer on Wednesday October 27, 2021 @10:00PM (#29021468)
Thank god, this guy[0] can finally cut over to native generics in his code.

[0]: https://www.reddit.com/r/rust/comments/5penft/parallelizing_...

Re:Expectations for generics in Go 1.18 by topspin on Wednesday October 27, 2021 @10:03PM (#29021485)
On the question of "what's this?":

    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?

Re:Expectations for generics in Go 1.18 by jandrese on Wednesday October 27, 2021 @11:12PM (#29021951)
That's the kind of thing you see in a comment and then back slowly out of the room, never breaking eye contact with the code until you are far enough away to turn tail and run.

At the very least they could have used the cute Japanese 「quotation marks」 to avoid confusion.

Re:Expectations for generics in Go 1.18 by weego on Thursday October 28, 2021 @05:33AM (#29024055)
This is the person you need. Be assured that they were the person willing to log into the live prod server to fix that script that was killing your startups app at 2am on a Friday night in 2007 when everyone else was too gun-shy.
Re:Expectations for generics in Go 1.18 by kodah on Thursday October 28, 2021 @02:15AM (#29022946)
> oh my god

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.

Re:Expectations for generics in Go 1.18 by ithkuil on Thursday October 28, 2021 @02:19AM (#29022981)
Bow to the One whose Name cannot be expressed in the Basic Multilingual Plane
Re:Expectations for generics in Go 1.18 by jcelerier on Thursday October 28, 2021 @05:54AM (#29024146)
> > c++ allows 0-width spaces in variable names.

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.

Re:Expectations for generics in Go 1.18 by jeroenhd on Thursday October 28, 2021 @06:52AM (#29024515)
I don't know about the standard, but both GCC and Clang accept ZWSP characters in the middle of variable names.

Clang logs a warning about potentially invisible characters every time you use them. g++ just compiles the code without warning, even with -Wall and -Wpedantic.

What clang _doesn't_ warn for, is the use of the left-to-right override character. This can be used to confuse the victims of your code even more.

Re:Expectations for generics in Go 1.18 by therein on Thursday October 28, 2021 @06:47AM (#29024464)
> every character is significant. Every identifier must conform Normalization Form C.

This seems to be the only limitation for that to be true.

So the question is does 0-width space (U+200B) survive canonical decomposition, followed by canonical composition?

It feels like it does to me.

Re:Expectations for generics in Go 1.18 by LastMuel on Thursday October 28, 2021 @01:16PM (#29028483)
I'm dying. This is hilarious.
Re:Expectations for generics in Go 1.18 by iamcreasy on Thursday October 28, 2021 @04:15AM (#29023644)
I suppose there are many examples like this. Once I've copied a piece of code from SO but IntellijIDEA was warning me that the semicolon at the end of the line is not correct.

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.

Re:Expectations for generics in Go 1.18 by Cthulhu_ on Thursday October 28, 2021 @04:41AM (#29023795)
It's similar when online editors try to be clever and replace a straight " with a fancy one (like in Word), really annoying.
Re:Expectations for generics in Go 1.18 by Joker_vD on Thursday October 28, 2021 @08:30AM (#29025280)
That's why Powershell actually recognizes those fancy quotes and treats those as normal quotes.
Re:Expectations for generics in Go 1.18 by aweiland on Thursday October 28, 2021 @11:09AM (#29027008)
So one Microsoft product contains an automatic workaround for an issue created by another Microsoft product.
Re:Expectations for generics in Go 1.18 by maattdd on Thursday October 28, 2021 @04:34AM (#29023747)
On VSCode, I use the Gremlins extension which highlight all those suspicious characters.

https://github.com/nhoizey/vscode-gremlins

Re:Expectations for generics in Go 1.18 by effdee on Thursday October 28, 2021 @07:08AM (#29024631)
Pressing ga in command mode in Vim displays the ASCII / Unicode value of the character under the cursor.
Re:Expectations for generics in Go 1.18 by iamcreasy on Friday October 29, 2021 @02:37PM (#29042062)
Yes, but IntelljIDEA's Linter showed me the error. Without linter you'll need compiler/interpreter to tell you something is not right.

And in my case, even if compiler / interpreter reported about an invalid syntax - I would not think of checking the unicode codepoint as it the character appeared to look exactly like semicolon.

Re:Expectations for generics in Go 1.18 by CodesInChaos on Thursday October 28, 2021 @04:20AM (#29023663)
The rust compiler warns when it encounters confusable symbols like that. Not sure about other languages.
Re:Expectations for generics in Go 1.18 by ipmonkey on Sunday October 31, 2021 @01:31PM (#29058641)
vim user here. Most of us are running the same linters and language servers as every other major editor, which does a pretty good job catching stuff like this. Modern vim is really only a C core with a web of JS, Python, Lua, and vimscript using the exact same third party solutions for every other part of an "IDE". emacs is probably similar, but no personal experience with that.
Re:Expectations for generics in Go 1.18 by killingtime74 on Thursday October 28, 2021 @01:42AM (#29022773)
Java Certified Professional
Re:Expectations for generics in Go 1.18 by glouwbug on Wednesday October 27, 2021 @10:55PM (#29021851)
Canadians now roll with the term Indigenous instead of Aboriginal
Re:Expectations for generics in Go 1.18 by spenczar5 on Wednesday October 27, 2021 @11:06PM (#29021915)
That may be, but in this case it is a precise technical term, referring to a particular block of Unicode: https://en.m.wikipedia.org/wiki/Unified_Canadian_Aboriginal_...

Maybe the Unicode Consortium should change it, but for now, Canadian Aboriginal is the correct term.

Re:Expectations for generics in Go 1.18 by LudwigNagasena on Thursday October 28, 2021 @03:47AM (#29023480)
In 10 years a new word may become fashionable. Better to keep technical terms the same.
Re:Expectations for generics in Go 1.18 by Cthulhu_ on Thursday October 28, 2021 @04:43AM (#29023805)
It's not about fashion, it's about cultural identity. I take it you don't see a problem with master/slave either?

Just do a find and replace, refactoring is easy and trying to argue on the internet about it is tiring.

Re:Expectations for generics in Go 1.18 by asguy on Thursday October 28, 2021 @11:37AM (#29027352)
I take it you didn’t grow up in the 80s. Trends in words change: you’ll see it with your own eyes.

> trying to argue on the internet about it is tiring.

… exactly.

Re:Expectations for generics in Go 1.18 by earleybird on Friday October 29, 2021 @07:37PM (#29044689)
If identity is about appearance, that would seem to admit fashion for consideration.
Re:Expectations for generics in Go 1.18 by uuddlrlr on Wednesday October 27, 2021 @11:54PM (#29022199)
Colloquially in the north "native" is ubiquitous.
Re:Expectations for generics in Go 1.18 by andai on Thursday October 28, 2021 @01:07AM (#29022581)
For now...
Re:Expectations for generics in Go 1.18 by throwaway894345 on Wednesday October 27, 2021 @11:28PM (#29022044)
I love the reply: “c++ allows zero width spaces in variable names. where’s your god now?”
Re:Expectations for generics in Go 1.18 by tambre on Thursday October 28, 2021 @03:54AM (#29023514)
Fixed in C++23 by adoption of P1949R7 [0], which didn't originally set out to fix that, but seems to have after a Netherlands national body ballot comment.

[0] http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p194...

Re:Expectations for generics in Go 1.18 by aitchnyu on Thursday October 28, 2021 @05:00AM (#29023906)
I once read a comment like "Gives a new meaning to the term native code".
Re:Expectations for generics in Go 1.18 by dagmx on Wednesday October 27, 2021 @10:50PM (#29021812)
I'm actually curious if Go would normalize the characters AND if it had used angle bracketd, and make those equivalent to angle brackets? Would he then not have to even change his code?

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

Re:Expectations for generics in Go 1.18 by jchw on Wednesday October 27, 2021 @11:12PM (#29021950)
They're semantically different characters and Go supports multilingual identifiers, so I would not expect normalization to impact this. At most I would expect normalization to simply deal with ordering combining marks and standardizing on composed or decomposed forms of characters (where applicable.)
Re:Expectations for generics in Go 1.18 by nitrogen on Thursday October 28, 2021 @02:37AM (#29023073)
This got me curious what I'd read about domain names and visual normalization of Unicode, and found this: http://www.unicode.org/Public/security/revision-05/confusabl...

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.

Re:Expectations for generics in Go 1.18 by tialaramex on Thursday October 28, 2021 @03:05AM (#29023253)
I believe Rust will warn you if your non-ASCII identifiers are potentially confusing based on this list.
Re:Expectations for generics in Go 1.18 by EdwardDiego on Thursday October 28, 2021 @02:39AM (#29023085)
It's funny how codegen has become widespread in Golang to work around its deficiency.
Re:Expectations for generics in Go 1.18 by mappu on Thursday October 28, 2021 @03:27AM (#29023382)
Codegen is a super flexible and versatile tool, and simply having a strong generics feature does not mean you can avoid it: at $DAYJOB we use codegen even for C++ for e.g. grpc/openapi types, generating rapidjson streaming unmarshallers, etc not even counting Qt's moc/uic.
Re:Expectations for generics in Go 1.18 by EdwardDiego on Thursday October 28, 2021 @04:12AM (#29023616)
I understand and agree, I've run many a Java project that used codegen to emit Protobuf/Avro IDLs as types.

But Go having actual generics, and accordingly removing some need for codegen, is not a bad thing at all.

Re:Expectations for generics in Go 1.18 by Cthulhu_ on Thursday October 28, 2021 @04:46AM (#29023829)
No, I do believe Go will be improved if it allows library maintainers to implement some things like new collection types and utilities using generics.

I for one won't be using more advanced functional coding though, it's a lot more difficult to read / parse and the language is not designed with functional programming in mind. I'm sure people are already working on a functional programming library so you can do map / reduce / filter and the like, but readability and performance will be dreadful.

Re:Expectations for generics in Go 1.18 by gpderetta on Thursday October 28, 2021 @05:06AM (#29023941)
Strongly agree. Some people like to be on this endless treadmill of cutting edge features, like in this case parametric polymorphism but I refuse to be dragged in. They just make the code more complex with no benefit.

Next thing you know they will try to force me into structured programming (I'm sure there are people already working on do...while). They can pry goto from my dead cold hands.

Re:Expectations for generics in Go 1.18 by EdwardDiego on Thursday October 28, 2021 @06:45AM (#29024449)
Look, I'd just kill for a generic Set, tbh.
Re:Expectations for generics in Go 1.18 by Cthulhu_ on Thursday October 28, 2021 @04:44AM (#29023813)
I've come to prefer code quantity over code complexity. I mean, what the fuck is

    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)
Re:Expectations for generics in Go 1.18 by Athas on Thursday October 28, 2021 @04:59AM (#29023902)
This is probably less readable than it has to be due to the lack of whitespace. I don't know the language (Scala?), but I don't think it's too hard to work it out. First, the '[F[_], A, B]' part are type parameters, where I assume the 'F[_]' part is just a bad notation for a type of kind '* -> *' (i.e. a higher-ranked type). The next value parameter has type 'Option[A]', and after that we have 'A => F[B]'. This confirms my suspicion that 'F' is a higher-ranked type - and probably a functor or something. The 'f' parameter is a function for converting a value of type 'A' into a value of type 'F[b]', which looks like it's tranforming a value and putting it into a functor or something. The final '(implicit F: Applicative[F])' hints at deep problems in the language, but I think it basically just says something like 'the higher-rank type F must implement the trait/typeclass/whatever Applicative'.

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.)

Re:Expectations for generics in Go 1.18 by Someone on Thursday October 28, 2021 @08:37AM (#29025333)
scala has infix everything ‘operators’. f(x) can be written as f x and f.g(x) can be written as f g x if the parser manages to figure out what it means (I’m sure they phrase that differently)

Idea, I think, is to make the repl look more like a CLI, but it also may be a fight against punctuation.

Re:Expectations for generics in Go 1.18 by eweise on Thursday October 28, 2021 @08:54AM (#29025499)
Its only hard to read because you don't know the language, otherwise, its fairly straightforward. Although the Applicative type would require some research. I would much rather use a language like this, that can create enough abstraction to enforce consistency throughout the codebase, rather than relying on boilerplate conventions. Just had a bug this week in Go where a previously defined "err" variable was re-used instead of creating yet another "err" variable, which caused the actual error never to get checked.
Re:Expectations for generics in Go 1.18 by dvdkon on Thursday October 28, 2021 @05:20AM (#29024004)
This function is certainly hairy, but its use in the codebase might very well be intuitive and simplify code that would otherwise be way less expressive. I personally think it can be worth it.
Re:Expectations for generics in Go 1.18 by cerved on Thursday October 28, 2021 @05:11AM (#29023962)
Transform fa using f, collecting the results as an option
Re:Expectations for generics in Go 1.18 by geodel on Thursday October 28, 2021 @08:48AM (#29025441)
What is funny about it? People have worked around deficiency of systems since forever in almost every field. Is it something you have never seen in real life?
Re:Expectations for generics in Go 1.18 by pjmlp on Friday October 29, 2021 @12:06PM (#29040160)
C++ and Java also used codegen before they got templates and generics respectively, but since Go's matra is to relearn history, they had to have a go at it.
Re:Expectations for generics in Go 1.18 by ashton314 on Thursday October 28, 2021 @01:51AM (#29022823)
S̷͕͂̒c̴͉͈̆ŕ̶̘͚̄e̸̘̽̌ͅa̵̼̳͌m̷̬̓̈́͜s̴͙͆ ̸̨͓̾̈́i̴͈̼͐ņ̶̟̊̍ ̵͍̐̊Ű̸̪̤n̴̪̝̅̍i̶̜͌c̷͎̩̑̀ỏ̶̜͊d̴̟̎͠e̴̘̿

Oh gosh oh gosh zaglo variables please no

Re:Expectations for generics in Go 1.18 by Cthulhu_ on Thursday October 28, 2021 @04:47AM (#29023831)
HE COMES
Re:Expectations for generics in Go 1.18 by jhoechtl on Thursday October 28, 2021 @03:25AM (#29023371)
The syntax the OP gave reference to has nothing to do with how generics in Go 1.18 will look like.

If you are interested in generics in Go 1.18 please read https://go.googlesource.com/proposal/+/refs/heads/master/des...

Re:Expectations for generics in Go 1.18 by dmead on Wednesday October 27, 2021 @11:18PM (#29021989)
Oh my god.