News for hackers. Stuff that matters.
Re:Errors are values by bsdetector on Monday January 12, 2015 @10:13PM (#8877910)
> that's once per 30 or so lines. 2 or 3 percent of the code ... I really prefer the Java "force you to catch exception" model much more to this.

And that 2%-3% doesn't include where errors should have been checked but were not. For instance run programs without stdout ("./program 1>&-") and most Go console programs will just happily write to nowhere whereas almost all Java ones error out immediately. Closing stdout doesn't often matter, but sometimes things like this are important.

I don't understand how in the 2010s it's okay to make a language with worse reliability. And worse "JavaDoc" equivalent. Go should be better than C and Java in every category and it's just not better in way too many.

Re:Errors are values by NateDad on Tuesday January 13, 2015 @09:07AM (#8879889)
My go code is way more reliable than my exception-language code, because I know exactly where it can fail and what happens when it does. It is much harder to see where exceptions can happen and what the code paths will be when errors happen.

Why is not having stdout automatically an error condition? Lots of programs should work fine with no stdout. If a program requires stdout and doesn't fall when it's missing, that's a bug (and pretty easy to fix).

Re:Errors are values by bsdetector on Tuesday January 13, 2015 @11:03AM (#8880623)
> Why is not having stdout automatically an error condition?

In UNIX the file handle an opened file gets is the next available, lowest number. Closing stdout means that the program opens a file and it gets file handle 1 instead of a higher number. Then it writes something to stdout, which is an alias for file handle 1, but instead it writes to the opened file.

I believe this caused some security bugs in passwd or maybe su where you could run it without stderr and "Password:" would be written to the passwd file instead of stderr. ...but these specifics are beside the point, which is that it is next to impossible to anticipate the problems an unhandled error can create.

Java's checked exceptions can be annoying when you have to add some extra "throws X" or handle every case, but my experience is that I never had the slightest doubt over how a method could fail or what needed to be done to handle errors. For unchecked exceptions maybe you have a point, although their failure mode for unhandled errors is still to abort the program rather than to continue on with undefined behavior as in Go.

Re:Errors are values by sangnoir on Tuesday January 13, 2015 @12:41AM (#8878350)
Language design is about trade-offs. Broadly speaking: being good in one category means being bad in another.
Re:Errors are values by TheDong on Tuesday January 13, 2015 @02:11AM (#8878553)
While your comment is sort of true, it's not applicable here really.

We know how to handle errors better than this. Go's error handling is C style. We've since found exceptions, Maybes, and friends which are very powerful.

What you said implies that when Rust chooses to use Maybes they're somehow being bad at something. That's simply false; computer science as a field has advanced and one of these advancements (not even that recent of one) is improved understandings of how strong type systems can be used to make code, including errors, safer. Go completely ignores this of course and they're not doing it for a tradeoff that I can see. They gain nothing in terms of performance for not having this type (everything is already a reflect/Value anyways, so much for not having the baggage that you'd need for generics) and everything in terms of having a worse language.

Being good at something doesn't instantly mean you're bad at something else. In fact, I wouldn't even claim that's the general case.

If you disagree, you're welcome to point out the tradeoffs at work here. I think your comment is just a vaguery that is completely untrue in this instance.

Re:Errors are values by enneff on Tuesday January 13, 2015 @05:52AM (#8879021)
The corresponding loss to Rust's gain is language complexity.
Re:Errors are values by kibwen on Tuesday January 13, 2015 @12:55PM (#8881422)
I think this argument is depressingly uncharitable.

One of Rust's goals was to remove the "feature" of null pointers. In its place rose the feature of tagged unions, to support the `Option` type. This is strictly trading one feature for another. Once this necessary task was completed, Rust was happily able to reap all the benefits of tagged unions elsewhere, such as with the `Result` type. It is not greater language complexity, it is merely the reuse of simple language features to empower developers to create more robust software.

Now, I am not among those saying that Go needs tagged unions, or any other feature for that matter (no, not even that one). I think Go is a good language, sometimes to the surprise of my peers. But what's disheartening to me is seeing a Go core developer imply that Go is literally the baseline for programming language simplicity, in effect papering over all the various tradeoffs that programming language design entails.

Re:Errors are values by enneff on Tuesday January 13, 2015 @03:00PM (#8882146)
You mischaracterised my point. Go is hardly the baseline for language simplicity. We just made a different set of trade offs to the Rust team, and I believe Go is the simpler (not simplest) language.
Re:Errors are values by marktangotango on Tuesday January 13, 2015 @08:49AM (#8879767)
>> We've since found exceptions, Maybes, and friends which are very powerful.

I think, and someone correct me if this is wrong, that implementing exceptions in Go is prohibited by go routines.

The stereotypical way to implement exceptions is using setjmp/longjmp which unwind the stack back to a known location. Since go routines are implemented as continuations, any particular executing go routine may or may not have it's stack in context, and I'm not sure what it means to unwind stacks across multiple continuations, ie is it even possible?

So that's one possible example.

Re:Errors are values by pcwalton on Tuesday January 13, 2015 @09:49AM (#8880144)
> I think, and someone correct me if this is wrong, that implementing exceptions in Go is prohibited by go routines.

No. Go already has all the runtime functionality necessary to support exceptions via panic/recover.

Re:Errors are values by NateDad on Tuesday January 13, 2015 @09:11AM (#8879913)
The tradeoff is complexity. You need to define a maybe for your return value, which needs generics. Whereas Go gets 80% of the functionality with multiple returns which are like 10% odd the complexity (and are useful in other ways).
Re:Errors are values by pcwalton on Tuesday January 13, 2015 @09:52AM (#8880158)
You don't have to have generics to use enums for error handling any more than you need generics to use tuples for error handling. The thing you need is enums/algebraic data types/sum types.

See for example the first answer to this SO question on error handling in Swift, which doesn't use generics at all: http://stackoverflow.com/questions/24010569/error-handling-i...

Re:Errors are values by frowaway001 on Tuesday January 13, 2015 @11:44AM (#8880890)
This is nonsense.