Link Details

Link 138043 thumbnail
User 237690 avatar

By baron314159
via lolcodrz.com
Published: Dec 02 2008 / 14:48

Passing arguments by reference won't improve performance. Plus, it makes code harder to understand. Please don't do it!
  • 10
  • 5
  • 1530
  • 514

Comments

Add your comment
User 235780 avatar

legendxx replied ago:

3 votes Vote down Vote up Reply

As one of the commenters noted, if the passed argument is altered in any way, the difference in memory usage is dramatic.

Matt [comment from article]:
You’ve missed something key here - if the argument IS altered in the function, there IS a difference in memory usage. I assume you’ve glossed over this to make your point stronger.

Like all blanket rules, this one is incorrect. In most cases, you don’t need to pass by reference, and it can cause hidden bugs. However, that does not mean that you should NEVER pass by reference, as there are a number of situations where it’s completely appropriate to do so, and may be the cleanest way of writing the code.

User 338269 avatar

OtengiM replied ago:

-4 votes [show comment] Vote down Vote up Reply

Add your comment


Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.