[cs13001] Coding Question

Mikhail Nesterenko mikhail at cs.kent.edu
Fri Mar 1 14:31:21 EST 2013


> Dr.Nesterenko,
> 
> What is considered better style?
> 
> Passing variables by reference in void functions
> 
> Or
> 
> Returning variables with a return in a function
> 

There is no hard and fast rule. 

If a function computes a sigle value then it is better to make it a
return value. Note that if this value is a long string or other
large-size aggregate constract then may be, for efficiency reasons, it
is better to pass the value as a call-by-reference parameter.

A good reason to have a function return a value is that you can use
this function in an expression.  This makes the code terse and easier
to read.

If a function needs to update multiple values, then it is probaby
clearer to make this a void function and pass the parameters by
reference.

Thanks,
--
Mikhail


More information about the cs13001 mailing list