Extract Function is not taking the arguments as a Reference variable
Currently Im working on Qt 5.6.2 . Im Pretty Happy in this enhanced version . In order to have a good code readability I'm reducing the code length of all the functions such as If i have 100 lines of code Im making 10 functions (Each function has 10 lines ) and calling respectively . Im achieving it by EXTRACT FUNCTION feature in Qt . Everything goes fine . When i Do extract function initially the arguments in the newly created method is a reference variable , so that if we change any value of the variable it will update in the function which we are calling . As of now all is fine . But later after few days If i do extract function , the arguments in the new function is not a reference variable . Can any one please help me on how to extract function with refrence variable
@keksi-venksi You can simply change them to references (just & in front of the parameter name). Although you should avoid non-const references as it is not possible to know whether a function/method is changing its parameters without checking the function/method signature:
int a = 10; myFunction(a); // Does myFunction change a or not?
If a function is changing something it should return it as its return value:
int a = 10; a = myFunction(a);
One general note: making 10 functions out of a 100 lines function sounds somehow wrong. You should decide which and how many functions you need based on design and not on number of lines. It can be perfectly fine to divide 100 lines function into, for example, four functions.