top | item 18538099

(no title)

hpbd | 7 years ago

I don't understand. I have a C background. What is wrong with that?

discuss

order

TheDong|7 years ago

In many languages invented since c that have errors as values, you can use something akin to a specialized monad to sequence things which may fail together.

For example, in rust you could use:

    let res1 = w.Write(...)?;
    let res2 = w.Write(res1)?;
In haskell, you can use do notation or monad binding to do a similar thing.

Of course C doesn't have a good type system that allows this sort of thing; it was created before such type systems were well known.

I would expect any modern language to at least recognize that there are good ways to sequence and compose types.

nkozyra|7 years ago

Probably the repetition of

if err != nil {}

You get used to that pretty quickly in Go, but it still looks messy to a lot of people.

dymk|7 years ago

And so it's clear to others, this probably the worst possible way for a language to go about implementing error handling (maybe aside from just not having any mechanism outright and terminating).

But alas, those are the choices that the Go language made.

bouncycastle|7 years ago

The alternative is just as bad, a multi block try and catch mess that is in Java!