Well, Main defined to never be called with a null parameter. If it somehow gets a null parameter, then your environment is so broken that all bets don't work no matter what you do, so nothing really works out by checking for null .
On the other hand, if you check the null value, readers and code developers will need to understand why. Why did the original programmer make such a useless check? Did he know something we don’t have? We cannot just delete it, because it may have discovered some strange error in the corners!
In other words, you add complexity to your program and upset future code readers. Do not do this. This future user may be you. Make your future happy and write code that makes sense.
However, in situations where such a null check makes sense, it should be the leftmost condition.
In a test like this: args.Length == 0 || args == null args.Length == 0 || args == null , args.Length is first evaluated, and if that fails, args compared to null . In other words, if args is null, your code throws an exception. It should be args == null || args.Length == 0 args == null || args.Length == 0
jalf
source share