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.
Comments
legendxx replied ago:
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.
OtengiM replied ago:
Voters For This Link (10)
Voters Against This Link (5)