Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make IO::Path.dir throw rather than fail
In general, if something is returing an Iterable, we throw rather than fail to prevent exactly the problem that R#2650 describes. Is spectest clean, so we weren't too strict about this anyway.
- Loading branch information
38f4b7b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hop isn't to late to be against.
I used to wrote
In general I think that every
throw
prevents the handling withwith
reducing its usefulness.38f4b7b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@salortiz interesting… can you file a ticket, please? At the very least we probably want to grep through the ecosystem for lines like that.
But I don't think it prevents much. Just add a
try
(likewith try '/some/dir'.IO.dir …
)38f4b7b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AlexDaniel, using
with try
hides theFailure
in theelse
block, please compare:with
While a
Failure
can be handled cleanly withwith
,//
,orelse
, etc. or opted-out by thefatal
pragma or, in this case, a simple type constraint;throw
should be handled withtry
and$!
or with aCATCH
block, both polluting the lexical scope.Try to rewrite, with the current status the elegant:
It is a matter of flexibility and choices to the user. In my opinion, Perl6's Exception/Failure model is an important differentiator, despite not being very widespread nor well documented.
A simple
my Str @foo = ...
would have sufficed to the original #2650 reporter.I'm thinking in fill a ticket in
spec
to encourage the discussion in search of 'best-practices' in this matter.Any thoughts @lizmat?
38f4b7b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason why this wouldn't suffice?
38f4b7b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a
CATCH
block modifies the semantic of the lexical scope around it, I use only when I needs centralized handling for, potentially many unrelated,Exception
s.This is all about different paradigmatic positions.
My main stance in this 'thrown Exception' vs 'return Failure' is that the former, as a one-way road, forces the user to use the CATCH paradigm, the latter allows others. TMTOWTDI