Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

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

by kennethk (Monsignor)
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 musing on the Monastery: (9)
As of 2014-09-30 18:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (380 votes), past polls