Comment

Comment by JamesSwift

I havent followed this argument closely so forgive me if I'm missing relevant discussion, but I dont see why the Rust style isnt just adopted. Its the thing I immediately add now that I have generics in Go.

I only see this blurb in a linked article:

> But Rust has no equivalent of handle: the convenience of the ? operator comes with the likely omission of proper handling.

But I fail to see how having convenience equates to ignoring the error. Thats basically half of my problem with Go's approach, that nothing enforces anything about the result and only minimally enforces checking the error. eg this results in 'declared and not used: err'

  x, err := strconv.Atoi("123")
  fmt.Println("result:", x)
but this runs just fine (and you will have no idea because of the default 0 value for `y`):

  x, err := strconv.Atoi("123")
  if err != nil {
    panic(err)
  }
  y, err := strconv.Atoi("1234")
  fmt.Println("result:", x, y)
this also compiles and runs just fine but again you would have no idea something was wrong

  x, err := strconv.Atoi("123")
  if err != nil {
  }
  fmt.Println("result:", x)
Making the return be `result` _enforces_ that you have to make a decision. Who cares if someone yolos a `!` or conveniently uses `?` but doesnt handle the error case. Are you going to forbid `panic` too?
parent JamesSwift 1 year ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton