Win a copy of Kotlin in Action this week in the Kotlin forum!
    Bookmark Topic Watch Topic
  • New Topic

Null check  RSS feed

 
Renu R.
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi,
I have heard that checking against null "null!=myVariable" is more efficient than checking like this "myVariable!=null".Can anyone let me know the reason for this.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Report post to moderator
Welcome to JavaRanch "NewToRanch Forum",

please read our JavaRanch Naming Policy and change your displayed name to comply with it. We require a displayed name in the form <first name><space><family name>, preferably your real name. Your profile will be disabled if you continue to post with your current dispayed name.

Thanks
-Barry

(NR)
[ October 20, 2005: Message edited by: Barry Gaunt ]
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Report post to moderator
Your question is not relavent to the SCJP certification - it should perhaps be in the Performance Forum. Did you hear it from a person familiar with C or C++? Oh! we are not in SCJP - sorry!

All I can say is that the loss of readability (that is, an increase of the Reader Suprise Factor - (WTF? factor)) of "null != myVariable" should be considered. I would always write "myVariable != null". That is, let the compiler optimise the expression if it wants to.
[ October 20, 2005: Message edited by: Barry Gaunt ]
 
Renu R.
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Report post to moderator
What is this WTF factor?
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Report post to moderator
To put it politely it means "The Reader Suprise Factor". Sorry I for got the international readership issue.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Report post to moderator
Continued at http://www.coderanch.com/t/202493/Performance/java/Null-check
 
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!