CodeSOD: Defensive Programming |
Marino was handed this code. Like all great code, its written defensively, protecting itself against nulls, empty strings, and other unexpected values.
I mean, sort of.
public static void LogMessageWithArguments(string message, params object[] args) {
Condition.Requires(message, "Message");
Condition.Requires(args, "arguments");
if (string.IsNullOrEmpty(message))
{
message = string.Empty;
}
if (args != null)
{
message = string.Format(message, args);
}
if (string.IsNullOrEmpty(message))
{
throw new NullReferenceException("Geen data om te loggen");
}
Log(message);
}
I mean, theyre really thorough about checking that the message has an actual value. Marino checked the Log
function, and found that it already had an overload the accepted a list of formatting parameters, thus making this function both redundant and ugly.
Комментировать | « Пред. запись — К дневнику — След. запись » | Страницы: [1] [Новые] |