in reply to In Love With Double Quotes

You are wrong. Complete, and utterly wrong. It's better to use "This hot Perlistic string" then 'This hot Perlistic string'.

Your argument that perl needs to do more work is a non-argument. If that difference is important to you you ought to be programming in C directly, as using perl makes C do more work than when you programmed in C directly.

But for engineering reasons, it's better to use double quotes in a string that doesn't contain dollar (or at) signs or backslashes. The only case where the kind of quotes you use matters is if you need to change them. When would you need to change the quotes of "This hot Perlistic string" to single quotes? When you change it to something like 'This hot Perlistic string costs $100' - although you could still write "This hot Perlistic string costs \$100". But when would you need to change 'This hot Perlistic string'? For instance, if you change it into "This hot Perlistic string\n", or "This hot Perlistic $noun". And then there isn't a single keystroke alternative available that leaves in the single quotes. The latter kind changes are far more common than the former kind. Hence, it's better to use double quotes than single quotes - programmer time is more important than CPU time. (If CPU time was more important, you should have written it in C anyway). Oh, and anyone complaining he gets confused when seeing a double quoted string that doesn't have a variable inside it ought to be fired.

Replies are listed 'Best First'.
Re^2: In Love With Double Quotes
by Tanktalus (Canon) on Aug 08, 2005 at 16:19 UTC

    For engineering reasons, I use single-quotes when I mean to use a literal, and double-quotes when I mean to interpolate. It's just a matter of doing what you're saying, and saying what you're doing.

    If I want to use a string constant, I use single quotes. No ambiguity. No mental gymnastics trying to figure out what '@$_$@#!!' means. It's a curse. Ok, so that doesn't come up too often. However, other interpolations, such as 'someone@somewhere.com', are quite frequent.

    If I want to interpolate strings, I use double quotes. No ambiguity. It's just a simple acknowledgement that I know what I'm doing, and what I'm doing is interpolation.

    People who mindlessly use only a single tool probably don't know there are other tools out there, and, moreover, probably don't really know their own tool properly. If you insisted on using double-quotes everywhere in your code while you worked for me, and in the style you present above, I'd have your attitude for supper. It's simply not conducive to either the workplace or perlmonks.

      Of course, one use double quotes when you want to interpolate, and single quotes when you don't. No question about that. The topic however is the large set of strings where "are we interpolating or not" isn't a sensible question. Are you interpolating in "Hello, world"? Perhaps you are, it just happens the set of variables you are interpolating happen to be zero. For me, double quotes also mean "I'm interpolating". But often, I interpolate zero variables.