Preferences

Okay, sure. Here is an explicit code example:

     func foo(bar func() error) bool {
          err := bar()
          if err != nil {
               return true
          }
          return false
     }

     func TestFooReturnsTrueWhenBarReturnsError(t *testing.T) {
          if foo(func() error { return nil }) {
               t.Error("expected foo to return false")
          }
          if !foo(func() error { return errors.New("error") }) {
               t.Error("expected foo to return true")
          }
     }
Now it is your turn. Modify the body of function foo to remove the error check as you imagine it would be if it were forgotten.

This https://go.dev/play/p/k8zDQj5knaj is what I envision you are talking about, but clearly that cannot be it. As you can see it loudly proclaims that I "forgot", making this forgetfulness idea you have come up with impossible. So, what it is that you actually have in mind?


That is not what is being discussed and you know it.

Provide an example backing up your claim regarding pattern matching + union types:

> Like in the same way you might forget to write pattern matching code?

> That is not what is being discussed and you know it.

That is exactly what is being discussed. Why would the topic arbitrarily change? In case you have forgotten, my literal question/assertion was:

"How would you forget, exactly? Your tests are going to blow in your face should you ever leave out an entire feature from the implementation."

Go on, show us: How would you forget?

> Provide an example backing up your claim regarding pattern matching + union types:

Uh... Okay. Sure? Strange request, but here is an example in CrabLang that meets your ask:

    let result = foo();
    match result {
        Ok(value) => println!("Result: {}", value),
    }
There you go. I forgot to check the error.

Like I said in the full comment that you quoted from, you'll soon recognize your forgetfulness once you apply your checks and balances, but for that brief moment in between it is possible to forget. It must be that way else it would be impossible to input the program. If that's what you think we're talking about... Why? And let me ask again like I did in the comment you quoted from: What is the significance of that? If you had carried that quote through you'd also see: "That's not a real problem." I stand by that. Why not you?

I'm not sure what the other commenter's point is. If you're checking if the error is nil, or pattern matching on the result of a call, it feels like exactly the same.

In your CrabLang example, you don't have warnings on (I assume they exist) for completion or whatever. There's still the Err case that should at least throw a warning for not being caught.

This item has no comments currently.

Keyboard Shortcuts

Story Lists

j
Next story
k
Previous story
Shift+j
Last story
Shift+k
First story
o Enter
Go to story URL
c
Go to comments
u
Go to author

Navigation

Shift+t
Go to top stories
Shift+n
Go to new stories
Shift+b
Go to best stories
Shift+a
Go to Ask HN
Shift+s
Go to Show HN

Miscellaneous

?
Show this modal