|
Silence from Lorrha [^]
[Update} Well, that's pretty useless: the audio track doesn't work.
Or maybe that's the point: literally the sound of nothing at all: null in the truest sense.
|
|
|
|
|
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 (value == null || value.equals(null)) {
return "null";
}
The method signature would be like,
public string Function1 () {
}
Favourite line: Throw me to them wolves and close the gate up. I am afraid of what will happen to them wolves - Eminem
~! Firewall !~
modified 25-Aug-14 13:29pm.
|
|
|
|
|
I understand the concept of null, however, evidently "those who came before" didn't...
Hence why I'm posting this here
|
|
|
|
|
|
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...
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.
|
|
|
|
|
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...
|
|
|
|
|
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.
|
|
|
|
|
Q.E.D.
(Sorry, it was just sitting there waiting for it).
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
Alan Kay.
|
|
|
|
|
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).
|
|
|
|
|
euhm, isn't
int i;
never null (it can't be null, that's where int? i is for )
(in C# that is)
(just double checked, you cannot even compile if not initialized, in the immediate window it initialized to 0)
|
|
|
|
|
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();
}
else
{
}
|
|
|
|
|
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
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...
|
|
|
|
|
Taking the code from Vark111's post, and assuming C#:
if (null == value || (null).Equals(value)) {
If value isn't null , the second part will be evaluated. Since the second part tries to call the Equals method on a null reference, it would throw a NullReferenceException .
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
|
|
|
|
|
sloosecannon wrote: What <dramatic pause="">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...
|
|
|
|
|
Nothing wrong with that. It's very common.
K&R Style[^]
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
Alan Kay.
|
|
|
|
|
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.
|
|
|
|
|
“==” compares if the object references are same while “.Equals()” compares if the contents are same.
So if you run the below code both “==” and “.Equals()” returns true because content as well as references are same.
object o = ".NET Interview questions";
object o1 = o;
Console.WriteLine(o == o1);
Console.WriteLine(o.Equals(o1));
Console.ReadLine();
True
True
Now consider the below code where we have same content but they point towards different instances. So if you run the below code both “==” will return false and “.Equals()” will return true.
object o = ".NET Interview questions";
object o1 = new string(".NET Interview questions".ToCharArray());
Console.WriteLine(o == o1);
Console.WriteLine(o.Equals(o1));
Console.ReadLine();
False
True
Sankarsan Parida
|
|
|
|
|
sloosecannon wrote: What is null equal to?
The place I worked in Germany?
|
|
|
|
|
I was asked to make small amendments to an ages old ASP Classic website. So I tried to log into the "administration" area, didn't know what username/password to use, and opened up the code to see where in the database (MSAccess) I should look for valid credentials...
Behold (some details left out/altered to protect involved parties):
Dim msg
msg=""
Dim sql
sql="SELECT * FROM USERS WHERE (usr= '" + username +"')"
Dim rs
Set rs = Server.CreateObject("ADODB.Recordset")
rs.ActiveConnection = dbconnSTRING
rs.Source = sql
rs.CursorType = 0
rs.CursorLocation = 2
rs.Open()
if rs.Eof And rs.Bof then
msg="Invalid username"
end if
sql="SELECT * FROM USERS WHERE (pswd= '"+ password +"')"
rs.Close()
rs.Open(sql)
if rs.Eof And rs.Bof then
if msg="Invalid username" then
msg="Invalid username and password"
else
msg="Invalid password"
end if
end if
So basically if I know your username and I have my own account, I can use your username and my password and log in as you...
Nice eh?
Φευ! Εδόμεθα υπό ρηννοσχήμων λύκων!
(Alas! We're devoured by lamb-guised wolves!)
|
|
|
|
|
|
A thing of beauty. Thanks for immortalizing it here.
P.S. I'll also take a moment to point out that such a validation routine should never indicate what went wrong, only that it failed. Telling a potential baddy that the user name doesn't exist makes his job easier -- he's simply stop trying that username and move on to the next without trying any more passwords.
modified 25-Aug-14 11:30am.
|
|
|
|
|
I'm never sure about that one. Yes, it has a marginal effect on security, but it has a big effect on user annoyance, and I think the trade-off is worth it in most cases to let a user know that they mistyped their username.
|
|
|
|