int foo(type& bar); is a bad practice?

Posted by Earlz on Stack Overflow See other posts from Stack Overflow or by Earlz
Published on 2010-04-14T16:32:30Z Indexed on 2010/04/14 16:43 UTC
Read the original article Hit count: 126

Filed under:
|
|
|

Well, here we are. Yet another proposed practice that my C++ book has an opinion on. It says "a returning-value(non-void) function should not take reference types as a parameter." So basically if you were to implement a function like this:

int read_file(int& into){ ... }

and used the integer return value as some sort of error indicator (ignoring the fact that we have exceptions) then that function would be poorly written and it should actually be like

void read_file(int& into, int& error){

}

Now to me, the first one is much clearer and nice to use. If you want to ignore the error value, you do so with ease. But this book suggests the later. Note that this book does not say returning value functions are bad. It rather says that you should either only return a value or you should only use references.

What are your thoughts on this? Is my book full of crap? (again)

© Stack Overflow or respective owner

Related posts about best-practices

Related posts about c++