News for hackers. Stuff that matters.
Re:Notes on the Go2 Generics Draft by civility on Sunday September 02, 2018 @05:24AM (#17896327)
Writing the exact same code for float and double (and possibly complex float and/or complex double) sucks. You've created some straw man about dopamine junky programmers because you don't need generics for whatever it is you do. If you wrote numerical algorithms you'd be annoyed at any language which lacks generics.
Re:Notes on the Go2 Generics Draft by zimbatm on Sunday September 02, 2018 @10:23AM (#17897086)
Maybe that's the issue. From what I have seen, the lack of generics mainly becomes painful when working in the numerical space. If I work on mapping JSON, doing APIs and CLIs I don't really need generics. If I work on algorithms and data bags then it starts to be annoying re-implementing the same thing over and over again.

So in these discussion you have devops-type people mainly dealing with APIs that are perfectly content. And the ones that work with algorithms are talking past them because they don't experience the same pain.

Instead of changing the language to enable generics everywhere, maybe there is a lighter version that exists that only applies to numerical problems. Is it possible that a boxed "Number" type would solve most of the problems?

Re:Notes on the Go2 Generics Draft by phamilton on Sunday September 02, 2018 @10:45AM (#17897152)
> mapping JSON

I find that an ideal set of tools allow us to describe our task and write our code using the same idioms.

The fact that "mapping JSON" doesn't actually involve calling "map" on JSON data is a great example of why not having generics in golang is frustrating for me.

Re:Notes on the Go2 Generics Draft by zimbatm on Sunday September 02, 2018 @07:17PM (#17899218)
I forgot the 3rd category, those who see the world exclusively through the functional programmer lens :-D

Mapping functionally it worth it if the transformation between A and B is regular enough. But things are dirty. Some irregularities appear and now the perfect higher-order function doesn't work nicely anymore. With the imperative approach it just means adding 1 -3 more lines.

Re:Notes on the Go2 Generics Draft by civility on Sunday September 02, 2018 @11:08AM (#17897233)
I think you're exactly right: People who live and breathe JSON and strings don't (and probably shouldn't) care about use cases where the choice between float or double matters...

I also see this with graphics people who live and breathe small (2x2, 3x3, and 4x4) matrices don't care about "type level integers" (as Rust calls them) to make 6x9 matrices efficiently live on the stack or in an array.

> Is it possible that a boxed "Number" type would solve most of the problems?

If you mean it the way I think you do, not for me. I can easily afford to fit a billion 4 byte floats in memory, but I can't afford a billion 8 byte box pointers to a 4 byte box with an n-byte tag, and the cache locality could be horrible.

However, if Go had an elegant macro system (Rust's doesn't seem too bad), I could get by though.

Re:Notes on the Go2 Generics Draft by steveklabnik on Sunday September 02, 2018 @01:56PM (#17897867)
Graphics people are one of the groups most often requesting type level integers. I’m sure many are fine without them, but many want them too.
Re:Notes on the Go2 Generics Draft by cdoxsey on Sunday September 02, 2018 @05:44AM (#17896365)
Ironically generics don't necessarily solve this. C# requires multiple implementations of numeric methods because int/float/etc don't sit in a type hierarchy.

It also doesn't really work in Java either because you have to use the Object types.

Even in rust this looks pretty complicated: https://travisf.net/rust-generic-numbers

Maybe it's easy in c++?

I've seem a similar comment made on almost every discussion of this issue... are folks just not aware of the limitations with generic implementations?

Re:Notes on the Go2 Generics Draft by civility on Sunday September 02, 2018 @10:35AM (#17897124)
Yes, it works well enough in C++. It would be nice if another language, without C++'s other pitfalls, got some of this right.

Btw, it's "ironic" that you think pointing at two broken implementations says anything about where it works. "Are folks just not aware" it's ridiculous to be snarky when arguing from a position of ignorance?

Re:Notes on the Go2 Generics Draft by slavik81 on Sunday September 02, 2018 @02:30PM (#17897995)
The complexity in that rust example comes from the indirection of requiring you to declare what operations you require via traits. C++ is much simpler: whatever operation you use is required.
Re:Notes on the Go2 Generics Draft by mseepgood on Sunday September 02, 2018 @06:01AM (#17896408)
It would be easy with the proposed Go 2 contracts.
Re:Notes on the Go2 Generics Draft by annywhey on Sunday September 02, 2018 @06:01AM (#17896405)
In agreement. IMHO generics basically have one place where they work well: abstract containers. Your queues, linked lists, what-have-you can benefit.

But most other data structures? Nope. Too much of the algorithm depends on the primitive type.

And that makes generics a nice boon for computer scientists and certain library authors, but of middling benefit for day-to-day coding. If the container works, you can copy-paste-modify your way to the types you want, or automate the same in a macro or code generator. It's not beautiful but it doesn't have to be.

Re:Notes on the Go2 Generics Draft by int_19h on Sunday September 02, 2018 @07:51AM (#17896658)
Having coded C# for many years now, generics are used for a lot more than just containers. There's a great many things that can be generalized. Just look at any large C# project on GitHub.
Re:Notes on the Go2 Generics Draft by kungito on Sunday September 02, 2018 @06:53AM (#17896521)
"Generics" (which should allow higher kinded types) work well with monads, who containers are among many others.
Re:Notes on the Go2 Generics Draft by lowmagnet on Sunday September 02, 2018 @11:56AM (#17897412)
You can just write the types, annotate them with github.com/clipperhouse/gen, and get pre-tested, reliable implementations around your type.

Generators are a legitimate solution and I wish they'd get more love.

Re:Notes on the Go2 Generics Draft by jy3 on Sunday September 02, 2018 @05:46AM (#17896370)
That means Go is not the right tool for you. Don't use it.

It's so sad to see people pushing to radically alter a language that they will probably never use because it will never be suitable for their needs.

Re:Notes on the Go2 Generics Draft by nicoulaj on Sunday September 02, 2018 @08:41AM (#17896773)
So what is the use case for Go exactly ? Programs that don't need to put numbers in containers ?
Re:Notes on the Go2 Generics Draft by stochastic_monk on Sunday September 02, 2018 @10:01AM (#17897021)
You didn't ask me, but the people I know using it are primarily writing networking or cryptographic code.

My biggest complaint about Go is the lack of generics; I bet they're just trying to get more adoption. That being said, adding generics won't eliminate all the other things I dislike about the language.

Re:Notes on the Go2 Generics Draft by civility on Sunday September 02, 2018 @10:53AM (#17897183)
No, Go is not currently the right tool for me, but it's close, and it would be much closer with (usable) generics.

What's "so sad" is you think this Reddit style "Don't use it" imperative is an acceptable way to talk to people. You're rightfully afraid of complexity creeping into an otherwise clean language, but it would suck less if you said it better.

Re:Notes on the Go2 Generics Draft by jy3 on Sunday September 02, 2018 @05:23PM (#17898738)
I'm taken aback. I didn't mean to sound condescending.

I won't argue with you my use of the imperative mood as I'm not a native speaker. I'll take note of it.