News for hackers. Stuff that matters.
Re:Go Proposal: first-class support for sorting slices by eknkc on Tuesday August 16, 2016 @12:24PM (#12298494)
It seems like due to lack of generics I see more and more interface{} and reflection stuff in code bases. This is getting ridiculous.

I've written a lot of Go. Tried my best to stick to what language provides but at some point you say "screw it" and start fighting with the language. That is never a good sign.

Re:Go Proposal: first-class support for sorting slices by shurcooL on Tuesday August 16, 2016 @01:22PM (#12298970)
Why hasn't it happened to me? I've been writing Go for over 3 years, and I prefer the language stay as is. I'm more concerned about porting it to more platforms. Perhaps that's a reason I'm motivated to desire less language changes.
Re:Go Proposal: first-class support for sorting slices by omarforgotpwd on Tuesday August 16, 2016 @01:40PM (#12299091)
I'm curious, what platform do you want to go to support that it doesn't already? Platform support seems pretty good already, at least for my needs.
Re:Go Proposal: first-class support for sorting slices by shurcooL on Wednesday August 17, 2016 @11:02PM (#12310158)
A really big and popular platform where Go isn't officially supported yet is the web (browser).

I'm trying to push that direction as much as I can by contributing to GopherJS [0], which is IMO our best bet until wasm [1] comes out and has adds support for GC languages [2].

I agree the rest of the platform support is absolutely fantastic. We have the big 3 desktop OSes, as well as iOS and Android already. But so much of what we do today is on the web, and I don't want to keep using JavaScript or to keep crossing the Go <-> JS boundary inconsistencies. That's not the kind of future I want to invest in.

[0] https://github.com/gopherjs/gopherjs#readme

[1] https://webassembly.github.io/

[2] https://github.com/WebAssembly/design/blob/master/FutureFeat...

Re:Go Proposal: first-class support for sorting slices by coldtea on Tuesday August 16, 2016 @02:12PM (#12299345)
>Why hasn't it happened to me?

Well, don't know about your case, but I've seen e.g. people who are religious about being DRY and dislike any kind of useless boilerplate, and others just copy paste code with wild abandon and couldn't care at all.

Re:Go Proposal: first-class support for sorting slices by shurcooL on Wednesday August 17, 2016 @11:05PM (#12310171)
I used to care about DRY to a _very_ great degree [0], and I still do. But I've come to realize DRY is much better to apply for high level _concepts_, ideas, and architectures, not unexported helper code.

It's unhelpful to try to apply it to little snippets of code and helpers. It's much less expensive to copy a snippet that's needed and duplicate it 1-2 times before starting to worry about factoring it out. By the time it's repeated 3+ times, you'll have a much better idea how to structure it.

[0] https://github.com/shurcooL/Conception#motivation

Re:Go Proposal: first-class support for sorting slices by eknkc on Tuesday August 16, 2016 @02:56PM (#12299714)
Also, I'm generally fine with language tradeoffs, If there is a good reason that I need to copy paste something, so be it. I'll do it.

Go and Generics issue on the other hand, feels a little different to me. It is a solved problem. Go does not have an inherent show stopper for generics. It's just not there because of.. What? Stubbornness? I'm not sure. But then it irritates me to copy paste stuff.

Re:Go Proposal: first-class support for sorting slices by shurcooL on Wednesday August 17, 2016 @11:10PM (#12310192)
> It is a solved problem.

This is debatable. Is it a problem that's solved well? Is it solved in the best way possible and there could never be a better way to do generics?

I think not. I think it's solved adequately, but not great. Compared to the other facilities that Go offers, generics are typically pretty messy and add significant complexity to the language, tools, parsing, reasoning, compilation times, etc.

> It's just not there because of.. What? Stubbornness? I'm not sure. But then it irritates me to copy paste stuff.

This statement is ill-informed. Have you seen https://github.com/golang/go/issues/15292 and https://github.com/golang/proposal/blob/master/design/15292-...? Have you considered all the ways in which it will affect the language and the trade-offs?

Once generics are added to Go, they will forever be there, together with all the disadvantages and missed opportunities, and we'll have to live with them. That's not a thing to be taken lightly.

In comparison, maybe copying a little here and there isn't all that bad.

Re:Go Proposal: first-class support for sorting slices by interactiv on Tuesday August 16, 2016 @12:48PM (#12298702)
yep, I wrote this :

https://github.com/Mparaiso/lodash-go

which is in theory "runtime type safe" in the sense that is yields an error if types do not match , but it uses reflection which leads to a huge performance hit.

The irony is that Go is a perfectly capable functional language when one opts out of Go type system. (Don't use that package, this is not idiomatic Go).

Re:Go Proposal: first-class support for sorting slices by burntsushi on Tuesday August 16, 2016 @01:17PM (#12298934)
Re:Go Proposal: first-class support for sorting slices by interactiv on Tuesday August 16, 2016 @01:37PM (#12299069)
Yes, if you look at the source code I use unification to tell whether types match or not.
Re:Go Proposal: first-class support for sorting slices by burntsushi on Wednesday August 24, 2016 @06:24PM (#12355716)
You're doing a lot of repeated work though. I was trying to point out this function, which does unification in a generic context, given some function type: https://godoc.org/github.com/BurntSushi/ty#Check ... For example, it reduces a lot of the reflection boiler plate: https://github.com/BurntSushi/ty/blob/master/fun/list.go#L80
Re:Go Proposal: first-class support for sorting slices by twblalock on Tuesday August 16, 2016 @12:43PM (#12298655)
interface{} is the new void*.

There are far better ways to handle generics in modern languages, which preserve type safety and aren't very cumbersome.

Re:Go Proposal: first-class support for sorting slices by masklinn on Tuesday August 16, 2016 @12:45PM (#12298677)
> interface{} is the new void*.

More like Java's Object, especially since downcasts are mandatorily runtime-checked. And the results are exactly what one could have expected from the first 10 years of java (if slightly subdued as Java only had a single magical blessed buildin type) given the language is in more or less the same class.

Re:Go Proposal: first-class support for sorting slices by mseepgood on Tuesday August 16, 2016 @02:12PM (#12299346)
More like C#'s "object" than Java's "Object".
Re:Go Proposal: first-class support for sorting slices by leaveyou on Tuesday August 16, 2016 @01:13PM (#12298919)
>interface{} is the new void*

There is an important difference between interface{} and void* which makes it a lot less reckless. AFAIK interface{} contains not only a pointer to data but also a reference to the type of the data. Therefore you can cast that data safely to the original type (or use "switch" on the type). if origData, ok := data.(OriginalType); ok { /safe to use origData here*/ }