- Mar 31, 2017
- Tags: programming
My team has gotten into the habit of annotating the constant parameters when calling a method; and it has paid off immensely.
We turned calls like this:
GetRecord(autoCreate: true, useCache: false);
- Safety: with named parameters, it's harder to flip the parameters around in this case.
- Improved readability.
- Easier code review, especially if you don't remember the signature of the method.
- Newbie friendly.
If your language of choice does not support named parameters, try inline comments:
GetRecord(true /* autoCreate */, false /* useCache */);
The same goes for other types and null of course:
Display(title: null, message: "I'm hungry!"); RunTask(this.RefreshData, maxRetry: 3);