conventions - Is it good practice to check for null and check object properties in the same if statement -
Is it good practice to check the blank and check the properties of the object in the same condition if statement?
The following code:
if (jamesBlunt! = Null & amp; amp; amp; amp; & amp; amp; amp; amp; ;;;;;;;;;;); JustialBad ()} {// do not buy your records} This special code is in Java and I know that expression has been evaluated from left to right So, technically, this null pointer will not make an exception, but in general it is a good practice in any language?
I think = is a typo and you mean & Amp; Amp; :) To answer your question: It depends.
Can it ever be empty for jamesBlunt ? If not, there would be better practice to do something like this: Zero is being purchased (artist jamesBlunt) {if (jamesBlunt == null) {new illegal execution exception ("James is not empty should be there ! "); }} If it makes sense for jamesBlunt , then your view is OK, assuming null and IsReallyBad means the same thing, that is, if they say different things meaningfully, then you should not combine them on one line. You need to be careful in other languages. Many people (java, c ++, c # etc) will behave in the same way, but some can evaluate right-to-left or evaluate snippets. Take special care with functional languages such as Lisp and Plan, because they behave differently for Oriented languages like Java and C #.
Comments
Post a Comment