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

Re: $var{el} += 1 vs $var{el} = $var{el} + 1

by kennethk (Abbot)
on Aug 13, 2013 at 14:25 UTC ( #1049285=note: print w/ replies, xml ) Need Help??


in reply to $var{el} += 1 vs $var{el} = $var{el} + 1

Any response you'll get here is 'IMHO', so the important thing is really readability for you, both today and in a year when you have to maintain this code.

From my perspective, using a compound assignment operator improves the legibility dramatically. With the large number of hash keys present, it'd be very easy to get confused whether the keys are all the same. += makes your intent much more obvious. It also protects you from potential typos.

Make sure in migrating this code that you are actually reading the code properly. It be a real shame to put time and energy into improving the readability and break the code in the process.


#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.


Comment on Re: $var{el} += 1 vs $var{el} = $var{el} + 1
Download Code
Re^2: $var{el} += 1 vs $var{el} = $var{el} + 1
by banesong (Acolyte) on Aug 13, 2013 at 14:38 UTC

    I actually just fixed a couple of problems where the hash got deeper on the left, and not on the right (e.g. extra level was added).

    I think that we will be changing the sub to use a more sanely readable format with +=.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2015-07-03 00:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (47 votes), past polls