CodeSOD: Defensive Programming
by Remy Porter from The Daily WTF on (#BJ78)
Marino was handed this code. Like all great code, it's 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, they're 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 today.Your first 30 days are free on us. Learn more at Scout.