Named arguments (parameters) as a readability aid

Posted by Damian Mehers on Programmers See other posts from Programmers or by Damian Mehers
Published on 2011-02-28T12:13:14Z Indexed on 2011/02/28 15:32 UTC
Read the original article Hit count: 309

Filed under:

A long time ago I programmed a lot in ADA, and it was normal to name arguments when invoking a function - SomeObject.DoSomething(SomeParameterName => someValue);

Now that C# supports named arguments, I'm thinking about reverting to this habit in situations where it might not be obvious what an argument means.

You might argue that it should always be obvious what an argument means, but if you have a boolean argument, and callers are passing in "true" or "false" then qualifying the value with the name makes the call site more readable.

contentFetcher.DownloadNote(note, manual : true);

I guess I could create Enums instead of using true or false (Manual, Automatic in this case).

What do you think about occasionally using named arguments to make code easier to read?

© Programmers or respective owner

Related posts about coding-style