Raku / doc

🦋 Raku documentation
https://docs.raku.org/
Artistic License 2.0
287 stars 291 forks source link

Returns signature check gets Nil, skip or run #3760

Open fecundf opened 3 years ago

fecundf commented 3 years ago

Confusing second Nil meaning

Nil is defined as being both "Absence of a value" and also "a benign failure," but the documentation does not justify or give examples of the "benign failure" sense.

I and at least one other beginner see the value in "Absence of a value" but not the "Benign failure" case, and have tripped on attempting to create a return signature that specifies a non-Nil return, eg "block always returns a value."

Suggestions

  1. Use the Failure type (undefined Failure) as "benign failure," and revert Nil to its pre-2016 sense as being "Absence of a value" solely
  2. OR explain the reasons to have Nil as an uncatchable return value, in addition to being an absence placeholder– why is it a Raku-ish helpful duality?

(edit) FYI commit that documented the additional "benign failure" sense is at https://github.com/Raku/doc/commit/2b3c920ae9c37d14f76ab1eab236df2ec4f513ec

JJ commented 3 years ago

Thanks. We'll do our best to try and fix this.

fecundf commented 3 years ago

Thanks for the eyes on this! Please share thoughts, I would like to know reasoning behind any changes or not, and happy to think more & discuss this bit of Raku-ness.

doomvox commented 3 years ago

The initial discussion about this issue was on the perl6-users list, "Checking for nil return":

https://www.nntp.perl.org/group/perl.perl6.language/2020/12/msg36850.html

doomvox commented 3 years ago

Sorry, I meant the perl6-language list (and github isn't letting me edit old comments now).

There was some discussion there about distinguishing between the output channel and the error channel. Myself I think there is a problem with the current behavior: the return value from a routine is something you would expect the programmer to be in complete control over, having a special value that you're restricted from messing with seems very strange...