Hacker News new | past | comments | ask | show | jobs | submit login

I know there is a lot of discussion about generics, but I am not sure if that is missing the point. I mean 'generics' sounds like a complex concept from the java development and I am uncertain if that's really what we need in go.

From my experience I think we should talk about container formats because they make 80% of what we would like to have generics for. Actually, go feels as if it has only two container data structures: Slices and Maps. And both feel as if they are pretty hard coded into the language.

Yes, I am sure there are more container formats and it is possible to build your own, but I think it is not easy enough.




> I mean 'generics' sounds like a complex concept from the java development and I am uncertain if that's really what we need in go.

That's inane and insane. Java generics do almost nothing, they don't even exist at runtime in a language with (much like Go) heavy runtime semantics. Here's what Java's generics do: get typechecked, and insert implicit casts.

> Yes, I am sure there are more container formats

First, you forgot Channels and arrays (which are distinct from slices) as well as "range" to iterate over them generically, second there are more containers than that in Go's own standard library: https://golang.org/pkg/container/, https://github.com/golang/go/issues/18177

> it is possible to build your own, but I think it is not easy enough

What does that mean? It is not easy enough what? To write containers? To have generics?


> What does that mean? It is not easy enough what? To write containers? To have generics?

Actually, I meant it is not easy enough to build container formats (maybe due to the lack of generics).

Btw. I will not continue this conversation as I am tired of getting insulted (inane and insane), getting downvoted for merely asking questions and you editing your post without labeling it. Just saying.


> I will not continue this conversation ... getting downvoted for merely asking questions

You didn't ask a question. You didn't include a single question mark.

What you said was a jumble of misleading and wrong words.


So if generics in java don't do anything beyond 'get typechecked, and insert implicit casts.' the empty interface is enough for all use-cases in go?


Yes, in a sense that structured loops don't do anything beyond inserting implicit if/goto, and so the latter is enough for all use-cases.


1. the empty interface does not do the first one, and thus does not allow writing typesafe structures and code

2. and it requires significant expense of explicit casts which are not just sanity checks (which is what they are in java, due to type system weaknesses)


> they make 80% of what we would like to have generics for

I regularly use generics in other languages for tasks unrelated to "containers"/data structures. They allow me to write less code and have the compiler check my mistakes.

Containers are frequently where people start with parameterized types, but once you are in the habit of using them actively that's rarely where you stop.


> once you are in the habit of using them actively that's rarely where you stop.

Eh. Many people don't ever go beyond that and it's fine, containers-type structures (to which I include stuff like futures or option types) and functions working on those are by far the most common use case.


For sure. But people like me write code for many-people. Giving us the tools to help make things better for many-people is wise. ;)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: