News for hackers. Stuff that matters.
Re:Errors in Go: From denial to acceptance by jstimpfle on Monday November 26, 2018 @04:35PM (#18537010)
> Once you get in the habit, it's not hard to scan through a program line-by-line asking yourself "what would happen if an exception were thrown at this point?" and to take appropriate precautions.

I feel there's a serious disagreement here with how I tend to look at things. I don't want to look line-by-line and ask what would happen in case of an exception. In most cases the answer would be: That would be bad, since the rest of the code would not get executed and the program would remain in an invalid state.

It's much easier to know that there will not be an exception. Simple sequential code, the way it was intended to be by the ancient gods. And handle errors manually where they could in fact occur. I reckon that for my own code, that is only once in a hundred lines or more. Or maybe even more (lines) than that, since I'll abort directly in the callee in many cases anyway, so the caller never gets a chance to see the error. But if there were any point in handling an error in the future, we can still switch to handling it later.

Now you can argue that you can do that with exceptions as well (handling errors directly either by returning an error code or by aborting) such that exceptions would never bubble up. But in that case what's the point in exception handling to begin with? It's just the same now, except that there's a lot of exceptions machinery required in the language.

Re:Errors in Go: From denial to acceptance by renox on Monday November 26, 2018 @06:03PM (#18537664)
Is there such thing as 'simple sequential code'?

Simple? Additions may overflow, printf may fail, etc. Usually code looks simple only because it ignores errors..

As for sequential, we're in the age of multiple cores and GPUs..

Re:Errors in Go: From denial to acceptance by jstimpfle on Monday November 26, 2018 @06:56PM (#18537942)
Of course, sequential code is simple. Overflowing additions don't have anything todo with the code. They overflow or not.

> Usually code looks simple only because it ignores errors..

No, it looks simple when the structure is right. There are other error handling strategies than "handle it now, or pop the stack frame and let your caller handle it now!". But with exceptions that's all the choice you are given (unless you convert them to regular data).

Since exceptions strongly discourage alternative error handling schemes, no wonder they lead to unmaintainable code as soon as a considerable amount of conditions actually should be handled, instead of just bailing out.

> As for sequential, we're in the age of multiple cores and GPUs..

What point are you trying to make? Obviously what I mean by sequential code here is that you can easily reason "if control flow reaches point A, then B will be executed, too".

Re:Errors in Go: From denial to acceptance by codebje on Tuesday November 27, 2018 @12:08AM (#18539580)
> > As for sequential, we're in the age of multiple cores and GPUs..

> What point are you trying to make? Obviously what I mean by sequential code here is that you can easily reason "if control flow reaches point A, then B will be executed, too".

That goes out the door with any parallelism whatsoever, because control flow may reach point A in thread 1, but then thread 2 kills thread 1, and point B is never reached.

It's increasingly hard to bury ones head in the sand and pretend every machine is a single-CPU single-task system with no interrupts.

Re:Errors in Go: From denial to acceptance by jstimpfle on Tuesday November 27, 2018 @07:52AM (#18541893)
Sure, today's CPUs execute not only in parallel but also out-of-order. But that doesn't matter since threads don't let threads die before they've done their share.

Out-of-order makes thread synchronization a little harder (when implementing lock-free algorithms for example), but that has nothing to do with exceptions.

Re:Errors in Go: From denial to acceptance by groestl on Tuesday November 27, 2018 @02:40AM (#18540312)
> and the program would remain in an invalid state.

But this is only ever possible if the program moved to an invalid state in the first place. Granted, sometimes there is no way around that, but usually it can and should be avoided.

Re:Errors in Go: From denial to acceptance by jstimpfle on Tuesday November 27, 2018 @06:05AM (#18541309)
For the programs I write, I'm sure the majority of function invocations do only a partial transformation (i.e., result in an invalid state).