Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!charyb!dan From: dan@kfw.COM (Dan Mick) Newsgroups: comp.lang.c++ Subject: Naive style question Message-ID: <1991Jun29.023254.25184@kfw.COM> Date: 29 Jun 91 02:32:54 GMT Reply-To: dan@kfw.com (Dan Mick) Organization: KFW Corporation, Newbury Park, CA Lines: 35 I'm just starting with C++, and I'm pondering the issue of reference types. For example, the oft-quoted example of void swap(int& i, int& j) { int tmp; tmp = i; i = j; j = tmp; } Obviously, you'd use this with "swap(i,j);" as opposed to the C version with pointers, which has to appear "swap(&i, &j);". My problem with this is that, as a maintenance programmer, you have to know all about swap()s signature before you can know that swap(i,j) does or doesn't change its parameters in the caller's scope, whereas with the pointer version as in C, you *know* the caller's variables can't be changed by the function unless their address is passed. It seems to me that the confidence inherent in pass-by-value is a big part of maintaining C code; in fact, it's one of the real advantages, to me, over languages that support pass-by-reference, especially those that support pass- by-reference with syntax *in the callee*. What do you all think? Are reference types more of a hassle than they're worth? Does this mean that it's insane to think about programming in C++ unless you've got a *great* tags/class-browser system? (Of course, this also opens the can of worms about overloaded functions and operators...can you ever know what "+" means again?...but let's leave that particular issue for another time...)