perl_constants_and_english

This is part of The Pile, a partial archive of some open source mailing lists and newsgroups.



Path: nntp.stanford.edu!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.direct.ca!look.ca!newsfeed.concentric.net!global-news-master
From: abigail@delanet.com (Abigail)
Newsgroups: comp.lang.perl.misc
Subject: Re: Why $|++ instead of $|=1 ?
Date: 08 Jul 2000 12:58:54 EDT
Organization: Abigail's Kinderboerderijen
Lines: 31
Message-ID: <slrn8meofv.rbj.abigail@alexandra.delanet.com>
References: <8k0m4d$13o$1@panix3.panix.com> <slrn8m7s9q.ibb.abigail@alexandra.delanet.com> <3967456e.12650700@news>
Reply-To: abigail@delanet.com
NNTP-Posting-Host: 216.112.173.227
X-Date: MMDIII September MCMXCIII
X-HTTP: http://purl.oclc.org/NET/Abigail
X-Revision: $Revision: 1.2 $
X-PGP-Fingerprint: 76 2E 82 7A 69 93 5F 97  AE 01 80 75 67 F3 45 D0
User-Agent: slrn/0.9.6.2 (Linux)
Xref: nntp.stanford.edu comp.lang.perl.misc:324236

Reini Urban (rurban@sbox.tu-graz.ac.at) wrote on MMDIII September
MCMXCIII in <URL:news:3967456e.12650700@news>:
~~ Abigail wrote:
~~ >$| ++ is obscure and bad. $| = 1 makes it instantly clear what the
~~ >effects are.
~~ 
~~ joking? both are obscure and bad.
~~ 
~~ use English;
~~ use constant BUFFERED   => 1;
~~ use constant UNBUFFERED => 0;
~~ 
~~ $OUTPUT_AUTOFLUSH = BUFFERED; # this is readable.
~~ $| = 1;                       # this is unreadable.


$OUTPUT_AUTOFLUSH = BUFFERED; is extremely obscure as it will turn
buffering *OFF*.

Furthermore, the English forms of punctuation characters are
indistinguishable from userland characters. There's nothing that gives
away that they are special, while punctuation variables look special. And
it's a hell of a lot easier not to use punctuation variables as user
variables than to not use variables that consists of characters.


Abigail
-- 
perl -we '$_ = q ;4a75737420616e6f74686572205065726c204861636b65720as;;
          for (s;s;s;s;s;s;s;s;s;s;s;s)
              {s;(..)s?;qq qprint chr 0x$1 and \161 ssq;excess;}'

Path: nntp.stanford.edu!newsfeed.stanford.edu!newsfeedZ.netscum.dQ!netscum.int!newsfeeds.belnet.be!news.belnet.be!nmaster.kpnqwest.net!newsfeed.Austria.EU.net!newsfeed.wu-wien.ac.at!aconews.univie.ac.at!news.tu-graz.ac.at!not-for-mail
From: rurban@sbox.tu-graz.ac.at (Reini Urban)
Newsgroups: comp.lang.perl.misc
Subject: Re: Why $|++ instead of $|=1 ?
Date: Sun, 09 Jul 2000 14:02:34 GMT
Organization: x-ray & xarch
Lines: 26
Message-ID: <396884c8.94404566@news>
References: <8k0m4d$13o$1@panix3.panix.com> <slrn8m7s9q.ibb.abigail@alexandra.delanet.com> <3967456e.12650700@news> <slrn8meofv.rbj.abigail@alexandra.delanet.com>
Reply-To: rurban@sbox.tu-graz.ac.at
NNTP-Posting-Host: 129.27.209.123
X-Trace: fstgss02.tu-graz.ac.at 963151308 21251 129.27.209.123 (9 Jul 2000 14:01:48 GMT)
X-Complaints-To: news@zid.tu-graz.ac.at
NNTP-Posting-Date: 9 Jul 2000 14:01:48 GMT
X-Newsreader: Forte Free Agent 1.11/32.235
Xref: nntp.stanford.edu comp.lang.perl.misc:324374

Reini:
>> use constant BUFFERED   => 1;
>> use constant UNBUFFERED => 0;

Abigail:
>$OUTPUT_AUTOFLUSH = BUFFERED; is extremely obscure as it will turn
>buffering *OFF*.

oops! but the fix would in the header only. 
the sources will stay readable in contrast to various obscurity
principles discussed before.

use constant BUFFERED   => 0;
use constant UNBUFFERED => 1;

