The Daily WTF
Ben ran into some misbehaving C# code- handling users was not doing what it was supposed to do, and when “what it’s supposed to do” is “prevent users from seeing content owned by other users without permission”, that’s a bad thing.
The code Ben found wasn’t the cause of the bug, but it ended up wasting a bunch of his time as he tried to understand why it existed.
It starts with:
public const string UserLess = null; public const string EmptyUser = “”;
Now, one might wonder why we create constants for well known values, like null and an empty string (aka String.Empty). Well, if you were reading this code, you’d have to scroll through several hundred lines before you find out where they’re used.
public static bool IsUserLess([CanBeNull] string userCode) { return userCode == UserLess; } public static bool IsSpecificUser([CanBeNull] string userCode) { if (IsUserLess(userCode) || userCode
To read the full article click on the 'post' link at the top.