What is null equal to?
-
I come before you with a question, a yearning in my heart. What is null..... Equal to?
...
if (value == null || value.equals(null)) {
return "null";
}
...Evidently, the concept of "null" and "null pointers" and "null pointer calls" is lost on the guys who wrote this particular line of code. It doesn't make any errors, probably because someone added the first condition after a few NPEs happened... EDIT: Clarification - the title is rhetorical.
-
I come before you with a question, a yearning in my heart. What is null..... Equal to?
...
if (value == null || value.equals(null)) {
return "null";
}
...Evidently, the concept of "null" and "null pointers" and "null pointer calls" is lost on the guys who wrote this particular line of code. It doesn't make any errors, probably because someone added the first condition after a few NPEs happened... EDIT: Clarification - the title is rhetorical.
What is the sound of two nulls equating?
-
What is the sound of two nulls equating?
Silence from Lorrha [^] [Update} Well, that's pretty useless: the audio track doesn't work. :mad: Or maybe that's the point: literally the sound of nothing at all: null in the truest sense. :)
-
I come before you with a question, a yearning in my heart. What is null..... Equal to?
...
if (value == null || value.equals(null)) {
return "null";
}
...Evidently, the concept of "null" and "null pointers" and "null pointer calls" is lost on the guys who wrote this particular line of code. It doesn't make any errors, probably because someone added the first condition after a few NPEs happened... EDIT: Clarification - the title is rhetorical.
In programming a
null
object means that this doesn't exist in the memory. For example,int i;
if(i == null) {
MessageBox.Show("Yes, Null!");
} else {
MessageBox.Show("No, value was added somewhere in the code stack");
}This, would execute if there is no value in
i
, or the i was never initialized. The code that you're having is something like this// if the variable of value is not initialized
// or contains nothing, does not exist in memory
// .equals(null) is a string method, to check string value
// and has same functionality
if (value == null || value.equals(null)) {
// then return a string that is NOT null but contains "null"
return "null";
}The method signature would be like,
public string Function1 () {
// returns a string
}Favourite line: Throw me to them wolves and close the gate up. I am afraid of what will happen to them wolves - Eminem ~! Firewall !~
-
In programming a
null
object means that this doesn't exist in the memory. For example,int i;
if(i == null) {
MessageBox.Show("Yes, Null!");
} else {
MessageBox.Show("No, value was added somewhere in the code stack");
}This, would execute if there is no value in
i
, or the i was never initialized. The code that you're having is something like this// if the variable of value is not initialized
// or contains nothing, does not exist in memory
// .equals(null) is a string method, to check string value
// and has same functionality
if (value == null || value.equals(null)) {
// then return a string that is NOT null but contains "null"
return "null";
}The method signature would be like,
public string Function1 () {
// returns a string
}Favourite line: Throw me to them wolves and close the gate up. I am afraid of what will happen to them wolves - Eminem ~! Firewall !~
I understand the concept of null, however, evidently "those who came before" didn't... Hence why I'm posting this here ;)
-
In programming a
null
object means that this doesn't exist in the memory. For example,int i;
if(i == null) {
MessageBox.Show("Yes, Null!");
} else {
MessageBox.Show("No, value was added somewhere in the code stack");
}This, would execute if there is no value in
i
, or the i was never initialized. The code that you're having is something like this// if the variable of value is not initialized
// or contains nothing, does not exist in memory
// .equals(null) is a string method, to check string value
// and has same functionality
if (value == null || value.equals(null)) {
// then return a string that is NOT null but contains "null"
return "null";
}The method signature would be like,
public string Function1 () {
// returns a string
}Favourite line: Throw me to them wolves and close the gate up. I am afraid of what will happen to them wolves - Eminem ~! Firewall !~
See the text at the top of the page: "a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance." Nearly everything here is found in real code and will hopefully make you go :doh: :WTF: :OMG: And laugh that anyone could think that the right thing to do... Generally, explanations and code fragment after the original are expected to make even less sense: just to prove it can be done! :laugh: For example, another way to do the original method would be
public object IsNull(object o)
{
try
{
return o.Equals(null) ? o : o;
}
catch
{
return null;
}
}But you'd have to be a complete moron to write that! Oops. I just did... :-O
You looking for sympathy? You'll find it in the dictionary, between sympathomimetic and sympatric (Page 1788, if it helps)
-
In programming a
null
object means that this doesn't exist in the memory. For example,int i;
if(i == null) {
MessageBox.Show("Yes, Null!");
} else {
MessageBox.Show("No, value was added somewhere in the code stack");
}This, would execute if there is no value in
i
, or the i was never initialized. The code that you're having is something like this// if the variable of value is not initialized
// or contains nothing, does not exist in memory
// .equals(null) is a string method, to check string value
// and has same functionality
if (value == null || value.equals(null)) {
// then return a string that is NOT null but contains "null"
return "null";
}The method signature would be like,
public string Function1 () {
// returns a string
}Favourite line: Throw me to them wolves and close the gate up. I am afraid of what will happen to them wolves - Eminem ~! Firewall !~
The problem is not the result of "null", the problem is the
value.equals(null)
. The first part of the if is right (value == null). The second is wrong and it would actually never execute when the value is null (and when it does execute, value will not be null, avoiding an exception). -
See the text at the top of the page: "a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance." Nearly everything here is found in real code and will hopefully make you go :doh: :WTF: :OMG: And laugh that anyone could think that the right thing to do... Generally, explanations and code fragment after the original are expected to make even less sense: just to prove it can be done! :laugh: For example, another way to do the original method would be
public object IsNull(object o)
{
try
{
return o.Equals(null) ? o : o;
}
catch
{
return null;
}
}But you'd have to be a complete moron to write that! Oops. I just did... :-O
You looking for sympathy? You'll find it in the dictionary, between sympathomimetic and sympatric (Page 1788, if it helps)
OriginalGriff wrote:
But you'd have to be a complete moron to write that!, and think that it is good code! Oops. I just did... :O
FTFY!
What do you get when you cross a joke with a rhetorical question? --- The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism.
-
See the text at the top of the page: "a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance." Nearly everything here is found in real code and will hopefully make you go :doh: :WTF: :OMG: And laugh that anyone could think that the right thing to do... Generally, explanations and code fragment after the original are expected to make even less sense: just to prove it can be done! :laugh: For example, another way to do the original method would be
public object IsNull(object o)
{
try
{
return o.Equals(null) ? o : o;
}
catch
{
return null;
}
}But you'd have to be a complete moron to write that! Oops. I just did... :-O
You looking for sympathy? You'll find it in the dictionary, between sympathomimetic and sympatric (Page 1788, if it helps)
Mmmh, yeah, there's stuff like that in there too. I'll have to see if I can anonymize it enough to be internet postable. Let's just say someone did not understand object oriented coding and how Java works. We got to use this library before we actually took over developing it as contractors, and all the problems we had with it before are starting to make sense now...
-
In programming a
null
object means that this doesn't exist in the memory. For example,int i;
if(i == null) {
MessageBox.Show("Yes, Null!");
} else {
MessageBox.Show("No, value was added somewhere in the code stack");
}This, would execute if there is no value in
i
, or the i was never initialized. The code that you're having is something like this// if the variable of value is not initialized
// or contains nothing, does not exist in memory
// .equals(null) is a string method, to check string value
// and has same functionality
if (value == null || value.equals(null)) {
// then return a string that is NOT null but contains "null"
return "null";
}The method signature would be like,
public string Function1 () {
// returns a string
}Favourite line: Throw me to them wolves and close the gate up. I am afraid of what will happen to them wolves - Eminem ~! Firewall !~
-
I come before you with a question, a yearning in my heart. What is null..... Equal to?
...
if (value == null || value.equals(null)) {
return "null";
}
...Evidently, the concept of "null" and "null pointers" and "null pointer calls" is lost on the guys who wrote this particular line of code. It doesn't make any errors, probably because someone added the first condition after a few NPEs happened... EDIT: Clarification - the title is rhetorical.
-
I come before you with a question, a yearning in my heart. What is null..... Equal to?
...
if (value == null || value.equals(null)) {
return "null";
}
...Evidently, the concept of "null" and "null pointers" and "null pointer calls" is lost on the guys who wrote this particular line of code. It doesn't make any errors, probably because someone added the first condition after a few NPEs happened... EDIT: Clarification - the title is rhetorical.
sloosecannon wrote:
What is null..... Equal to?
Don't know, I'm having difficulty getting past the brace placement.
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
-
sloosecannon wrote:
What is null..... Equal to?
Don't know, I'm having difficulty getting past the brace placement.
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
Eh, not my choice. Code style rules...
-
Well, clearly they didn't apply the proper Yoda-ordered syntax in the if statement. Should have read thus:
if (null == value || (null).equals(value)) {
Which can be simplified to
if (null==value)
{
throw new NullPointerException();//It was null, we don't like their kind here
}
else
{
//Do something
} -
See the text at the top of the page: "a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance." Nearly everything here is found in real code and will hopefully make you go :doh: :WTF: :OMG: And laugh that anyone could think that the right thing to do... Generally, explanations and code fragment after the original are expected to make even less sense: just to prove it can be done! :laugh: For example, another way to do the original method would be
public object IsNull(object o)
{
try
{
return o.Equals(null) ? o : o;
}
catch
{
return null;
}
}But you'd have to be a complete moron to write that! Oops. I just did... :-O
You looking for sympathy? You'll find it in the dictionary, between sympathomimetic and sympatric (Page 1788, if it helps)
OriginalGriff wrote:
But you'd have to be a complete moron to write that!
Q.E.D. (Sorry too easy)
"If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.
-
sloosecannon wrote:
What is null..... Equal to?
Don't know, I'm having difficulty getting past the brace placement.
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
-
Which can be simplified to
if (null==value)
{
throw new NullPointerException();//It was null, we don't like their kind here
}
else
{
//Do something
}If it was VB, yes, but not in C#. If it is null, the second part will not be evaluated. It's effectively a dead condition. So, it won't blow up - thanks to this oversight. I vaguely remember a manager who claimed that we always should use ".equals" for comparisons, and that it was a best practice. Using the operator is not only more readable, it also does not depend on the object having a value.
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]
-
If it was VB, yes, but not in C#. If it is null, the second part will not be evaluated. It's effectively a dead condition. So, it won't blow up - thanks to this oversight. I vaguely remember a manager who claimed that we always should use ".equals" for comparisons, and that it was a best practice. Using the operator is not only more readable, it also does not depend on the object having a value.
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]
Woops, logic derp. Yep, you're right. The code is Java for context, but it does lazy logic evaluation too...
-
If it was VB, yes, but not in C#. If it is null, the second part will not be evaluated. It's effectively a dead condition. So, it won't blow up - thanks to this oversight. I vaguely remember a manager who claimed that we always should use ".equals" for comparisons, and that it was a best practice. Using the operator is not only more readable, it also does not depend on the object having a value.
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]
Taking the code from Vark111's post, and assuming C#:
if (null == value || (null).Equals(value)) {
If
value
isn'tnull
, the second part will be evaluated. Since the second part tries to call theEquals
method on a null reference, it would throw aNullReferenceException
. :doh: Thankfully, the C# compiler is smart enough to prevent you from compiling this code - you'll get an "Operator '.' cannot be applied to operand of type '<null>'" compiler error.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
I come before you with a question, a yearning in my heart. What is null..... Equal to?
...
if (value == null || value.equals(null)) {
return "null";
}
...Evidently, the concept of "null" and "null pointers" and "null pointer calls" is lost on the guys who wrote this particular line of code. It doesn't make any errors, probably because someone added the first condition after a few NPEs happened... EDIT: Clarification - the title is rhetorical.
Empty memory is a variable that is declared without a value Null memory is a variable that does not have a memory location Same goes with null from files.