>Furthermore, the English forms of punctuation characters are
>indistinguishable from userland characters. There's nothing that gives
>away that they are special, while punctuation variables look special. And
>it's a hell of a lot easier not to use punctuation variables as user
>variables than to not use variables that consists of characters.

agreed. to hell with use constant.
one uses it only with XS modules with "badly designed" API's anyway.
(say "OS-near").
--                                         
Reini

Path: nntp.stanford.edu!newsfeed.stanford.edu!bloom-beacon.mit.edu!news-out.cwix.com!newsfeed.cwix.com!newsfeed.icl.net!newsfeed00.sul.t-online.de!t-online.de!diablo.theplanet.net!news.vas-net.net!server2.netnews.ja.net!pegasus.csx.cam.ac.uk!mjtg
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Newsgroups: comp.lang.perl.misc
Subject: Re: Why $|++ instead of $|=1 ?
Date: 13 Jul 2000 15:18:26 GMT
Organization: University of Cambridge, England
Lines: 17
Message-ID: <8kkmk2$bfh$1@pegasus.csx.cam.ac.uk>
References: <8k0m4d$13o$1@panix3.panix.com> <slrn8m7qfq.8d6.tjla@thislove.dyndns.org> <slrn8m7uag.ibb.abigail@alexandra.delanet.com>
NNTP-Posting-Host: libra.cus.cam.ac.uk
Xref: nntp.stanford.edu comp.lang.perl.misc:325641

Abigail <abigail@delanet.com> wrote:
>
>That's what local is for.  Your subs will fail to do the right thing
>if $| happens to be -1. Or imagine that some_sub has a fatal error in
>it, which is caught by an eval{}. Your entire $| ++ and $| -- will be
>hosed.

Nope.    $| is magical, and can only ever take values 0 or 1.    Which
means the subroutine is nonsense for other reasons.

And that also shows that $|++ is exactly the same as $|=1, so entirely
respectable if a little eccentric.

But $|-- is a very different kettle of fish.


Mike Guy

Path: nntp.stanford.edu!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!feeder.via.net!enews.sgi.com!news.xtra.co.nz!tjla
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Newsgroups: comp.lang.perl.misc
Subject: Re: Why $|++ instead of $|=1 ?
References: <8k0m4d$13o$1@panix3.panix.com> <slrn8m7qfq.8d6.tjla@thislove.dyndns.org> <fbS85.9$E27.2912@vic.nntp.telstra.net> <8kknbg$c2e$1@pegasus.csx.cam.ac.uk>
Organization: World Center for Flux Capacitor Research
Message-ID: <slrn8mssqj.19b.tjla@thislove.dyndns.org>
User-Agent: slrn/0.9.6.2 (Linux)
Lines: 30
Date: Fri, 14 Jul 2000 01:53:39 GMT
NNTP-Posting-Host: 210.55.47.4
X-Complaints-To: newsadmin@xtra.co.nz
X-Trace: news.xtra.co.nz 963539619 210.55.47.4 (Fri, 14 Jul 2000 13:53:39 NZST)
NNTP-Posting-Date: Fri, 14 Jul 2000 13:53:39 NZST
Xref: nntp.stanford.edu comp.lang.perl.misc:325852

I was shocked! How could M.J.T. Guy <mjtg@cus.cam.ac.uk>
say such a terrible thing:
>Wyzelli <wyzelli@yahoo.com> wrote:
>>
>>As I have demonstrated previously, whilst calling $|++ repeatedly leaves
>>the state of $| 'high' (or 'unbuffered' if you wish, since any non zero
>>value = unbuffered), calling $|-- repeatedly can in certain
>>circumstances cause $| to switch between a zero and non-zero value which
>>can lead to misleading results.
>
>It's not "in certain circumstances"  -  it's in *all* circumstances.
>
>$| is magical and can only take values 0 or 1.    An attempt to set
>any nonzero value sets it to 1.

perl -we '$| = 0; $|--;$|++; print "\$| == $|";'
$| == 1

Ergo. using $|-- and $|++ is not safe as the fact that $| is magic means
that doing these things in equal (ie. balanced) numbers does not get you
back to where you started. This is a bad thing I think. You should
always use 'local'.

-- 
Gwyn Judd (tjla@guvfybir.qlaqaf.bet)
My return address is rot13'ed
Schlattwhapper, n.:
	The window shade that allows itself to be pulled down,
hesitates for a second, then snaps up in your face.
		-- Rich Hall, "Sniglets"


the rest of The Pile (a partial mailing list archive)

doom@kzsu.stanford.edu