Re: [Plib-devel] C++ Philosophy Question
Brought to you by:
sjbaker
From: Steve B. <sjb...@ai...> - 2000-03-22 05:12:55
|
Bill Weiland wrote: > references are more precise/less error prone than pointers > when e.g. a function arg. or member cannot/should not be > NULL (and cannot/should not be changed dynamically)... The thing I *really* dislike about ref parameters is that it's possible to see this in the header for a library somewhere: void some_funtion ( int x ) ; ...you go and write code to use 'some_function' *knowing* for sure that: x = 6 ; some_function ( x ) ; *CANNOT* change the value of 'x'. What's nasty about 'ref' arguments is that some subsequent version of that library can change the parameter of 'some_function' to be 'ref' and then change the value of x inside the function without the author of the application code being aware that the libraries' policy has changed. The old call to some_function still compiles! Eeeekkkkk! Also, I like to be able to look at some complex code that uses 'some_function' and *know* that the parameter isn't altered by the the function just by looking at the call. I don't even have to go off and read the manual for 'some_function' in order to know that. The nice thing about good old fashioned C-style pointers is that when you see: x = 6 ; some_function ( & x ) ; ...that '&' shouts loudly to you to bear in mind that x may well have been changed by the call. If you don't see an '&' then you don't need to know much about some_function in order to see that it doesn't change 'x'. That makes code MUCH more readable. I think 'ref' is *EVIL* because its syntax doesn't make it obvious. > Anyway, that's it for religion, time to write some code. Indeed. -- Steve Baker http://web2.airmail.net/sjbaker1 sjb...@ai... (home) http://www.woodsoup.org/~sbaker sj...@ht... (work) |