c# - Is it good practice to use the same Variable names for both method call and method signature parameters? -



c# - Is it good practice to use the same Variable names for both method call and method signature parameters? -

for example:

int a; int b; int value = getvalue(a,b); private int getvalue(int a, int b) { int value = a+b; homecoming value; }

is above practical or considered bad practice , cause problem later in development.

i realize it's contrived illustration demonstrate you're asking, illustration does contain naming problem i'll point out:

int a; // <---- right here int b; // <---- , here int value = getvalue(a,b); // <--- , little here private int getvalue(int a, int b) { int value = a+b; homecoming value; }

the problem isn't in whether or not variable names match or don't match they're called in method. problem variable names aren't called meaningful. considerably more of issue you're asking.

let's re-factor method create illustration less contrived...

int a; int b; int value = getsum(a,b); private int getsum(int firstvalue, int secondvalue) { homecoming firstvalue + secondvalue; }

the method bit cleaner , more intuitively reflects purpose. re-ask question... should a , b renamed match ones in method?

most not. names in method have been changed indicate context. method getting sum of 2 values, first 1 , sec one. context of a , b? known first 1 , sec one? or convey other meaning that's not readily available? like:

int milestofirstdestination; int milestoseconddestination;

or:

int heightofpersonininches; int heightofstepstoolininches;

or other illustration of 2 values need summed purpose. if added context variable names wouldn't want add together method. method should general-purpose possible, performing single task without concern outside of task.

in short, it's neither nor bad practice, because it's not consider. there may times where, coincidence alone, names same. (this can happen private helper methods, example.) they're not same result of standard or practice followed, rather result of coincidentally having same meaning.

c#

Comments

Popular posts from this blog

delphi - blogger via idHTTP : error 400 bad request -

c++ - compiler errors when initializing EXPECT_CALL with function which has program_options::variables_map as parameter -

How do I check if an insert was successful with MySQLdb in Python? -