6 ms·
Gen - a generics library for Go
- shurcooL 13y agoHere is someone trying to come up with a good solution for generics, rather than simply complaining it don't exist. I am thankful for the effort.
- stefantalpalaru 13y agoGood? It's an ugly hack with limited functionality (due to Go's design, not the developers' skill and good will). A good solution would be forking the reference compiler and doing a proper implementation.
- KevinEldon 13y agoThe library is Go. What you're suggesting seems to be extending Go so that it becomes some other language derived from Go. Extending Go might make for a cleaner and/or better generics solution but if you have to have customized compiler to run the code then you're no longer running Go.
- graetzer 13y agoIt would be like Java to the Pizza Language: http://en.wikipedia.org/wiki/Pizza_%28programming_language%29 http://en.wikipedia.org/wiki/Pizza_%28programming_language%2...
- saryant 13y agoHistorical tidbit: Pizza is the precursor to Java's own generics implementation (introduced in Java 5), both were written by Martin Odersky who then went on to create Scala.
- elwell 13y agoWow, 12 years old: http://pizzacompiler.sourceforge.net/ http://pizzacompiler.sourceforge.net/
- judk 13y ago- Generics (aka Parametric polymorphism) - Function pointers (aka First-class functions) - Class cases and pattern matching (aka Algebraic types) 13 years, and only it's three features has made it into Java I wish Sun found a way to transfer the Java trademark to Odersky before dying. Scala has so many nice features that companies prohibit because the language isn't called "Java".
- allochthon 13y agoI'm interested in Go but haven't looked into it yet. The fact that we're even talking about "generics" makes me nervous about further exploring it. Generic collections that have clean, dry implementations seem to be pretty much a requirement for new programming languages, in the way that core support for hashes is.
- kazagistar 13y agoI think if he gets something good enough that Go devs like, then some form of it might very well be rolled into the compiler itself.
- pjmlp 13y agoSome of us use languages with parametric types since the mid-90's.
- coldtea 13y ago>Here is someone trying to come up with a good solution for generics, rather than simply complaining it don't exist. That's a hack. Complaining that they don't exist might eventually result in a better language.
- namelezz 13y agoJust because there is no solutions yet, it does not mean you can just throw out any solution. I don't think code generation is a good solution for generics but I like the Linq feature though.
- c-a 13y agoWhy call it a library when it's a code generator/compiler?
- Refefer 13y agoI would argue this is a new language which just happens to compile to go.
- c-a 13y agoActually it's a code generator with a library of functions it can generate. This is how the "generics" are implemented: https://github.com/clipperhouse/gen/blob/master/templates.go https://github.com/clipperhouse/gen/blob/master/templates.go
- mwsherman 13y agoAuthor here, you’re right. I prefer to call it a tool or an ‘approach’ but whatevs. :)
- LukeShu 13y agoThis looks similar to an older generics system for Go, `got` (GO Templates). Got was pretty cool, but Go 1.0 broke it due to the parser getting stricter. Edit: found it: https://github.com/droundy/gotgo https://github.com/droundy/gotgo
- mseepgood 13y agoThese higher-order functions are a very inefficient way to write loops in Go. When you chain them you will end up with multiple sequential iterations instead of only one. Sort should not allocate and return a new slice, it's better to sort in-place, etc.
- rybosome 13y agoThat's functional programming for you. It's definitely less efficient, but there are other major advantages. For one thing, given the propagation of immutable data, things can be parallelized effortlessly - look at 'pmap' in Clojure for example. Once you're familiar with the style, it's significantly more concise and readable. That being said, a systems programming language may not be the right place for FP concepts.
- saryant 13y agoScala gets around this with "views": store the higher-order functions until the collection actually needs to be used and then apply them all at once, without any intermediate data structure. http://docs.scala-lang.org/overviews/collections/views.html http://docs.scala-lang.org/overviews/collections/views.html
- coolsunglasses 13y ago>That's functional programming for you. Uhm, what? No it's not. Haskell has stream fusion, thereby generating assembler that looks a lot like the optimal imperative version.
- rybosome 13y agoVery cool - I was not aware of this feature. Fwiw, I'm actually something of an FP zealot; I failed to make a stronger case in my comment because I'm tired of arguing, and I'm concerned that I'm being obnoxious.
- burntsushi 13y agoThis is kind of misleading. Stream fusion isn't baked into Haskell; you need to use a library. [1,2] [1] - https://ghc.haskell.org/trac/ghc/ticket/915 [2] - http://hackage.haskell.org/package/stream-fusion
- Xelom 13y agoThanks for your effort. This is not about the library. Your site's mobile version is kinda broken. The left menu thingy always remain in the site and you can't read the main context. This happened to me on my Android Firefox Browser.
- StavrosK 13y agoSame here, I couldn't read it at all.
- mwsherman 13y agoAuthor here, pleasantly surprised to see this on HN. There is a substantial set of changes happening out on this branch: https://github.com/clipperhouse/gen/tree/projection https://github.com/clipperhouse/gen/tree/projection. … for this reason: https://github.com/clipperhouse/gen/issues/8 https://github.com/clipperhouse/gen/issues/8
- stiff 13y agoI really hope this will get solved in the language itself, I like Go quite a bit, but there are quite ugly places, all related to generics I guess: - No min/max for integers (and Go doesn't have the ternary operator) - No IsMember for checking if an object is in a collection - Directly from the Gen page: Go’s sort package requires the fulfillment of three interface members, two of which are usually boilerplate. If you want to sort by different criteria, you need to implement multiple ‘alias’ types. Also, unrelated to generics, but no multidimensional arrays.
- mseepgood 13y ago> no multidimensional arrays That's not true, e.g. [4][4]byte is a multi-dimensional array. It's a contiguous block of 16 bytes of memory.
- stiff 13y agoThe size has to be known at compile time, though. One can do a slice of slices, but then it's not necessarily continuous in memory. So you are left with allocating a one dimensional array of size x*y and doing index calculations by hand like in the good old 70's or something.
- howeman 13y agoPackages aren't enough of a namespace differentiator for you?
- stiff 13y agoI edited that part of the comment out because it was not really related to anything, but I meant that all identifiers go into a single (language-level, not program-level) namespace, e.g if you have a struct type called Bytes, you can't call the instance Bytes etc. I end up having to use a lot of ugly variable names.
- a-nom-a-ly 13y ago(Can't reply to your post below) > I edited that part of the comment out because it was not really related to anything, but I meant that all identifiers go into a single namespace, e.g if you have a package called bytes you can't call a variable bytes, if you have a struct type called bytes, you can't call the instance bytes http://play.golang.org/p/98vt2YLslY http://play.golang.org/p/98vt2YLslY