in reply to In Love With Double Quotes

But, this post brings one more thing to the table, a suggestion that a string concatenated with a variable is more legible than a variable interpolated in a double string. Which I don't believe. I would also be willing to cite a strong statistic from the Association of Made up Statistics, which was funded by the Organization of Statistics Pulled Out of My Ass it says, "In 100% of the cases studied explicit concatenation turned out to be a very bad idea."


Evan Carroll
www.EvanCarroll.com

Replies are listed 'Best First'.
Re^2: In Love With Double Quotes
by Koolstylez (Scribe) on Aug 10, 2005 at 18:01 UTC
    If you don't interpolate variables, you must end up with some pretty messy code.

    Instead of
    print "On $todays_date you have received $num_emails emails from $num_ +people people in mailbox $mailbox\n";
    you would prefer this?
    print 'On ' . $todays_date . ' you have received ' . $num_emails . ' e +mails from ' . $num_people . ' people in mailbox ' . $mailbox . '\n';
    IMHO, the former is quite a bit easier on the eyes.
      I agree. I am the only person I know of who has gone on record has having intentionally tried both types as my default quoting style (A guide to coding Perl). I vote for double-quotes in the common case; when you consider that interpolation was designed to be convenient it is not surprising that it is.

      There have been many arguments in favor of using single-quotes as a marker that no interpolation is going to happen. This implies that double-quotes denote that interpolation is going to happen. I find this a subtle sort of commenting and would not count on any one's self discipline to be consistent at it unless I knew there was an effective system to enforce it. The idea shows an attention to detail that I can respect but I find the convention uninteresting and uninspiring. Usually strings are just not that interesting from a programmer's perspective. Often I may start a string without much thought as to what all will be in it when its contents are finalized.

      There are situations where quoting styles are worth attention. When generating templating text or code that has lots of special characters; in such cases it is worth avoiding " and ' and using the other quoting methods.

      Be well,
      rir