News for hackers. Stuff that matters.
Re:Another go at Go failed by pcwalton on Wednesday January 08, 2014 @12:40PM (#7025001)
Generics, inheritance, and the factory pattern are completely orthogonal features. Adding generics would not entail adding inheritance, mandating the factory pattern, or any other slippery slope feature.
Re:Another go at Go failed by stcredzero on Wednesday January 08, 2014 @02:49PM (#7026029)
Most of Go's feature decisions seem to have something to do with compilation speed or how it fits in with the concurrency features and GC.

Inheritance is overrated, and the factory pattern is often overused. Both of those happen with generics.

Re:Another go at Go failed by pcwalton on Wednesday January 08, 2014 @02:56PM (#7026092)
> Inheritance is overrated, and the factory pattern is often overused. Both of those happen with generics.

Generics have nothing to do with inheritance and the factory pattern. There are lots of languages that have generics but neither inheritance neither factories: SML, OCaml, Haskell, etc.

Inheritance makes generics harder, in fact, because type inference becomes undecidable in the general case.

Factories are basically a workaround for functions not being able to be freestanding (unattached to a class) in Java (the "kingdom of nouns"), a problem that Go doesn't have.

Re:Another go at Go failed by stcredzero on Wednesday January 08, 2014 @05:36PM (#7027322)
Generics have nothing to do with inheritance and the factory pattern.

Where do I say such a thing? I'm saying that generics are both overrated and overused.

Factories are basically a workaround for functions not being able to be freestanding (unattached to a class) in Java (the "kingdom of nouns"), a problem that Go doesn't have.

Being the "Kingdom of Nouns" is kinda the point of Smalltalk/Objective-C style OO. (Though Alan Kay once famously said that when he thought of OO, he was not thinking of Java.) That said, while it is nice to have someplace to put functions, there are times when it's also nice not to be forced to attach them to a class. Not so sure it's a problem as much as it's just a particular approach with its advantages and drawbacks.

Where do you get that Factories are "a workaround for functions not being able to be freestanding?"

Re:Another go at Go failed by cstrahan on Wednesday January 08, 2014 @07:38PM (#7027959)
>> Generics have nothing to do with inheritance and the factory pattern.

> Where do I say such a thing? I'm saying that generics are both overrated and overused.

It looks like that's what you're suggesting here:

> Inheritance is overrated, and the factory pattern is often overused. Both of those happen with generics.

---

> Where do you get that Factories are "a workaround for functions not being able to be freestanding?"

A factory is, conceptually, a function of some set of inputs that returns a new instance - which is, of course, exactly what a constructor is. Now, it's not always appropriate for a class to know every single way in which it might be assembled, so such responsibility is usually lifted out - the question is where to put it. We already have constructors, and those are functions, so it would seem reasonable that we could just write method similar to a constructor, place it in some other namespace (perhaps in a completely different package/module), and then pass that along to the component that needs to create these new instances.

For languages like Java, the problem is that functions are not first class - you can't directly pass along a method/function like (Conf -> SomeService), so instead, it's common to create some special type, like SomeServiceFactory. If, for comparison, you take a look at Scala/Haskell/C#/etc, you'll wont often spot /.*Factory/ anywhere, because a function (with the ability to close over free variables) is much more concise, and doesn't require defining new types (e.g. SomeServiceFactory, versus Function<Conf,SomeService>).

I think that, seen in this light, the practice of defining dedicated factory classes is a rather clumsy approach necessitated by the design of the underlying language.

Re:Another go at Go failed by stcredzero on Wednesday January 08, 2014 @08:43PM (#7028207)
It looks like that's what you're suggesting here:

> Inheritance is overrated, and the factory pattern is often overused. Both of those happen with generics.

Non-sequitur here. To me, it's clear that I'm saying that generics are overrated and overused. Your interpretation makes no sense!

For languages like Java, the problem is that functions are not first class - you can't directly pass along a method/function like (Conf -> SomeService), so instead, it's common to create some special type, like SomeServiceFactory.

Another non-sequitur here. Factory pattern was originally popularized in the GoF book as a way of providing an opportunity for polymorphism.

If, for comparison, you take a look at Scala/Haskell/C#/etc, you'll wont often spot /.Factory/ anywhere, because a function (with the ability to close over free variables) is much more concise*

Old hand at Smalltalk here -- over 10 years. You don't often see Factory classes in Smalltalk. We also have very easy and nimble closures over variables in the context they're defined. I still don't get what you're on about.

Re:Another go at Go failed by cstrahan on Friday January 10, 2014 @02:20PM (#7038725)
>> Inheritance is overrated, and the factory pattern is often overused. Both of those happen with generics.

> Non-sequitur here. To me, it's clear that I'm saying that generics are overrated and overused. Your interpretation makes no sense!

Ok, now I understand what you're saying. As an aside, I would suggest that most people (as is evident in this comment thread) would not interpret your statement the way you intended.

>> For languages like Java, the problem is that functions are not first class - you can't directly pass along a method/function like (Conf -> SomeService), so instead, it's common to create some special type, like SomeServiceFactory.

> Another non-sequitur here. Factory pattern was originally popularized in the GoF book as a way of providing an opportunity for polymorphism.

I agree (re: polymorphism), but I don't think that contradicts what I'm saying; functions with parametric polymorphism (with support for {co,contra,in}variance) provide the same benefits of class polymorphism in this context.

> Old hand at Smalltalk here -- over 10 years. You don't often see Factory classes in Smalltalk. We also have very easy and nimble closures over variables in the context they're defined. I still don't get what you're on about.

You're absolutely correct. However, my point was that in statically typed languages, generics are conducive to favoring closures over factories classes and inheritance. But, now I realize that we were arguing two different things.

Re:Another go at Go failed by Sssnake on Thursday January 09, 2014 @12:09AM (#7028883)
>Non-sequitur here. To me, it's clear that I'm saying that generics are overrated and overused. Your interpretation makes no sense!

You are making the non-sequitur. His interpretation is the only one that makes sense. It is not clear at all that you are saying what you claim you are saying. You are in fact not saying anything like it. You are saying two things you don't like happen with generics, but that is completely false.

Re:Another go at Go failed by stcredzero on Thursday January 09, 2014 @08:21AM (#7030268)
Okay, now you just sound like you're trolling. Please point me to the grammar rule that says my referents can't be verbs.
Re:Another go at Go failed by Sssnake on Friday January 10, 2014 @12:23AM (#7035243)
What do you mean "now"? That was the first thing I said to you. You may wish to consider that when many people are telling you that what you said was nonsense, it may not be that all of them are crazy.
Re:Another go at Go failed by stcredzero on Friday January 10, 2014 @12:34PM (#7037951)
What do you mean "now"? That was the first thing I said to you.

So you are trolling, and you still haven't pointed out such a rule.

Re:Another go at Go failed by runT1ME on Friday January 10, 2014 @03:00PM (#7038969)
>Where do I say such a thing? I'm saying that generics are both overrated and overused.

How/why are they overused? How are they overrated? How can you claim there's any benefit to static typing but say generics are overrated?

Re:Another go at Go failed by Sssnake on Wednesday January 08, 2014 @11:29PM (#7028775)
>Inheritance is overrated, and the factory pattern is often overused. Both of those happen with generics.

No, both of those have absolutely nothing to do with "generics".

Re:Another go at Go failed by jamra on Wednesday January 08, 2014 @06:17PM (#7027579)
Those are all object oriented features. I was trying to compare O.O. to golang's approach.

I like the fact that you are forced to look at the algorithm vs the class hierarchy. I like that you don't have to read through factories.

I do think that generics would be great if they found a way of implementing them, however, I do not think that you need generics in order to write this kind of project.