Introducing Steven Wilssens#

My colleague Steven Wilssens is one of the most knowledgeable people I know personally (on .NET related topics anyway ;-) ), and he's just started blogging! So be sure to keep an eye on his blog for some solid information about all things .NET, Indigo (WCF), Software Configuration Management, Team System and lots more!

On a job interview we were conducting together a few weeks ago, the applicant couldn't really explain the difference between passing arguments "by value" and "by reference", so Steven just used the can of soda in front of him as an analogy: if I pass the can by value to you and you drink from it, I'll notice it afterwards and get mad at you for stealing my drink (assuming the can is a reference type, like an ICollection of soda molecules if you will). If I pass it to you by reference, you can drink as much as you want - you can replace the entire can altogether so I won't notice :-)

So that's the kinda guy he is, check him out!

Sunday, August 21, 2005 7:55:59 PM (Romance Standard Time, UTC+01:00)
Huh? It's the other way around. When you pass the drink by value he gets a copy of the drink and you won't notice a thing since he's drinking the copy and you still have your original. However if you pass the drink by reference, he's drinking from your drink through a reference and you'll end up with nothing.
doens't matter
Sunday, August 21, 2005 9:09:16 PM (Romance Standard Time, UTC+01:00)
No I'm sorry, it's correct. Think again :-) And don't forget the hint that the soda can is a reference type - not a value type!
Wednesday, August 24, 2005 7:03:13 AM (Romance Standard Time, UTC+01:00)
Indeed the analogy is correct, but perhaps the guy/girl from the first comment is used to Java... And actually in Java everything is passed on by value. Many people forget that. A reference is always copied, and of course you can modify the contents of the object reference (assuming it's mutable, so String would be a bad example), but changing the reference would only have a result in the scope of that method. Outside the called method, the original reference is still pointing to the original object.

Sometimes I wonder whether it would be nicer to have the ability in Java to allow passing by reference. On the other hand, perhaps it's better not to have it, it would only make things more difficult for some people ;-)
Comments are closed.
All content © 2012, Jelle Druyts
On this page

Recent Photos
www.flickr.com
This is a Flickr badge showing public photos from Jelle Druyts. Make your own badge here.
Advertising
Top Picks
Statistics
Total Posts: 350
This Year: 0
This Month: 0
This Week: 0
Comments: 530
Archives
Sitemap
Disclaimer
This is my personal website, not my boss', not my mother's, and certainly not the pope's. My personal opinions may be irrelevant, inaccurate, boring or even plain wrong, I'm sorry if that makes you feel uncomfortable. But then again, you don't have to read them, I just hope you'll find something interesting here now and then. I'll certainly do my best. But if you don't like it, go read the pope's blog. I'm sure it's fascinating.

Powered by:
newtelligence dasBlog 2.0.7226.0

Sign In