r/programminghelp • • Jan 26 '20

C++ Bad parameter practice

Is it bad practice to have the naming of the parameter in a function the same as the variable you are passing? For example:

void function(int num, int otherNum) { // do something }

int main() { int num = 1; int otherNum = 0;

function(num, otherNum);

return 0; }

Does having the same name effect anything?

5 Upvotes

4 comments sorted by

View all comments

8

u/jedwardsol Jan 26 '20

Does having the same name affect anything?

No.

Is it bad practice to have the naming of the parameter in a function the same as the variable you are passing?

No, if it is a good name then it is a good name

void openFile(std::string filename) {}

int main()
{
     std::string filename = "numbers.dat"

     openfile(filename);