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

Re: Improve readability of Perl code. Naming reference variables.

by johngg (Canon)
on Jan 20, 2017 at 10:45 UTC ( [id://1179987]=note: print w/replies, xml ) Need Help??


in reply to Improve readability of Perl code. Naming reference variables.

As someone who prefers camelCase I use a more succinct convention.

my $rsSomeValue = \ do { my $val = 42 }; # scalar ref my $raCats = [ qw{ Tiddles Desmo Felix } ] # array ref my $rhAges = { John => 23, Bill => 35 }; # hash ref my $rcDoIt = sub { return $_[ 0 ] * 3 }; # code ref my $rxPat = qr{abc}; # regexp ref my $roObj = Some::Pkg->new() # object ref

If I see something matching m{\$r[sahcxo][A-Z]} I know I'm dealing with a reference.

Cheers,

JohnGG

Replies are listed 'Best First'.
Re^2: Improve readability of Perl code. Naming reference variables.
by hakonhagland (Scribe) on Jan 21, 2017 at 08:49 UTC

    Hello johngg.

    Yes, it is shorter, but is it more readable? This also extends to the discussion of whether to use snake_case or camelCase. In my opinion camelCase is more succint (easier to type), whereas snake_case is more readable (but more difficult to type).

    I also once used camelCase, so I can understand your choice. My main objection though is that the prefix syntax (that you propose) is not optional. See also comment to kcott for more information.

Re^2: Improve readability of Perl code. Naming reference variables.
by nysus (Parson) on Feb 08, 2017 at 23:11 UTC
    Camel case makes my skin crawl. Hate it. Give me underscores or give me death.

    $PM = "Perl Monk's";
    $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate";
    $nysus = $PM . ' ' . $MCF;
    Click here if you love Perl Monks

      I guess it's all a bit subjective. I don't dislike underscores and can happily use them if mandated but camelCase keeps long descriptive variable names shorter which is why I prefer it.

      Cheers,

      JohnGG

        It's totally subjective. Whether warranted or not, camel case reminds me of Microsoft code. Underscores remind me of old school programming. I also think camel case is harder to read. Though camel case does take fewer keystrokes to execute. I'll give you that.

        $PM = "Perl Monk's";
        $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate";
        $nysus = $PM . ' ' . $MCF;
        Click here if you love Perl Monks

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2024-04-18 21:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found