in reply to Optional quotes: to use or not to

Whereas my own viewpoint would be quite definite:   “never use barewords!”

A bareword is a string literal that doesn’t look like one.   I believe very strongly that everything in the source-code of a computer program should look, to a human being, like what it actually is to the compiler.   If that means typing two extra characters and pressing the Shift key twice, c’est la guerre.   We aren’t putting source code on paper tape anymore.

Now, let me tell you why.   Remember, from my Meditations thread, that “I see dead projects.”   The software was abandoned by a programmer or team that did very sloppy, unsupervised work, e.g. before their visa-time ran out.   In one such case, many days were spent looking for what turned out to be ... “an omitted dollar-sign.”   foo instead of $foo, buried deeply in a mountain of shit source code.   A bareword, meant to be a variable-reference, but acceptable to the Perl compiler.

Unlike most other languages today (JavaScript being the most notable and therefore most egregious exception), Perl is very permissive.   It likes to assume that you meant exactly what you say, that you never make a tpyographic error, never use the wring word, put never words in the order wrong.   That source is meant to be taken at face-value exactly as writ, if possible.   The defense against this is coding-standards, and to me this is an important one.

Replies are listed 'Best First'.
Re^2: Optional quotes: to use or not to
by 1nickt (Canon) on Jul 10, 2015 at 12:42 UTC

    foo instead of $foo, buried deeply in a mountain of shit source code. A bareword, meant to be a variable-reference, but acceptable to the Perl compiler.

    How would "the Perl compiler" accept 'foo' as a bareword if you were using strict and/or warnings? Couldn't you find the problem immediately if you turned those on?

    #! perl # 1134136.pl use strict; my ($bottom, $top); my @mountain = ($bottom, $top, foo); exit;
    [05:38][nick:~/monks]$ perl 1134136.pl Bareword "foo" not allowed while "strict subs" in use at 1134136.pl li +ne 4. Execution of 1134136.pl aborted due to compilation errors.
    #! perl # 1134136-2.pl use warnings; my ($bottom, $top); my @mountain = ($bottom, $top, foo); exit;
    [05:41][nick:~/monks]$ perl 1134136-2.pl Unquoted string "foo" may clash with future reserved word at 1134136-2 +.pl line 5.
    Remember: Ne dederis in spiritu molere illegitimi!

      Strict wouldn't catch this would it:

      my %h; $h{foo} = 82;
Re^2: Optional quotes: to use or not to
by hurricup (Pilgrim) on Jul 10, 2015 at 12:35 UTC

    Do you mean quotes by "look" or kind of highlighting?