3 ms·
Not just beginners. Seeing the following in a pull request is bad for everybody: someFunction(username, true, false, 10) Named parameters remove ambiguity
by gregmac 6y ago
Not just beginners. Seeing the following in a pull request is bad for everybody:
someFunction(username, true, false, 10)
Named parameters remove ambiguity and make the code easier to read and review, and even avoid bugs because if you're passing the wrong values it's immediately obvious.
One of the hidden issues with the above code comes in the future: if anyone ever changes the order of the 2nd and 3rd arguments in the function definition, and forgets to update this spot, the code will still "work" (no compile error) but instead will have the wrong runtime behaviour. In a pull request, you can't see all the affected spots that didn't get updated, so it is easy to slip through.