News for hackers. Stuff that matters.
Re:Go by Example by hdevalence on Friday January 17, 2014 @09:37AM (#7075936)
Are there any plans to add generics yet, or do I still have to write a bunch of extra boilerplate functions in order to sort a list?
Re:Go by Example by bsg75 on Friday January 17, 2014 @10:08AM (#7076105)
What does yet another gripe about generics in Go have to do with a tutorial written by an independent party, one that is about features in the language today ?
Re:Go by Example by jamesaguilar on Friday January 17, 2014 @12:09PM (#7076916)
Same reason most posts about MongoDB for a long time had complaints about Mongo's uh . . . let's say "relaxed" . . . approach to durability. Because proponents of the language/system/idea tend to promote an unbalanced view of its quality, its detractors need to be there to give people on the fence the right dose of the bad medicine.

Also, speaking only for myself, I really like the language and its ideas, but that one thing it's missing makes it too annoying to write code in it. I'd like to see more people aware of this deficiency and putting pressure on the language's owners to fix that problem, so that I can start using it.

Re:Go by Example by Shamanmuni on Friday January 17, 2014 @12:40PM (#7077141)
I tend to think that you and the rest of "Generics or death!" crowd make a disservice to your own cause when you lazily come and repeat the same arguments. The rest gets bored and frustrated. Yeah, we get it, you like generics, it makes sorting stuff easier, and you're repeating the same stuff over and over again for our own good because you are true altruists, etc. Can we get over that?

If there's another thread which talks about good and bad points of the Golang design then, by all means, bash the language as much as you like. But if there's something you don't like it doesn't mean you get a free pass to repeat yourself whenever something with Go in the title appears in HN, whatever it is. Context matters, you aren't helping anybody, just trolling.

Re:Go by Example by jamesaguilar on Friday January 17, 2014 @01:42PM (#7077597)
I would surely never take these complaints to a go-specific discussion board. That would be disruptive and rude. But this site is not that. I will react to stories on here as pleases me, and it pleases me to constructively criticize certain go design choices sometimes when the subject comes up.
Re:Go by Example by Shamanmuni on Friday January 17, 2014 @02:11PM (#7077761)
You don't fool anybody, the subject didn't come up untill you brought it. The thread is about a site that shows examples of Go code and explains them, there's no discussion about the advantages or disadvantages of their design decisions, just matter of fact statements.

Of course, you can do whatever you want, but that doesn't mean that the rest of us won't probably look at your comments thinking "Here come the generics whiners again" and look in the other direction. You are alienating your audience with your indiscriminate repetition.

And, if the disclaimer helps you, I'd like generics in Go, they are useful sometimes. I just don't see the point in such zealotry over something which is merely convenient.

Re:Go by Example by 0xdeadbeefbabe on Friday January 17, 2014 @02:35PM (#7077917)
If only there were a workaround for not having generics, sigh.

But seriously, they may not implement generics out of spite or just to troll generics zealots.

Edit: remove ambiguity

Re:Go by Example by dvirsky on Friday January 17, 2014 @05:14PM (#7078811)
I recently added the statement "type T interface{}" to a piece of code, as a private joke about the generics-in-go talk.

now my code looks like "func map(x []T, f func(T) T)" and everybody's happy :)

Re:Go by Example by earthboundkid on Friday January 17, 2014 @08:52PM (#7079680)
I firmly believe that when Go introduces generics, the syntax should look like:

type T1 generic type T2 generic

func Map(f func(T1) T2, s []T1) []T2

Re:Go by Example by jamesaguilar on Friday January 17, 2014 @02:58PM (#7078053)
I'm not sure what you think I'm trying to fool people about. When Go comes up, I sometimes want to talk about how good I think it is. I hope you don't think I'm trying to hide that. It is pretty common on HN to comment on the merits of a thing when the thing itself comes up, even if said merits are not the specific subject of the link.

I can see that I am putting some people off with my commentary, but other people apparently got new information. Hard to say whether this is a win or loss on net. Time will tell, sooner or later.

Re:Go by Example by bsg75 on Friday January 17, 2014 @12:24PM (#7077039)
Go generics and Mongo durability in the same thread. There is a trifecta brewing here...
Re:Go by Example by sehr on Friday January 17, 2014 @12:40PM (#7077140)
Never underestimate the power of nitpicking in an HN thread.
Re:Go by Example by jamesaguilar on Friday January 17, 2014 @01:24PM (#7077457)
It is amusing that you consider either generics or durability to be "nitpicks." One is a feature that is present in almost every static language of at least the last two decades, and another is a fundamental need of most database users, relational or not. Unless by nitpick you mean, "something I personally don't care about," I think your nitpick-classifier is a bit busted.
Re:Go by Example by sehr on Friday January 17, 2014 @02:32PM (#7077897)
I don't consider the features (or lack thereof) to be nitpicks. They are valid criticisms, but they have had their own very extensive discussions, and we are all very aware of them.

Bringing that into a thread regarding a very cool set of examples regarding the core features of the language, isn't very constructive (at least IMO).

Re:Go by Example by jamesaguilar on Friday January 17, 2014 @02:37PM (#7077934)
Ah. I see where our disagreement comes from. I do not believe that everyone is very aware of these issues. I believe go users are, but since this entire thread is evangelistic, there are people here who are not currently go users who are not aware. The exclamations of surprise at my provided example are proof enough of this for my satisfaction.
Re:Go by Example by justin66 on Friday January 17, 2014 @05:24PM (#7078876)
You do realize that people who look at the tutorial will discover the lack of generics on their own, right? And that if they share the "my God, lack of generics is a war crime!" attitude, they're bound to discover it literally right away?
Re:Go by Example by jamesaguilar on Friday January 17, 2014 @05:35PM (#7078930)
This argument can equally be used to protest the saying of anything good about the language, since obviously people who try the language will discover this good thing quickly if it's useful. This is not a compelling argument to me.
Re:Go by Example by hdevalence on Friday January 17, 2014 @10:29AM (#7076222)
It was in response mainly to:

> Go is that _slim_, and that's good! Guaranteed you'll find use for Go in one system or the other...

I'm all for learning new programming languages, but if you're going to learn a new programming language, why not use one that has new ideas?

Re:Go by Example by bsg75 on Friday January 17, 2014 @11:19AM (#7076539)
Go does not have a lot of new features, but mostly a specific collection of convenient ones (static compilation, GC, etc.) Not sure how many new languages have truly new features, vs. how many are improvements in productivity (human and machine).

My point is that generics are not a new idea either, and plenty of languages offer them. Go is not meant (anymore) to replace C/C++/Java or even Rust. It will never have all the features of those, and probably should not.

But it seems impossible to have a HN discussion on Golang without part of the thread getting hijacked with "But generics!!!" This make no more sense to me than considering other languages incomplete because they don't generate static binaries.

Re:Go by Example by masklinn on Friday January 17, 2014 @01:52PM (#7077645)
> But it seems impossible to have a HN discussion on Golang without part of the thread getting hijacked with "But generics!!!"

Surely the exact same criticism could be leveraged at go proponents pointing out the exact same features they love every time, should discussions of Go simply stop until the next major release, and only new features (if any) be discussable?

Re:Go by Example by burntsushi on Friday January 17, 2014 @05:58PM (#7079055)
> Surely the exact same criticism could be leveraged at go proponents pointing out the exact same features they love every time

This thread was started by someone complaining about lack of generics.

> should discussions of Go simply stop until the next major release, and only new features (if any) be discussable?

Why? Because there's no reasonable middle ground between "don't ever talk about Go until there's a release" and "hijack every thread about Go"?

Re:Go by Example by bsg75 on Friday January 17, 2014 @04:40PM (#7078603)
Note my point in that line was not about criticism, but about thread hijacking.
Re:Go by Example by ckarmann on Friday January 17, 2014 @02:36PM (#7077924)
Learning languages for their new ideas is fine, but there are other reasons you might want to learn a language. For example, because it is a good language for the specific kind of program that you want to write.

Go hits some sweet spot, apparently, since some people are happier using it than anything else they had tried. If no "new ideas" are going to help them, why should they chose more "innovative" languages instead of Go?

Re:Go by Example by genwin on Friday January 17, 2014 @01:26PM (#7077479)
Because it's much faster than other languages at its difficulty level. Which can save a lot of money.
Re:Go by Example by colin_mccabe on Friday January 17, 2014 @07:14PM (#7079395)
Hi hdevlance,

Generics actually have very little to do with sorting a list in Go. The example that the parent gave could be expressed in one line as "sort.Sort(sort.Reverse(sort.StringSlice(vs)));" No generics needed-- only composition. sort.Reverse is a wrapper interface which can be composed with any other sort.Interface to reverse it. It is typesafe, too-- there are no typecasts.

There are cases where generics would allow us to avoid typecasts, but this is simply not one of them. In many cases, what you want can be expressed via composition of types, and often (in my opinion) in a clearer way than by using lambdas, continuations, and callbacks. I suggest learning a bit more about the language and keeping an open mind.

Re:Go by Example by hdevalence on Friday January 17, 2014 @07:28PM (#7079450)
If you say so -- I'm just going off of the examples given in the Go documentation on how to sort lists. If that's not the "Go-ic" way to do it, perhaps the documentation should be updated. If it is the "Go-ic" way to do it, then I think that my point still holds.

I also don't really have a lot of excitement about the prospect of solving problems by composing types in Go. For instance, to the best of my knowledge, Go does not have language support for sum types. It's not that I'd rather use continuations or callbacks -- I like powerful, expressive type systems to do, e.g., static enforcement of contracts -- it's just that I think that Go's type system isn't very expressive.

You're right, perhaps I'm totally misinformed about the language, and that lurking below there really is a way to do clear and clean things with types in Go. But everything I've seen points in the opposite direction, so at this point, though I have an open mind, I'd need more evidence to change my view.

Re:Go by Example by colin_mccabe on Friday January 17, 2014 @07:45PM (#7079492)
The example we were discussing was written by Mark McGranaghan, and is not part of the go documentation per se. I think it's a nice little tutorial, but please don't confuse it with "the Go documentation."

Mark's point was that you can create an arbitrary wrapper type around another interface, so that the behaviors are composed. This is the most flexible way to do things. If there's already a wrapper type that does what you want, however, then you can simply use that. They are both examples of composition, and both "the Go-ic way to do it."

Composition is often overlooked by people who are fixated on other ways of doing things, like inheritance or generics. But in many ways, it's cleaner, since composition allows you to link together many modules without peeking inside.

It's funny that people have accepted the reality of dynamic languages, but can't seem to "get" the idea of statically typed language without generics. There isn't a troll comment in every Python article that it would be better with static typing. Type systems are a little bit like body armor-- development can be slower, but in exchanged you get a little more confidence in the program. People have accepted the idea of going naked, and the idea of medieval-style full plate armor, but the idea that you might want some type safety, but not go overboard often seems to fall on deaf ears.

Re:Go by Example by hdevalence on Friday January 17, 2014 @09:30PM (#7079768)
Actually, the example I was referring to (see my comment elsewhere in the thread) is copied directly from the Go documentation here: http://golang.org/pkg/sort/

Composition is great. It does not solve the same problem as generics. The reason people can't seem to "get" the idea of statically typed languages without generics is because static typing without parametric polymorphism is a painful experience.

I'm not opposed to the idea of finding some balance between static and dynamic typing -- Clojure type annotations seem interesting -- it's just that I don't like the way Go does it.

Re:Go by Example by scriptproof on Friday January 17, 2014 @01:10PM (#7077364)
Re:Go by Example by Dewie on Friday January 17, 2014 @01:21PM (#7077440)
"I resolve to recognize that a complaint reveals more about the complainer than the complained-about. Authority is won not by rants but by experience and insight, which require practice and imagination. And maybe some programming."

Of course, being Rob Pike, decreeing that authority and experience is more valuable than any (well-reasoned) complaints from other people is a very convenient stance for him to take; how many complainers are going to rival his résumé?

Re:Go by Example by burntsushi on Friday January 17, 2014 @06:00PM (#7079062)
That's pretty much the boiler plate ad hominem.
Re:Go by Example by asdf3 on Friday January 17, 2014 @01:38PM (#7077562)
Complaint<generics>("write a bunch of extra boilerplate functions in order to sort a list");
Re:Go by Example by sergiotapia on Friday January 17, 2014 @09:40AM (#7075952)
That's something for the Go creators to decide, but personally I enjoy the feeling of safety that comes with lack of generics. I have very few Go bugs at runtime and I think that explicitness plays a huge part in it.
Re:Go by Example by hdevalence on Friday January 17, 2014 @09:52AM (#7076009)
What? I'm talking about stuff like this, copied from the documentation:

    func (a ByAge) Len() int           { return len(a) }
    func (a ByAge) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
    func (a ByAge) Less(i, j int) bool { return a[i].Age < a[j].Age }
How does forcing me to type out (or copy-paste) an implementation of Swap increase safety? If anything, it just makes the code more error-prone.

And not having generics means that (as far as I can tell) people end up using a lot of `interface{}`. How does that increase safety?

More importantly, why would I want to use a language whose solution to the problem of "dealing with generic data" essentially boils down to "use a void*"?

Re:Go by Example by JeanPierre on Friday January 17, 2014 @09:47AM (#7075987)
Could you elaborate on how generics makes code less safe? In my experience, the lack of generics is much more type unsafe, as you often have to do casts at runtime (and handle them) when you have to implement your own data structures. In contrast, languages with generics handle those at compile time.
Re:Go by Example by pcwalton on Friday January 17, 2014 @01:26PM (#7077481)
Not having generics reduces explicitness (because you don't specify the types of your containers) and reduces safety (because of all the casts and manual implementations of things like swap functions).
Re:Go by Example by fauigerzigerk on Friday January 17, 2014 @02:40PM (#7077955)
On the other hand, C++ templates sometimes make it hard to understand which function ends up getting called, what size a particular type actually has or what is an alias for what.

There are too many indirections to follow manually. All I know is that the compiler will select some function that has conforming types. The compiler is very very smart. It knows all the incredibly complicated name resolution rules and it will use each one of them.

Unfortuntately I'm not as smart. Even after more than 20 years of using C++ I sometimes fail to anticipate which function the compiler decides to use. And that is not safe.

In fact it is less safe than casting interface{}, because that will at least fail fast at runtime instead of silently doing something unexpected.

Re:Go by Example by scott_s on Friday January 17, 2014 @05:23PM (#7078866)
It is possible to have generics without having the specialization rules of C++.
Re:Go by Example by pcwalton on Friday January 17, 2014 @08:31PM (#7079631)
You're criticizing ADL, not generics.
Re:Go by Example by fauigerzigerk on Saturday January 18, 2014 @03:14AM (#7080511)
It's true that I'm not criticising generics in general, but ADL is only part of what makes C++ templates so treacherous.

I think Go needs some form of generics. Every statically typed language does. But after C++ I do understand the hesitation on the part of Go's creators.