News for hackers. Stuff that matters.
Re:Go 2 Draft Designs by spullara on Tuesday August 28, 2018 @12:36PM (#17860267)
I really thought they were going to allow their idealism to win over pragmatism. Versioned modules, generics and exception handlers all going in is really going to put the defenders of them being missing in a tough spot.
Re:Go 2 Draft Designs by bradfitz on Tuesday August 28, 2018 @12:51PM (#17860431)
Lack of generics was never part of "Go idealism". It has remained an open question for 9 years.

It was added to the FAQ in 2010: https://web.archive.org/web/20101123010932/http://golang.org...

Ian has been thinking about the problem for the past 7+ years, since even before Go1 was out, when the language was frozen.

I think this is about the seventh generics design doc that Ian has written. (This time he wrote it with Robert.) They keep getting better. Hopefully this one holds up.

Re:Go 2 Draft Designs by josefx on Wednesday August 29, 2018 @03:02AM (#17866276)
> Lack of generics was never part of "Go idealism". It has remained an open question for 9 years.

You should read less is exponentially more by Pike. He made it clear back then that he didn't see a need for generics and Go was explicitly written to be a replacement for C++ without all the unnecessary features. Not having generics was at least initially a core part in justifying the existance of Go, just like not having any form of exception handling ( they had to add panic recover quite early ).

Re:Go 2 Draft Designs by calcifer on Wednesday August 29, 2018 @04:49AM (#17866768)
You realize you are trying to explain Go's philosophy to one of the Go developers, right?
Re:Go 2 Draft Designs by josefx on Wednesday August 29, 2018 @06:53AM (#17867217)
Are you claiming that Pike wasn't a core developer and driving force behind Go? Because my point is about the "never" being false when early statements quite clearly said something else.
Re:Go 2 Draft Designs by calcifer on Wednesday August 29, 2018 @02:08PM (#17870311)
> Are you claiming that [...]

No, I'm saying that the person you are replying to has no need of you reminding him of Pike's words, given that he actually knows Pike, unlike you.

Re:Go 2 Draft Designs by josefx on Wednesday August 29, 2018 @07:37PM (#17873003)
So, just that I follow. Go guy claims historically never A.

I point to Pikes blog which clearly said A.

So given these two points I should implicitly discard evidence (in form of a blog entry by one of the Go creators) in favour of a statement that is clearly at odds with it? His connection to Pike or Go does not change the text on the blog, unless you disavow Pikes role in the creation of Go his distaste of generics and his clear classification of them as unnecessary remains a fact.

Re:Go 2 Draft Designs by yashap on Wednesday August 29, 2018 @12:35AM (#17865669)
Agreed! Go is the only language I’ve found that combines static typing, lightning fast compilation, great concurrency support, a lightweight runtime, a community that emphasizes simplicity over purity, a strong ecosystem, and nice tooling.

However, ever churning dependency management, cumbersome error handling and the lack of generics were all huge drawbacks, that kept me reaching for Scala and Python for backends of personal projects. When Go 2 comes out, I think it’ll be my clear #1. It’ll bring the language to the level of power I like, while maintaining Go’s unique set of strengths (listed above).

Re:Go 2 Draft Designs by reificator on Tuesday August 28, 2018 @12:57PM (#17860482)
I've always been of the opinion that generics would be nice to have. But people were acting ridiculous about their exclusion. You can write plenty of useful programs without them.
Re:Go 2 Draft Designs by erik_seaberg on Tuesday August 28, 2018 @01:35PM (#17860865)
You can write any useful program in assembly, but compile time is dirt cheap so it's far more reasonable to automate anything that doesn't require thought and creativity. E.g., a large set of identical function bodies with similar but different types, where if I write them by hand the best I can do is not make any mistakes.
Re:Go 2 Draft Designs by weberc2 on Tuesday August 28, 2018 @08:21PM (#17864105)
I'm generally for generics, but there are tradeoffs. As soon as they debut, expect a flood of overly abstracted libraries. I'm actually pretty apprehensive because I could easily see the costs outweighing the gains.
Re:Go 2 Draft Designs by yashap on Wednesday August 29, 2018 @12:20AM (#17865597)
Agreed that “excess abstraction entering the Go ecosystem” is probably the main danger, but even still, I’m not too worried. The Go community is all about simplicity, and I don’t see that changing. It’s not going to suddenly become the Enterprise Java community. Libraries with crazy abstract APIs won’t become popular.

I expect it’ll be similar to Python, which supports generics, very powerful reflection, many programming paradigms, etc., but the popular libraries tend to have simple, easy to understand APIs, because that’s just the culture of the community.

Re:Go 2 Draft Designs by weberc2 on Wednesday August 29, 2018 @08:26AM (#17867669)
This last point isn’t true at all. Lots of popular libraries do weird things. Lots of popular library functions do completely different things based on the types and combinations of provided parameters (Pandas being one of the most egregious offenders, but the stdlib does this all over too) or they overload operators to make a clever, magical DSL (e.g., SQLAlchemy). Or they use metaclasses to programmatically generate APIs (e.g., AWS sdk, SQLAlchemy, etc). I take notice because I use Python professionally and spend so much more time pouring over docs and source code trying to grok APIs than I do with Go.
Re:Go 2 Draft Designs by yashap on Wednesday August 29, 2018 @10:46AM (#17868570)
Yeah, the scientific Python world is a different story, but I’d say most Python libraries are simple to use, including the AWS SDK. Agreed that SQLAlchemy is much tougher to use if you opt in to their DSL, but to be fair that’s true of every SQL lib with a DSL, in every language I’ve used.

Basically, I find that though it’s possible to do all sorts of crazy shit in Python, most popular libraries have simple APIs, because simplicity is part of Python’s culture. There are certainly exceptions though.

Re:Go 2 Draft Designs by weberc2 on Wednesday August 29, 2018 @01:54PM (#17870227)
Agreed that the scientific community are the worst offenders, but I don't think it's just them. There are examples all over, but I don't think this conversation will benefit from their enumeration. I will point out that you're letting SQLAlchemy off the hook because their DSL is "opt in" and it's par for the course for DSLs; however, their DSL is not really "opt in", it's the standard way for building queries. Further, "DSLs will be DSLs" is kind of missing the point, which is that the Go community rejects these kinds of hacky DSLs while the Python community embraces them.

At the end of the day, I notice a significant difference in wanton magic between the Go and Python communities, and it's big enough to make me prefer Go over Python when given the choice (despite that I've used Python far longer and more regularly).

Re:Go 2 Draft Designs by pjmlp on Wednesday August 29, 2018 @03:43AM (#17866443)
Those overly abstracted libraries already exist, they are just using interface {} everywhere or go generate.
Re:Go 2 Draft Designs by weberc2 on Wednesday August 29, 2018 @08:28AM (#17867676)
Maybe, although I suspect that these libraries are but a shadow of what will follow the release of generics. Hopefully I’m wrong! :)
Re:Go 2 Draft Designs by pjmlp on Tuesday August 28, 2018 @02:58PM (#17861785)
Of course we can, after all we were writing code before generics became mainstream around the mid-2000's.

The point was creating a language without them after they had become a common language feature across all major static languages.

Re:Go 2 Draft Designs by randomdata on Tuesday August 28, 2018 @03:50PM (#17862253)
C doesn't have generics. Objective-C didn't get generics until 2015, which is well after Go was released. Not all major static languages have generics and not all major static languages had generics when Go was being planned.

Not that Go ever planned to not have generics. It was always simply a question of how to implement them in a non-ridiculous way. They were warned early on by members of the Java team to tread carefully and not make the same mistakes they did.

The team has crafted many generics proposals over the years, but they all fell short one way or another.

Re:Go 2 Draft Designs by pjmlp on Tuesday August 28, 2018 @04:30PM (#17862573)
C has basic support for generics since 2011.

Objective-C merges C's type system with the dynamism of Smalltalk. Generics are only meant as a mechanism to ease interop with Swift.

Dynamic languages naturally don't require generics due to their semantics.

The team always handwaved the remarks of many of us as they now themselves recognise.

"In retrospect, we were biased too much by experience with C++ without concepts and Java generics. We would have been well-served to spend more time with CLU and C++ concepts earlier."

Re:Go 2 Draft Designs by lazyjones on Wednesday August 29, 2018 @06:21AM (#17867104)
To be fair, we had macros and they covered many of the uses of generics people are arguing with.
Re:Go 2 Draft Designs by weberc2 on Tuesday August 28, 2018 @06:34PM (#17863537)
Yeah, I can't count the times I heard some variation of "It's literally impossible to ship software without generics" from /r/programming alone. The OP's idealism/pragmatism comment is particularly misguided, since Go consistently favors pragmatism over idealism and in fact that was why Go has held off for so long on adding generics (idealism would have added them from day 1, consequences be damned).
Re:Go 2 Draft Designs by the_duke on Tuesday August 28, 2018 @12:43PM (#17860346)
Edit: To clarify, the handle() system does indeed resemble an exception propagation system and is also the part I like least.

Just "check" would be preferable, with an implicit handler of "if err != nil { return err }"

Although I still would prefer something leaner like the "?" operator from Rust.

Re:Go 2 Draft Designs by jerf on Tuesday August 28, 2018 @01:04PM (#17860548)
One of the key characteristics of exception handling is the ability to set a handler in one stack frame, but receive exceptions from deeper in the stack, causing error-handling-at-a-distance. Anything that does not have that is not an exception system.

Proof: Any exception system that lacked the ability to catch exceptions from lower frames would be called a defective exception system.

This check keyword does not implement an exception handling system.

Re:Go 2 Draft Designs by spullara on Tuesday August 28, 2018 @02:48PM (#17861665)
This is the default behavior of the new check system. If you don't handle it at the bottom of the stack it is propagated up the stack to the caller automatically. Not sure how easy this will be to debug since it doesn't capture a stack trace at the bottom and it won't be obvious where the error started.
Re:Go 2 Draft Designs by grey-area on Tuesday August 28, 2018 @03:07PM (#17861875)
But isn’t it only to the immediate caller using the explicitly declared error, not all the way up the stack?

That’s very different behaviour and along with using the error interface avoids the main objections to exceptions ( unexpected throws handled far from the error location, unexpected errr types).

This is just a small change to make it easier to annotate and easier to return without comment.

Re:Go 2 Draft Designs by spullara on Tuesday August 28, 2018 @03:58PM (#17862325)
Assuming the caller uses check as well it will continue on. Seems the same as checked exceptions to me.
Re:Go 2 Draft Designs by grey-area on Wednesday August 29, 2018 @03:05AM (#17866290)
That’s an invalid assumption, as most functions will not use check (looking at my code there are just a few places I’d use it). It’s an addition to current error handling, not a replacement.
Re:Go 2 Draft Designs by spullara on Tuesday August 28, 2018 @12:48PM (#17860393)
Ok, we won't call them exception handlers. Instead, call them "if anything goes wrong in this function do this" handlers.
Re:Go 2 Draft Designs by SamWhited on Tuesday August 28, 2018 @01:59PM (#17861136)
Those are very different things, whatever you want to call them. check/handle doesn't involve unwinding the stack, and doesn't default to crashing your program if you forget to add a handle block.
Re:Go 2 Draft Designs by tonyedgecombe on Tuesday August 28, 2018 @02:45PM (#17861633)
and doesn't default to crashing your program if you forget to add a handle block

Is that a good thing?

Re:Go 2 Draft Designs by grey-area on Tuesday August 28, 2018 @03:13PM (#17861930)
Is that a good thing?

Yes, because instead your program won’t compile if you forget to handle an error ( except in the case of a function which only returns error, which you can ignore by mistake - I would like to see that fixed in go 2 as well).

Re:Go 2 Draft Designs by fwip on Tuesday August 28, 2018 @07:04PM (#17863704)
Expect to see a lot of `_, _ = fmt.Println(...)`, then.
Re:Go 2 Draft Designs by grey-area on Wednesday August 29, 2018 @02:42PM (#17870577)
Since they’re calling it go 2 perhaps they could just make an exception for println by having an alternative with no error (like map access with k,ok or just k).
Re:Go 2 Draft Designs by quotemstr on Tuesday August 28, 2018 @12:47PM (#17860391)
> The draft design introduces two new syntactic forms. First, it introduces a checked expression check f(x, y, z) or check err, marking an explicit error check. Second, it introduces a handle statement defining an error handler. When an error check fails, it transfers control to the innermost handler, which transfers control to the next handler above it, and so on, until a handler executes a return statement.

Sure. It's explicit error handling that just so happens to look exactly like a form of exception handling, c.f., the zero-overhead exceptions proposal in C++land.

This is how you say, in language-design-ese, "I want to do what my critics have been saying for years is the right thing without admitting that they've been right all along".

Re:Go 2 Draft Designs by heavenlyhash on Tuesday August 28, 2018 @01:13PM (#17860635)
I really don't know where people get on this high horse and imagine that there's been some kind of fighting attitude here.

I saw a talk by James Gosling (of Java fame) a few months ago in which he said one of the most important things he's glad he did throughout the development of the language is "Decide... not to decide".

The purpose of this "deciding not to decide" should sound familiar by now: once you commit to something, it's hard to backtrack. And once it's hard to backtrack, you have lost your ability to look for more optimal solutions than the one you've fixated on.

This is why generics in Java took so long. And to this day, the developers of those generics do not regret taking their time to do so. I think that's interesting to note, don't you?

It's okay to make decisions after deliberation.

Deliberation does not imply a fight.

---

Tone police aside, did you... read... the proposals? I don't think it's correct to dismissively say that the proposed handle/check syntax is identical to other checked exception syntaxes; it doesn't compose in the same way as traditional try-catch blocks; and it doesn't have the power to create arbitrary longjumps across multiple stack frames as exceptions do. In short, it's very little like traditional exceptions at all.

Re:Go 2 Draft Designs by pjmlp on Tuesday August 28, 2018 @02:55PM (#17861744)
Actually they do, hence the ongoing work to add value types and reified generics to Java, which is again a multi-year project with no defined end date.
Re:Go 2 Draft Designs by heavenlyhash on Monday September 10, 2018 @06:10AM (#17950665)
Sure, but just like there's a difference between "deliberation" and "a fight", there's also a difference between "hmm, there's more to do" and "we regret the thinking we invested so far".
Re:Go 2 Draft Designs by rsc on Tuesday August 28, 2018 @01:15PM (#17860661)
If you are interested in learning why check-handle differs from traditional exception handling, you can read https://go.googlesource.com/proposal/+/master/design/go2draf....

If you just feel like snarking, then sorry for spoiling.

Re:Go 2 Draft Designs by int_19h on Tuesday August 28, 2018 @10:54PM (#17865128)
Are there any write-ups on how your error handling proposal interacts with higher-order functions and generic wrappers? That has always been a problem with "explicit everything" approach to error handling, in my experience - like, if you map() over a collection that does disk I/O as part of its implementation, then map() needs to be able to flow I/O errors through - but it can't be aware of them specifically, because it's a generic algorithm. In Java, it pretty much meant that you had to use the RuntimeException escape hatch, defeating the purpose of checked exceptions. For another example, generic collection interfaces don't reflect the fact that e.g. fetching an item can fail, making them that much less generic.

And to work around that problem, you need some kind of generics that lets you define error signatures in terms of other signatures - e.g. for map(), you want to say that it can return an error if and only if the function it maps can return an error (and ditto for error types).

Re:Go 2 Draft Designs by erik_seaberg on Tuesday August 28, 2018 @02:31PM (#17861479)
It looks like the only difference is that catch blocks precede try blocks and aren't indented to show how they nest. One could mechanically convert

  handle err {
          cleanup1()
          return 42, nil
  }
  handle err {
          cleanup2()
  }
  check dostuff()
into

  try {
      try {
          dostuff();
      } catch (Exception e) {
          cleanup2();
          throw e;
      }
  } catch (Exception e) {
      cleanup1();
      return 42;
  }
Re:Go 2 Draft Designs by ianlancetaylor on Tuesday August 28, 2018 @02:47PM (#17861660)
That is not the only difference. Exceptions travel through calling functions if there is no catch clause. The check construct does not.
Re:Go 2 Draft Designs by erik_seaberg on Wednesday August 29, 2018 @12:20AM (#17865596)
When every function call uses "check", we end up with the same control flow as exceptions, which is almost always what I want. You only get different behavior where you don't use it.
Re:Go 2 Draft Designs by spullara on Tuesday August 28, 2018 @02:49PM (#17861684)
The default handler just propagates the error up to the caller.
Re:Go 2 Draft Designs by ianlancetaylor on Tuesday August 28, 2018 @04:06PM (#17862390)
And then the caller has to either check or ignore the error. The error never propagates to the caller's caller without an explicit action in the caller. That is unlike exceptions.
Re:Go 2 Draft Designs by ianlancetaylor on Tuesday August 28, 2018 @04:24PM (#17862525)
What is an "unmarked check call"?
Re:Go 2 Draft Designs by quotemstr on Tuesday August 28, 2018 @04:15PM (#17862456)
But it will propagate through a chain of unmarked check calls. If the requirement to mark potentially-throwing call sites is what disqualifies an error handling scheme as belonging to the class of exception systems, then we need a new term that includes both exceptions and this proposal and excludes everything else, because the proposed Go scheme very closely resembles exceptions.
Re:Go 2 Draft Designs by ecnahc515 on Tuesday August 28, 2018 @08:53PM (#17864282)
An unmarked check call would mean explicit error handling like if err != nil {} which isn't unchecked..it's just checked not using `check`. If you don't have this, then your error variable will be unused an you'll get a compile error.
Re:Go 2 Draft Designs by dnomad on Tuesday August 28, 2018 @01:56PM (#17861098)
To some extent I almost wish they had stuck to their guns. The current brokenness actually serves as a much stronger argument for why exceptions are needed. There's a visceral understanding that comes from forcing people to handle every error immediately that is actually very hard to teach.