News for hackers. Stuff that matters.
Re:Another go at Go failed by arundelo on Wednesday January 08, 2014 @07:49AM (#7023135)
being able to do minus, union, intersection, etc. I had to code those in-line every time.

I'm not sure I understand the post author's complaint here. What's wrong with writing your own SetDiff, SetUnion, and SetIntersection functions and doing stuff like the following?

    baz = SetUnion(foo, bar)
(I have done very little programming in Go.)
Re:Another go at Go failed by NateDad on Wednesday January 08, 2014 @08:38AM (#7023343)
The problem is that you would need to rewrite that code for each type of foo and bar.... so if you have a set of ints and a set of strings and a set of SomeStruct... they'd all need their own implementation.

This is where code generation can work really well, especially for boring crap like set functionality... but he's right that rewriting it each time you figure out you have a new set type is a pain in the butt.

Re:Another go at Go failed by Roboprog on Wednesday January 08, 2014 @10:59AM (#7024259)
If the base type of the set is a bit set, the function need only worry about the position of each bit, and not the intended type. Of course, if the set has content in hash buckets (or a similar scheme), you would need to pass in some kind of comparator function/callback.

I say this as a former C programmer used to doing such things to make library routines like "bsearch()" work.

Too many things in Java rely on subclassing, rather than functional composition.

Re:Another go at Go failed by tomp on Wednesday January 08, 2014 @07:58AM (#7023177)
What is the (declared) type of `SetUnion`? Don't forget, Go has no generics/parametric polymorphism.
Re:Another go at Go failed by lafar6502 on Wednesday January 08, 2014 @08:30AM (#7023314)
So, are you saying that it's impossible to declare a function without generics? How did the world run before generics were invented?
Re:Another go at Go failed by Pxtl on Wednesday January 08, 2014 @10:02AM (#7023849)
> How did the world run before generics were invented?

We used code-generators or pre-compiler macros or dynamically typed languages or we hand-wrote heaps upon heaps of boilerplate.

It sucked.

And regardless, Go only offers the last option.

Re:Another go at Go failed by sixthloginorso on Wednesday January 08, 2014 @08:35AM (#7023335)
The author said that he needed a generic set for different concrete types, so he'd have to write a bunch of these functions for all the combinations he needed. And he did. And it was a mess. And it was also slow.

Edit: not that we can conclude anything from the lack of performance, though, we don't know how it was written.

Re:Another go at Go failed by lafar6502 on Wednesday January 08, 2014 @08:46AM (#7023384)
I believe it was a mess. But i don't believe it couldn't be done correctly in Go or whatever language you take.
Re:Another go at Go failed by Roboprog on Wednesday January 08, 2014 @11:27AM (#7024479)
My guess would be too much "noun oriented thinking".

Some of us came of age before the tyranny of King Java, learning such obsolescent tools as Pascal, Lisp and C back in school. (I'm gonna ignore BASIC and FORTRAN, other than as examples of what not to do) We learned how to pass around individual functions/procedures to support library code.

http://steve-yegge.blogspot.com/2006/03/execution-in-kingdom...

Re:Another go at Go failed by dded on Wednesday January 08, 2014 @08:38AM (#7023344)
No, the problem is that SetUnion needs to be implemented six times for six different data types.
Re:Another go at Go failed by sixthloginorso on Wednesday January 08, 2014 @08:49AM (#7023403)
Well, as we all know, Go does give you a way, sort of. You'd have to write basically a dynamic version using interface {}, and then write wrappers casting the values in and out, and possibly handing out the equality predicate.

That sucked in Java at the time, though, when you had to screw around casting Objects in your code, I don't see why people would prefer that.

Re:Another go at Go failed by frou_dh on Wednesday January 08, 2014 @09:20AM (#7023566)
Surprisingly, Erik Meijer (Haskell, C#) can somewhat see the appeal of no generics and a bit of casting:

22m-31m http://www.youtube.com/watch?v=on5DeUyWDqI#t=22m

(I give myself and Google a pat on the back for being able to remember and quickly find this!)

Re:Another go at Go failed by Paradigma11 on Thursday January 09, 2014 @07:44AM (#7030111)
Thanks.
Re:Another go at Go failed by corresation on Wednesday January 08, 2014 @10:10AM (#7023906)
For the app being described, would there really be six different type signatures required?

Generics would absolutely be nice for Go, primarily because they would allow the core libraries to provide all of these rich collections. However if we're discussing the notion that someone can write these themselves, it just seems contrived that people think generics are critical for any specific app -- in the example he described, it sounds like he would need one single concrete implementation.

Re:Another go at Go failed by tomp on Wednesday January 08, 2014 @08:46AM (#7023387)
No, only that in Go it's impossible to abstract the code that implements the "set union" functionality into a function.
Re:Another go at Go failed by Roboprog on Wednesday January 08, 2014 @11:19AM (#7024423)
I'm going to disagree:

    new_set = old_set.union( another_set, element_comparator_func);
If you allow some helper functions or an interface to do things such as compare/hash members, it's totally doable. Extra points for passing the helper(s) into the constructor.

Yes, you can still mismatch set types, but the casting/type-assertion in the helpers will fail with an explicit reason.

Re:Another go at Go failed by Roboprog on Wednesday January 08, 2014 @11:17PM (#7028731)
Almost forgot: in Go, classes aren't "closed". While you cannot "monkey patch" and change existing methods, you can define new functions, such as my_set_comparator, that accept each given type as "this". You would then make a new interface, such as my_set_element, which defines method my_set_comparator, and any data types for which you had defined my_set_comparator would automagically meet the new interface.
Re:Another go at Go failed by acjohnson55 on Wednesday January 08, 2014 @07:53AM (#7023156)
What's wrong with having them in the standard library?