[CSI] Parameter Names in Similar Functions
Mikhail Nesterenko
mikhail at cs.kent.edu
Sun Oct 2 23:53:55 EDT 2016
>
> Would it be poor style to reuse identifiers for parameters if the function
> of the parameter is identical across each function where the identifier
> appears?
>
> This is evident in both parts of the week five labs where several of the
> functions would take identical arguments (the measurements for BMR or the
> size for the figures).
>
> To me it would seem to be confusing to have to constantly generate synonyms
> for the parameters to remain meaningfully named and the idiom of using the
> identifier "i" in For loops would seem to suggest that this is at least
> acceptable occasionally.
When we deal with style, it is often recommendations rather than
hard-and-fast rules.
I am somewhat against naming arguments and matching parameters the
same. However, naming parameters in different functions the same seems
acceptable. Remember in functions lab, we had a number of functions
drawing different figures and accepting figure size as a parameter?
Naming them all
size or figureSize
would be acceptable.
Now, the variable name is inversely proportional to its scope. If a
loop only takes up a few lines, then naming the loop variable "i",
"j", or "k" is appropriate. However, if it takes up a page, then I
would recommend giving the loop variable a meaningful name.
Thanks,
--
Mikhail
More information about the cs13001
mailing list