Using function arguments as local variables

前端 未结 9 1343
野的像风
野的像风 2020-12-30 03:57

Something like this (yes, this doesn\'t deal with some edge cases - that\'s not the point):

int CountDigits(int num) {
    int count = 1;
             


        
9条回答
  •  攒了一身酷
    2020-12-30 04:20

    The code needs to be as self sufficient as possible. What I mean by that is you now have a dependency on what is being passed in as part of your algorithm. If another member of your team decides to change this to a pass by reference then you might have big problems.

    The best practice is definitely to copy the inbound parameters if you expect them to be immutable.

提交回复
热议问题