On Monday, November 24, 2003, at 03:28 PM, Luke Palmer wrote:
Damian Conway writes:
In which case I think we just fall back to:

try{$opus.write_to_file($file); CATCH {die "Couldn't write to $file:
$!"}}


which is, after all, only 5 characters longer than:

$opus.write_to_file($file) catch die "Couldn't write to $file: $!\n";

;-)

Fair enough :-)


No, I wasn't implying that C<write_to_file> could validly return undef.
I just failed to realize how short the "long" version was.

But you have to admit, the latter version makes the important part of
the expression stand out, and is more natural to write (IMHO, as
always).

But it's moduleable, so I won't worry about it.


A small point of order, philosophically...

While there is a justifiable urge to deny entry into of the core language of as much syntactic sugar as possible -- since merely looking at the operator list proves P6 will be a behemoth of a language, when you consider all of its nooks and crannies -- I think we also need to be skeptical of the false economy of putting such sugar into CP6AN, if a sizable portion of the community is going to download it anyway.

In my mind, Luke's proposed C<catch> modifier quite easily fits the qualifications of something that should be in core, for the following reasons:

- It serves a common purpose, for which there is Only One (Good) Way To Do It. While you perhaps _can_ say

    try {
        $opus.write_to_file($file);
        CATCH {
            die "Couldn't write to $file: $!"
        }
    }

in other golfish ways, the above is clearly (ignoring preferences in whitespace formatting) the Obvious and Recommended way to do it, and so the above phrase will appear _wherever_ a single statement needs to be wrapped with a try/CATCH.

- It has one, and only one, obvious meaning. Nobody should be making their own 'catch' modifiers that do different things -- that would be far more annoying, for shared code, than reserving the keyword in advance to do the One Obvious Thing.

- It is consistent with the philosophy of similar syntax.

- It poses no significant harm to novice users. They can program in P6 effectively without ever using it, but if they do see it in someone else's code, it will be reasonably obvious what it is doing. And whether it is core or commonly used CP6AN, they _will_ see it in other people's code.


It is true, the difference between the two constructs:


try { $opus.write_to_file($file); CATCH {die "Couldn't write to $file: $!"} }

$opus.write_to_file($file) catch die "Couldn't write to $file: $!";

is only 7 characters. But four of those characters are curly brackets, visually introducing two blocks. That's kind of a yuck.

MikeL



Reply via email to