| |||||||||||
| |||||||||||
Wimbledon Neck
What use is the "+=" operator? Why did the language designers bother to provide it? Yet they did ...
In Perl and PHP $number_on_bus = $number_on_bus + $goton_here; becomes $number_on_bus += $goton_here; In Python number_on_bus = number_on_bus + goton_here becomes number_on_bus += goton_here In C and Java number_on_bus = number_on_bus + goton_here; becomes number_on_bus += goton_here; The += operator adds the result of evaluating the expression to the right into the variable named on the left. The code is shorter, but there's more too it than that. It makes the code easier to maintain - it saves what we call "Wimbledon Neck" which is very appropriate for me to be writing about this week as the tennis championships are just about to start. If I write $longvariablename = $longthingummyname + $some; then anyone coming along to maintain the code has to take a careful look on both sides of the assignment to see whether or not the information is being saved in the same slot from which it was loaded or not; can you visualise the maintainer turning his neck to the left, to the right, to the left, to the right rather like watching a tennis volley from the side line? If the element being used is a member of an array (= list in Perl) or hash (= dictionary, = associative array) then that's all the more checking to do. So - it may not come natural to you to code += (or -= *= /= etc) but please do so ... you're making life easier for those who follow behind! (written 2005-06-20 08:58:36) Associated topics are indexed under P204 - Perl - Conditionals and LoopsH104 - PHP - Control Statements Y103 - Python - Conditionals and Loops C203 - C and C based languages - Conditionals and Loops J704 - Java - Loops and Conditional Statements
Some other Articles
Where do Perl modules load fromSudoku helper or sudoku cheat Context in Perl Ballooning from Bath Wimbledon Neck Improved mining techniques! Is photoajustment an addiction? Want to be one better Comments in Tcl Graveyard pages 1638 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33 at 50 posts per pageThis is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price. Link to Ezine home page (for reading). Link to Blogging home page (to add comments). |
| ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 707126 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho | |||||||||||