Message-ID: <6C93669D-6B58-45B6-86DC-2A77984C7CC3@stat.ubc.ca>
Date: 2011-01-24T19:15:29Z
From: Davor Cubranic
Subject: "+" operator on characters revisited
In-Reply-To: <AANLkTikZ8M38vX1eGs76EK-FwMoOFJBuJHbF2_Jdj0St@mail.gmail.com>
On 2011-01-23, at 4:34 AM, Gabor Grothendieck wrote:
> On Sun, Jan 23, 2011 at 6:56 AM, Vitalie S. <spinuvit.list at gmail.com> wrote:
>> Gabor Grothendieck <ggrothendieck at gmail.com> writes:
>>
>>> Also the gsubfn supports quasi perl style string interpolation that
>>> can sometimes be used to avoid the use of paste in the first place.
>>> Just preface the function in question by fn$ like this:
>>>
>>> library(gsubfn)
>>> fn$cat("pi = $pi\n")
>>
>> Thanks for the tip. Not bad indeed.
>> Almost as readable as
>>
>> cat("pi = " + pi + "\n")
>
> To me the + can be substantially less readable. The need to
> repeatedly quote everything makes it just as bad as paste. Compare
> the following and try to figure out if there is an error in quoting in
> the + and paste solutions. Trying to distinguish the single and
> double quotes is pretty difficult but simple in the fn$ and sprintf
> solutions. Even if there were no quotes the constant need to
> interpose quotes makes it hard to read.
That may be a matter of taste, but FWIW it seems that shell-style string interpolation (using the dollar prefix) has going out of style in recent scripting languages. Ruby uses the expression substitution construct ("#{expr}"), while Python has "str.format", both allowing arbitrary expressions.
And most editors have syntax highlighting that distinguishes strings from other program elements. This makes quoting errors pretty obvious.
Davor