Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

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

by ww (Archbishop)
on Jan 19, 2017 at 20:32 UTC ( [id://1179939]=note: print w/replies, xml ) Need Help??


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

You wrote: "You should not be forced to used the more verbose form of the variable name."

Just in case there's a misunderstanding here, NOTHING in PBP is mandatory. Some of the recommendations do, in fact, reflect a concensus among some Perl programmers. Others are held up to criticism as 'one author's preferences.'

And here's another 'one person's opinion' about your observation that it "should it be entirely up to the user to ensure that he used the correct sigil."
Frankly, that idea is anathema to me; IMO, it's just another way to write code that you will have trouble deciphering sometime down the road, and that some future maintainer will almost certainly find problematic.

Replies are listed 'Best First'.
Re^2: Improve readability of Perl code. Naming reference variables.
by hakonhagland (Scribe) on Jan 20, 2017 at 08:51 UTC
    Yeah, I agree that the suggested reference syntax also could introduce new issues. For example consider function calls:
    func( $var->@ )
    Here it is of course possible that the programmer introduces a typo. First, assume he wrote @ when $var is a scalar (i.e. $var is not a reference). This typo will of course confuse a human reader. But the compiler would probably be quite happy. It would just ignore the optional postfix syntax (OPRDS). Hence, there will be no runtime issues with this typo either. Then consider a different typo. The user types @* when he rather meant to type @:
    func( $var->@* )
    Now, this is a more serious mistake. The compiler will assume that the array reference should be dereferenced. Hence, the function will receive $var->[0] instead of the reference $var, likely to cause some sort of runtime malfunction that may be difficult to debug.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2024-04-19 10:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found