[32945] in Perl-Users-Digest
Perl-Users Digest, Issue: 4221 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri May 23 14:09:14 2014
Date: Fri, 23 May 2014 11:09:02 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 23 May 2014 Volume: 11 Number: 4221
Today's topics:
Re: Help with an operator precedence (?) puzzle <derykus@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 22 May 2014 16:43:19 -0700
From: Charles DeRykus <derykus@gmail.com>
Subject: Re: Help with an operator precedence (?) puzzle
Message-Id: <llm22v$tvj$1@speranza.aioe.org>
On 5/20/2014 4:24 AM, G.B. wrote:
> On 19.05.14 23:33, Peter J. Holzer wrote:
>
>>>> $frog = 'green', return if blort();
>>>>
>>>> seems like a pretty natural choice.
>>>
>>> The choice seems to match the nature, and possibly the interest,
>>> of a competent Perl consultant, since interpreting it correctly
>>> requires substantial knowledge of Perl,
>>
>> It requires knowledge of the comma operator and statement modifiers. I
>> consider both "basic Perl".
>
> Comma is "basic", but not simple, as demonstrated by this thread.
> The problem, however, *is* simple!
>
> ("IF bla-bla THEN <assign>; <return>; FI")
>
> In the presence of TIMTOWTDI, a programmer is free to prefer more
> or less obscure modes of statement, or reject them. Because they
> seem boring, or because they take more than 1 line of code,
> or because the programmer likes clever modes of statement, or
> because a short statement clearly and briefly conveys the intent
> ---if it does, assuming the author knows the "audience".
>
>> In addition, the comma operator is present
>> in C and many languages derived from it (not in Java, though).
>
> The presence of some comma operator in similar or related languages
> makes discerning the comma even more tricky, in particular if you
> frequently need to switch languages (Perl, C, sh, Python). A slight
> change of meaning only adds pitfalls.
> Unless, maybe, both the programmer and readers of the program are
> in that luxurious position of using just one language.
>
> Thus this comma requires thinking (obviously), a valuable resource
> that could be spent on solving the "real" problem.
>
>
>> Also, how do the alternatives
>>
>> $frog = 'green' and return if blort();
>> do { $frog = 'green' } and return if blort();
>>
>> require less "substantial knowledge of Perl"? How are they "more
>> natural" to a non-Perl programmer?
>
> These, too, require substantial knowledge of Perl.
> They, too, mix several aspects of: conditionality, precedence
> (associativity), absence of presence of punctuation, ... all on 1 line.
>
> Don't write English when programming! ;)
>
I'd often agree that TIMTOWTDI can be abused but the lack of it can
be just as oppressive. As mentioned earlier, these examples are "basic
perl".
You can cater to someone with a shell/Java/X mindset but then you lose
Perl's native expressiveness and idioms. A more idiomatic approach
and/or TIMTOWTDI can often hasten a solution and be clearer code.
Simplicity trumps complexity and most would agree "if...else" or
a comma op would be preferable to some hack to avoid a compiler
warning. However, what if someone argues a basic, unambiguous
and very English-looking variant:
"blort() and $frog="green" and return;
is more expressive and avoids a debilitating case of "whitespace
blindness". Most who still have their eyesight would agree it's a
terrible, headache-inducing condition that makes a language
unreadable...any language.
--
Charles DeRykus
lack of it.
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 4221
***************************************