News for hackers. Stuff that matters.
Re:Go 1.3 is released by duaneb on Wednesday June 18, 2014 @10:10PM (#7914051)
I think it's pretty clear by now Go is not aligning itself with type parameters. If you need generics, don't use Go. Most programs probably don't need generics.
Re:Go 1.3 is released by joncooper on Wednesday June 18, 2014 @11:38PM (#7914323)
My understanding is that the Go team isn't opposed to generics, and in fact is quite aware of their value, but that:

- it isn't a priority

- it is a tricky thing to get right in the context of Go

- there haven't been any satisfactory proposals thus far

If this isn't quite right I'd love to be corrected.

Re:Go 1.3 is released by coldtea on Thursday June 19, 2014 @05:36AM (#7915352)
That was the common understanding from 2-3 years ago, when they left the question hanging and said that "we'll do it when we find the proper way etc".

In the meantime there have been several satisfactory proposals (in the lists and elsewhere), and it's not like 200 other languages implementing Generics have had many issues with them.

So, it boils down to the Go core team putting up the solution to an impossible tradeoff as the holdback (and a little exagerrated one at that, with relation to the costs involved).

And then, they said "the language won't change" etc recently.

Re:Go 1.3 is released by lbruder on Thursday June 19, 2014 @08:59AM (#7915790)
So it's more like Guido refusing to add TCO to Python because that would be oh so hard to do. And look, the stack trace! The horror, the horror. /s
Re:Go 1.3 is released by duaneb on Thursday June 19, 2014 @10:16AM (#7916164)
I'd like to add that generics can add a lot of complexity to a compiler, and the compiler's simplicity is IMHO of great benefit to the language. I'm happy they're taking their time with it; it's better than ending up with a half-assed implementation like Java.
Re:Go 1.3 is released by mrgriscom on Thursday June 19, 2014 @08:46AM (#7915741)
that is basically the "please go away and stop asking" response
Re:Go 1.3 is released by collinvandyck76 on Wednesday June 18, 2014 @10:31PM (#7914101)
Most programs don't need generics, but a lot of programs benefit from having them. This, along with exceptions, are the two things that keep me from considering Go for future service development. We've stood up a couple of successful Go services, but the maintenance overhead from not having these two things has been substantial.
Re:Go 1.3 is released by seanmcdirmid on Wednesday June 18, 2014 @10:43PM (#7914138)
Go has something that is functionally equivalent to exceptions; they just don't call them exceptions and make them look a lot different from what we are used to.
Re:Go 1.3 is released by collinvandyck76 on Wednesday June 18, 2014 @11:25PM (#7914245)
If you're talking about panics, you can only handle them in defer funcs if I'm not mistaken, which makes them significantly different from exceptions that I'm used to that can be caught in any part of the code. The dependency on defer in my opinion makes them unusable as typical exceptions in my case. This was perhaps the intent, making panics and the recoveries thereof truly exceptional and painful, pushing one towards the normal error handling semantics, which is what I dislike.
Re:Go 1.3 is released by cmelbye on Thursday June 19, 2014 @12:47AM (#7914521)
It's true that you can only handle them in defer funcs, but the defer func could be anywhere up the stack, not just the current function you're inside.

(I'm not sure if that was your understanding or not)

"The panic and recover functions behave similarly to exceptions and try/catch in some other languages in that a panic causes the program stack to begin unwinding and recover can stop it. Deferred functions are still executed as the stack unwinds. If recover is called inside such a deferred function, the stack stops unwinding and recover returns the value (as an interface{}) that was passed to panic."

https://code.google.com/p/go-wiki/wiki/PanicAndRecover

Re:Go 1.3 is released by dragonwriter on Thursday June 19, 2014 @01:32AM (#7914606)
> If you're talking about panics, you can only handle them in defer funcs if I'm not mistaken,

That's true...but no different from "exceptions can only be caught in catch blocks".

> which makes them significantly different from exceptions that I'm used to that can be caught in any part of the code.

It doesn't make them any different from exceptions -- just as a catch block can be anywhere up the call chain, a deferred function can have been set anywhere up the chain.

Defer is basically "finally", except the position is different, and "recover" inside it lets it also do what "catch" does.

Re:Go 1.3 is released by mwsherman on Wednesday June 18, 2014 @11:20PM (#7914228)
Yes and no, errors are just return values. They’re not special, they are conventional. So you get the whole type system to express errors – they’re just values. And you don’t have a different control flow.

It’s not without warts. You can bail with panic(), which is essentially a throw.

It’s tedious to handle errors, but that’s because actually handling errors is tedious.

Re:Go 1.3 is released by eropple on Thursday June 19, 2014 @01:28AM (#7914596)
"Actually handling errors" isn't tedious at all in Scala. Chain flatMap() across methods that use Try[A], handle the Failure[_] at the other end, and you're done.

I'm not joking when I say it really is that easy. Go makes it (and, really, many other things) very difficult for reasons that are at best murky.

Re:Go 1.3 is released by NateDad on Thursday June 19, 2014 @01:13PM (#7917158)
So you call say 3 methods, and at the end you have a "file not found" error... which call resulted in that failure? I don't know Scala specifically, but from what I know of most languages that support this kind of chaining, you can't tell. And that's the problem. Did your initialization fail to find it's config file in step 1? Did you fail to find the target file you were going to transform in step 2? Was there some other failure in step 3? You can't tell, so you can't actually handle the error.

This is effectively like doing this in Java:

  try {
      DoX()
      DoY()
      DoZ()
  } catch( Exception ) {
      // The code has no idea what failed here.
  }
Whereas, the go code looks like this:

  if err := DoX(); err != nil {
      // handle error from DoX
  }
  if err := DoY(); err != nil {
      // handle error from Doy
  }
  if err := DoZ(); err != nil {
      // handle error from DoZ
  }
This is what Go programmers means when they say "actually handle the errors". At each step you handle the specific failure from the specific call. It's somewhat more verbose, but it's a LOT more robust against real life failures.
Re:Go 1.3 is released by pcwalton on Thursday June 19, 2014 @02:38PM (#7917603)
You'd have the same effect (you don't know what specific call failed) if all of the comment lines said "return err", which is a common pattern in Go. The Scala approach mentioned is just sugar for that. You can of course handle each case separately if you want in Scala, just as you can in Go, but the common pattern has sugar.
Re:Go 1.3 is released by frowaway001 on Thursday June 19, 2014 @02:47PM (#7917658)
What? Actually, absolutely not.

If you only care about whether something succeeded use Option, if you care about the error use Either, Validation, etc.

Just pick the right Monad.

Re:Go 1.3 is released by pcwalton on Thursday June 19, 2014 @06:18PM (#7918584)
Yes, I agree, but I don't see how that's related to what I said.
Re:Go 1.3 is released by frowaway001 on Friday June 20, 2014 @09:02AM (#7920484)
Then maybe don't comment?
Re:Go 1.3 is released by eropple on Friday June 20, 2014 @04:25PM (#7922694)
> So you call say 3 methods, and at the end you have a "file not found" error... which call resulted in that failure?

The first exception hit pops out the other side and you pattern-match against it. So, the one that did file access and returned a FileNotFoundException. If you have multiple pieces of code that can return FileNotFoundExceptions, you can pass a message in the exception, just like any other Java exception. You can often be more type-specific, too. Bear in mind that defining a new exception in Scala is a one-liner, and you can encapsulate your FileNotFoundException in a RetrievalFailedException very easily and cleanly.

Your method is not more robust, I assure you--it's just verbose and both typo- and thinko-prone.

Re:Go 1.3 is released by gouggoug on Thursday June 19, 2014 @03:12AM (#7914816)
Errors are just return value, but in go, you either explicitly ignore the error returned (using the "blank identifier" _ ), or, you assign it, in which case you have to deal with it (otherwise go will complain about an unused variable).

An that is what makes go awesome. In java or php, you, as a developer, can never know wether the functions you are calling will throw an exception. The only way to know? Read the doc, if you're lucky and there's a doc, or read the code... The result? your program will crash if you didn't add your try..catch block.

Go forces you to either explicitly ignore errors (and your fellow co-worker will know you did it on purpose) or deal with them. No surprises.

Re:Go 1.3 is released by Peaker on Thursday June 19, 2014 @03:17AM (#7914834)
I get the same in C, with gcc's __attribute__((warn_unused_result)).
Re:Go 1.3 is released by aktau on Thursday June 19, 2014 @04:33AM (#7915180)
This comment should be more prominent, warn_unused_result is pretty awesome!
Re:Go 1.3 is released by tmhedberg on Thursday June 19, 2014 @10:31AM (#7916242)
> In java or php, you, as a developer, can never know wether the functions you are calling will throw an exception.

That's what checked exceptions are for in Java.

Re:Go 1.3 is released by gouggoug on Thursday June 19, 2014 @01:28PM (#7917235)
The larger problem with exceptions, checked or not, is that they interrupt the flow of your program, which is too bad since most exceptions are not that exceptional. That problem is exacerbated by developers who don't know how and when to throw exceptions and end up throwing exceptions for easily recoverable errors. The other thing I dislike about exception is that your code ends up with tons of try..catch blocks.
Re:Go 1.3 is released by disputin on Thursday June 19, 2014 @09:11AM (#7915840)
It's that convention and exclusion of special abstractions that appeals to me by keeping the cognitive load to a minimum. I can focus on the problem without thinking about the language. If Go became like various other languages, then what would be the point? We already have Java, C#, ...
Re:Go 1.3 is released by dragonwriter on Thursday June 19, 2014 @10:11AM (#7916129)
The only real significant difference between panics and exceptions in the Java/Python/etc. style is that -- reflecting (apparently) the same philosophy of explicit-over-implicit that governs other Go error handling -- the common catch-one-kind-of-exception-and-implicitly-rethrow-everything-else idiom of the Java/etc. language is inconvenient and verbose to express in Go (though if you really want to use that idiom a lot, it seems like it should be implementable in a library function to create that kind of handler that would then eliminate the boilerplate on each use, though given Go's convention on panics generally not crossing public API boundaries, you shouldn't need that idiom as much in Go code.)
Re:Go 1.3 is released by seanmcdirmid on Wednesday June 18, 2014 @10:19PM (#7914072)
Most programs don't need generics like most programs don't need static typing. Just use "any" and downcast.
Re:Go 1.3 is released by gohrt on Thursday June 19, 2014 @12:08AM (#7914444)
That's entirely different. Generics can be replaced by code-generation (C++-style templates) in a preprocessor with no loss of safety, or by boring copy-paste (with some loss of safety :-().

non-static typing is a massive loss of safety.

Re:Go 1.3 is released by pcwalton on Thursday June 19, 2014 @12:13AM (#7914459)
Static typing can be replicated in a dynamically typed language with a preprocessor too. (For example, see TypeScript.)
Re:Go 1.3 is released by seanmcdirmid on Thursday June 19, 2014 @03:00AM (#7914793)
Templates/macros/preprocessing do sacrifice separate compilation and separate type checking; so your error messages might not be comprehensible, your compile times can be much slower, and...you need source for your generic container. Rob Pike probably knows the drawbacks of that approach well and I doubt he would go there.
Re:Go 1.3 is released by coldtea on Thursday June 19, 2014 @05:29AM (#7915334)
No programs really needs anything above assembly.

It's the "nice to have" things that make programming easier/more correct/better.

Re:Go 1.3 is released by drdaeman on Thursday June 19, 2014 @12:23PM (#7916892)
A single instruction is sufficient. Anything more just complicates things and is completely unnecessary.
Re:Go 1.3 is released by Touche on Wednesday June 18, 2014 @11:03PM (#7914181)
Most programs do list manipulation and list manipulation in Go is a pain. Generics are one solution for that.
Re:Go 1.3 is released by nonuby on Wednesday June 18, 2014 @11:49PM (#7914362)
I agree generic would be a serious win for Golang. However in the meantime we have this workaround/hack which alleviates some of the pain http://clipperhouse.github.io/gen/
Re:Go 1.3 is released by mwsherman on Thursday June 19, 2014 @12:11AM (#7914451)
Appreciate the mention! Also gen is getting more, um, generic with the notion of custom ‘typewriters’, out on this branch: https://github.com/clipperhouse/gen/tree/3.0
Re:Go 1.3 is released by logicchains on Thursday June 19, 2014 @12:00AM (#7914403)
Lisp manipulation? Do you mean linked lists, or arraylists? The only common use of linked lists I've encountered is writing custom allocators, and most programs don't need custom allocators.
Re:Go 1.3 is released by personZ on Thursday June 19, 2014 @09:27AM (#7915898)
Go "lists" are type dynamic -- "generics" in the most important place for generics to be.
Re:Go 1.3 is released by steveklabnik on Thursday June 19, 2014 @10:43AM (#7916312)
Heterogeneous lists are not "generics."
Re:Go 1.3 is released by personZ on Thursday June 19, 2014 @11:16AM (#7916522)
A Go map is of the defintion map[KeyType]ValueType. A Go slice and dynamic array is similar typed. That isn't heterogeneous, it isn't of type object, and is 99% of the common use of generics.

Yeah, the native fundamental collections are generic.

Re:Go 1.3 is released by steveklabnik on Thursday June 19, 2014 @11:23AM (#7916570)
I have a feeling we're talking about different things: when people speak about Go generics, they mean that the language doesn't support parametric polymorphism. Yes, some of the built-in types are special. That's not the point.
Re:Go 1.3 is released by _ak on Thursday June 19, 2014 @06:10AM (#7915419)
lolwhat? How exactly would list manipulations in Go be made easier because of generics?
Re:Go 1.3 is released by TheCoelacanth on Thursday June 19, 2014 @10:55AM (#7916384)
How many of these[1] functions can I write in Go without doing a bunch of casting? Probably less than half.

[1] https://hackage.haskell.org/package/base-4.7.0.0/docs/Data-L...