Live data from Hacker News

Go Proposal: first-class support for sorting slices

github.com

31–40 of 105 posts

Re: Go Proposal: first-class support for sorting slices

#31

Earlier quoted context omitted.

Well, that's how C++ started. I'm honestly surprised nobody's forked Go or made a less obnoxiously opinionated front-end.

I think you overestimate the number of people who care that much about Go. It's not very widely used. It would also be a massive effort to add generics to it at this point, because of the design choices the team made early on.

Not sure what counts for "widely used", but it's now in the top20 TIOBE: http://www.tiobe.com/tiobe-index/

Re: Go Proposal: first-class support for sorting slices

#32
post #12

Another approach to this (this is used to good effect in LINQ) is to skip the `Less(i,j)` and just provide a value extractor, except golang makes that super verbose because you'd have to do `func(v interface{}) interface{}` The idea would be if you have `type foo struct { ID int, Rank int }` you could provide `func(v interface{}) interface{} { return v.(foo).Rank }` and it would sort by rank. Some level of late bindi…

> Another approach to this (this is used to good effect in LINQ)

Also in Python, it's called "key functions". Of course since Go doesn't have tuples and/or user-defined ordering, it either only works for simple comparisons (e.g. by rank but not by rank and name) or you have to hand-roll some weird-ass coercion into whatever key type the language uses.

> you'd have to do `func(v interface{}) interface{}`

And that doesn't actually work, interface{} is not orderable. Only integers, floats and strings are "naturally" orderable.

Re: Go Proposal: first-class support for sorting slices

#34
post #11

Earlier quoted context omitted.

https://golang.org/LICENSE

Right, so now I'm forking it and maintaining my own language to add a feature I just get for free in any number of reasonable competitors..

So you want other people to maintain something for you and do it the way you like? Obviously, it's not simple to just fork a project like Go and maintain it but the point is that it is not legally impossible. A group of people inclined enough to "fix" Go for themselves are completely free to do so.

BTW, you might be interested in https://oden-lang.org/

Re: Go Proposal: first-class support for sorting slices

#35

Earlier quoted context omitted.

Right, so now I'm forking it and maintaining my own language to add a feature I just get for free in any number of reasonable competitors..

Well, that's how C++ started. I'm honestly surprised nobody's forked Go or made a less obnoxiously opinionated front-end.

I promise this isn't a troll question, but isn't the opinionatedness (which is a matter of taste) one of Go's biggest features? Once you remove that, what do you get over Elixir or Erlang, on a technical level? Static linking and no VM?

Re: Go Proposal: first-class support for sorting slices

#36
post #18
post #15

Earlier quoted context omitted.

Or use code generation via the generate package. Go is a great C replacement for any use case where using a GC is an affordable option. Other than that, there are lots of other languages with AOT compilation to native code and better abstractions.

Can you give an example of what exactly generate does? All I can tell is that it me you call other programs like yacc to preprocess some files. So just a replacement for make?

It's basically the storing of a verbatim one-line command as a line comment in a .go source file rather than its traditional home of a line in a shell script or makefile.

Imagine you found it intolerable to have an interpreter-dependant -- not even /bin/sh -- source file in your package directory (said another way, anything but .go source files in the package directory), but at the same time needed to somehow sneak in the functionality of a rudimentary shell script. The answer? Weave it into a .go source file and the Go toolchain will be able to pick up on and execute it (on demand, never automatically).

Re: Go Proposal: first-class support for sorting slices

#37
post #17

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.

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.

>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*/ }

Re: Go Proposal: first-class support for sorting slices

#38

Earlier quoted context omitted.

Well, that's how C++ started. I'm honestly surprised nobody's forked Go or made a less obnoxiously opinionated front-end.

I think you overestimate the number of people who care that much about Go. It's not very widely used. It would also be a massive effort to add generics to it at this point, because of the design choices the team made early on.

> It would also be a massive effort to add generics to it at this point

Not really. The easiest approach would take like a day for PoC.

Re: Go Proposal: first-class support for sorting slices

#39
post #17

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.

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

See also: http://blog.burntsushi.net/type-parametric-functions-golang/

Re: Go Proposal: first-class support for sorting slices

#40

Earlier quoted context omitted.

Right, so now I'm forking it and maintaining my own language to add a feature I just get for free in any number of reasonable competitors..

So you want other people to maintain something for you and do it the way you like? Obviously, it's not simple to just fork a project like Go and maintain it but the point is that it is not legally impossible. A group of people inclined enough to "fix" Go for themselves are completely free to do so. BTW, you might be interested in https://oden-lang.org/

No, I want the language to have a standard way to extend it that's compatible with the core. Generics is a standard way to do type polymorphism without having the ship people another compiler.
Post reply on HN