Geeks With Blogs

News
Joe Mayo

Using named arguments everywhere is tedious and unnecessary, but can be applied as needed to improve the readability of your code.  Here’s an example, using Directory.Delete() that helps document the meaning of a bool argument:

Directory.Delete(pathToDelete, recursive: true);

If Directory.Delete was your own code, you could re-write the parameter to use an Enum and get away from the bool code smell.  However, Directory is a class in the .NET Framework’s System.Diagnostics namespace, which demonstrates a situation that you can’t change yourself.  There might be other ways to make this code self documenting, but now that we have named arguments, it’s pretty easy to add the name whenever you think it might help.

Joe

Posted on Monday, October 11, 2010 11:04 AM C# | Back to top

Copyright © Joe Mayo | Powered by: GeeksWithBlogs.net