The proper way to open()

Dominic Thoreau dominic at thoreau-online.net
Wed Feb 1 14:24:47 GMT 2012


On 1 February 2012 13:34, Smylers <Smylers at stripey.com> wrote:
> Yitzchak Scott-Thoennes writes:
>
>> On Mon, Jan 30, 2012 at 9:12 AM, David Cantrell
>> <david at cantrell.org.uk> wrote:
>>
>> > On Mon, Jan 30, 2012 at 05:03:47PM +0000, James Laver wrote:
>> >
>> > > On 30 Jan 2012, at 16:56, Dominic Thoreau wrote:
>> > >
>> > > > open IN, '<', $cfg || handle_that_error_sub;
>> > >
>> > > No, explicitly not. The || operator is far too high precedence
>> > > binding. Use 'or' to remove your bug.
>> >
>> > No.  The correct solution to buggy code caused by precedence is not
>> > to invent a new level of precedence, but to use parens.
>
> That makes sense if you see the problem as being one of precedence.

My personal style is to put brackets around the open portion of the
call, but I understand the current trend is to remove these (for
reasons that a: escape me, and b: I'm not that interested in anyway).

open(IN, '>', $cfg) || die "$! made me do it";

this would be fine, as would OR instead of the IIs.
Personally I feel the brackets make things more explicit. At work I've
in the past written complex DB constraints with lots of brackets, and
then been annoyed when Postgres threw hem away, and replaced my
explicit clause with something functionally identical, but impossible
to read.

-- 
Nonnullus unus commodo reddo is mihi.
ABC*D1EFGHIJK2.LMNO3*4PQRST*ITUBE-STANDARD-ANTI-BULLSHEIT-EMAIL*U.56X



More information about the london.pm mailing list