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.
[Advertisement]
Scout is the best way to monitor your critical server infrastructure. With over 90 open source plugins, robust alerting, beautiful dashboards and a 5 minute install - Scout saves youvaluable engineering time. Try the server monitoring you'll M today.Your first 30 days are free on us. Learn more at Scout.
| Комментировать | « Пред. запись — К дневнику — След. запись » | Страницы: [1] [Новые] |