News for hackers. Stuff that matters.
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.