Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Optimizing Perl Code - single versus double quotes really that important?

by rir (Vicar)
on Feb 05, 2009 at 18:38 UTC ( [id://741639]=note: print w/replies, xml ) Need Help??


in reply to Optimizing Perl Code - single versus double quotes really that important?

No, this is a compile time thing and buys you nearly nothing performance-wise.

The relatively recent arguments for using single-quotes on strings which have no interpolation is motivated by an intent to inform a reader whether a string literal is interpolated or not.

In my coding, I made an extended trial of using single-quotes on all uninterpolated strings. I found the practice unproductive both as a maintainer and as an author. As a maintainer, most of my strings are not so long as to be problematic. As an author, I found double-quotes to be more flexible--too often the final interpolative nature of the string was unknown when the quotes were opened.

It might seem that there would be more benefit to this practice when using very long strings. I did not find this to be the case; with long string literals it is work to determine if you are looking a one literal or a list or concatenation of literals.

I'm sure experience and personal taste vary, but I find literals which are more than a line to be most easily readable in this form:

my $usage = "This is just a literal string concat'd up; " . "it keeps significant\n" . "whitespace and interpolations in normal or " . $visible . "places. Double-quotes seem most convenient " . "just to contain simple things like newlines " . "and tabs.\n" . "But the important thing is that the dots " . "make it easy to see that each line starts\n" . "a new token\n";
I use and like syntax highlighting, but haven't made it a prerequisite to reading code as it is not always conveniently available. I find highlighting helpful when writing to catch unterminated literals, but I tend to ignore highlighting when just reading code.

For what it is worth, my experiment was motivated by the thought that my use of double-quotes was just a habit carried over from C.

Be well,
rir

  • Comment on Re: Optimizing Perl Code - single versus double quotes really that important?
  • Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://741639]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2024-04-24 23:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found