Why do so many "developers" not understand 'null'?
-
I read somewhere, years ago, that zero/nothing is one of the most difficult concepts for the human brain to understand. I think it was suggested that that was why there is no zero in Roman numerals.
Zero and null are not remotely the same thing. Zero is a value like any other. Null is the absence of any value, "undefined" if you like.
-
Zero and null are not remotely the same thing. Zero is a value like any other. Null is the absence of any value, "undefined" if you like.
-
I have just gone through four QA questions, each of which is an error caused by a null reference. And yet none of the posters seems to have any idea a) how to diagnose and fix it, or b) even what the error means. Do those of you who still work in teams find this is a common problem with younger team members?
This happens because young programmers learn (at first) languages like python, C#, or other high-level languages right away. Old farts like me have had to put up with C, if not even assembly language. At least on K&R, it is explained what a null pointer is, although my favorite chapter is the one where complicated declarations (which are not complicated at all) are described. It's fine to learn high-level languages right away, but don't we want to take a look at how things work internally? Maybe with the help of the old, decrepit, and "very dangerous" C? I'm not saying to delve into Assembly ... C is sufficient. I am always amazed when I see young computer science students get stunned when I tell them about the two's complement. Old languages may be old and decrepit (though still widely used), but they would still be very useful for many people. To be picky, even high-level languages run on hardware whose principles are still those of John von Neumann's architecture, evolved or not. Many people would still have a lot to learn from "very very very ugly and dangerous" languages like C. And I don't find anything complicated or difficult to understand in malloc(0) either. It must be because I am an old fart. Cheers
-
This happens because young programmers learn (at first) languages like python, C#, or other high-level languages right away. Old farts like me have had to put up with C, if not even assembly language. At least on K&R, it is explained what a null pointer is, although my favorite chapter is the one where complicated declarations (which are not complicated at all) are described. It's fine to learn high-level languages right away, but don't we want to take a look at how things work internally? Maybe with the help of the old, decrepit, and "very dangerous" C? I'm not saying to delve into Assembly ... C is sufficient. I am always amazed when I see young computer science students get stunned when I tell them about the two's complement. Old languages may be old and decrepit (though still widely used), but they would still be very useful for many people. To be picky, even high-level languages run on hardware whose principles are still those of John von Neumann's architecture, evolved or not. Many people would still have a lot to learn from "very very very ugly and dangerous" languages like C. And I don't find anything complicated or difficult to understand in malloc(0) either. It must be because I am an old fart. Cheers
-
It isn't. I have one apple in my hand. How much do you have in yours? Even prehistoric hunters came back with "zero". There's no 0 in Roman Numerals because it would not make sense to count nothing. A farmer that owes no taxes gets ignored, they counted what was owed. "Zero" would have no use there; even if that is the return of your hunting trip, 0 is not recorded. Writing is too precious to record zero's.
Bastard Programmer from Hell :suss: "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
Do you ever really have 0 apples from a weird sort of ship of Theseus-like perspective? Some cultures lack that sort of integer concept from a similar view... all apples are not created equal. No point talking about N of them as the potential distance from reality only increases the further from 1 you get. Forget apples to oranges, they don't even do apples to apples. More recently, quantum physics is saying there is no "nothing" and that there is always "quantum foam" that has always been. Maybe the young ones are so much smarter they look dumb. Nahhh haha. But maybe sending null across a wire as a matter of course is a little bit dumb too.
-
I have just gone through four QA questions, each of which is an error caused by a null reference. And yet none of the posters seems to have any idea a) how to diagnose and fix it, or b) even what the error means. Do those of you who still work in teams find this is a common problem with younger team members?
Meh, because often it's a pain in the neck? Look at most languages and the various operators or functions built around 'null'. Then there's things like empty, not set, nothing, and default 'blank' types. Gets into a lot of fun, especially with databases and SQLs. Speaking of fun, and a fun discussion, I had a young programmer use the three values of a boolean. I asked what he was doing. I said go get that switch on the wall to be 'not answered', lol. I'm a firm believer in two boolean values. If you're looking for 3 answers, use a different data type and clearly capture the intent. In my database designs, I leave no null values. Saves that pesky code, lol.
-
I have just gone through four QA questions, each of which is an error caused by a null reference. And yet none of the posters seems to have any idea a) how to diagnose and fix it, or b) even what the error means. Do those of you who still work in teams find this is a common problem with younger team members?
-
I have just gone through four QA questions, each of which is an error caused by a null reference. And yet none of the posters seems to have any idea a) how to diagnose and fix it, or b) even what the error means. Do those of you who still work in teams find this is a common problem with younger team members?
-
I have just gone through four QA questions, each of which is an error caused by a null reference. And yet none of the posters seems to have any idea a) how to diagnose and fix it, or b) even what the error means. Do those of you who still work in teams find this is a common problem with younger team members?
-
I have just gone through four QA questions, each of which is an error caused by a null reference. And yet none of the posters seems to have any idea a) how to diagnose and fix it, or b) even what the error means. Do those of you who still work in teams find this is a common problem with younger team members?
i tried to explain that to C# students (back when i had a few) by saying that a "null reference" is a named/typed placeholder/slot for a pointer/reference to something which is not defined. you, the programmer, have the "freedom" to create the named/typed slot. and, that the common exception "null reference" was what happened after your running code made demanded/needed/required a defined pointer. you have a favorite metaphor, or explanation ... i am all ears ! of course, now, Visual Studio/C# compiler (and ReSharper) are going to ... suggest a check. and, now, C#/>NET has new Attributes for static Type analysis: [^].
«The mind is not a vessel to be filled but a fire to be kindled» Plutarch
-
And so is the color black (assuming an RGB color space). Or anything else represented as binary zeroes in your favorite computer architecture. That two values of completely different semantics have identical same internal representations doesn't imply that the two values are "very much the same thing" - if you just overlook the type/class information. In an OO world, any object instance, regardless of class, having a single member which is set to some value represented as all bits reset is also very much the same thing as a numeric zero. Or a null pointer. If you ignore its semantics, the way you do to claim that zero and null are very much the same thing.
-
And so is the color black (assuming an RGB color space). Or anything else represented as binary zeroes in your favorite computer architecture. That two values of completely different semantics have identical same internal representations doesn't imply that the two values are "very much the same thing" - if you just overlook the type/class information. In an OO world, any object instance, regardless of class, having a single member which is set to some value represented as all bits reset is also very much the same thing as a numeric zero. Or a null pointer. If you ignore its semantics, the way you do to claim that zero and null are very much the same thing.
-
I have just gone through four QA questions, each of which is an error caused by a null reference. And yet none of the posters seems to have any idea a) how to diagnose and fix it, or b) even what the error means. Do those of you who still work in teams find this is a common problem with younger team members?
I have to deal with Microsoft employees not understanding null for dates or GUIDs, thereby actually making programming, especially if a database is involved, even more difficult.
-
I have just gone through four QA questions, each of which is an error caused by a null reference. And yet none of the posters seems to have any idea a) how to diagnose and fix it, or b) even what the error means. Do those of you who still work in teams find this is a common problem with younger team members?
Richard MacCutchan wrote:
Do those of you who still work in teams find this is a common problem with younger team members?
Versus other problems by inexperienced (younger) persons in any craft? I didn't get better with null until I burned myself so many times that I started focusing on it intently. Thus experience.
-
I have just gone through four QA questions, each of which is an error caused by a null reference. And yet none of the posters seems to have any idea a) how to diagnose and fix it, or b) even what the error means. Do those of you who still work in teams find this is a common problem with younger team members?
-
I have just gone through four QA questions, each of which is an error caused by a null reference. And yet none of the posters seems to have any idea a) how to diagnose and fix it, or b) even what the error means. Do those of you who still work in teams find this is a common problem with younger team members?
-
I didn't have that problem, but I did have a junior developer think that the font was causing a unicode problem.
Bond Keep all things as simple as possible, but no simpler. -said someone, somewhere
-
I have just gone through four QA questions, each of which is an error caused by a null reference. And yet none of the posters seems to have any idea a) how to diagnose and fix it, or b) even what the error means. Do those of you who still work in teams find this is a common problem with younger team members?
No. Where are you finding these people? It seems hard to get far in life without knowing what null is. KNIGHT: The Knights Who Say Null demand a sacrifice! ARTHUR: O, Knights Who Say Null, we are but simple travelers who seek an enchanter who lives beyond these woods. KNIGHT: NULL! NULL! NULL! ARTHUR and PARTY: Ooh, ow! KNIGHT: We shall say NULL again to you, if you do not appease us. ARTHUR: Well, what is it you want? KNIGHT: We want... a :shipit: on this code-review.
-
In Norwegian, the name of numeric zero is 'null'. So Norwegian kids 'sort of' have an excuse for confusing the two. But they are quite different. Zero is a distinct, well defined numeric value that you may treat 100% like any other numeric value. 'null' is nothing, not a numeric value, but a void. Emptiness. An abyss. Not at a valid numeric value. Some programming languages use the term 'void'; it is really much more descriptive. I feel like digging up my old Robert Heinlein collection to re-read the short story—And He Built a Crooked House[^]. The story tells about a crazy architect (in California, obviously :-)) who designs a house which is a 3-dimensional projection of a 4-dimensional cube, a tesseract. The night before the house owners move in, there is an earthquake that makes the house fold up as a true tesseract, in 4 dimensions, not just as a 3-dim projection. I believe that Heinlein has taken liberties in his description of how a real tesseract would appear. But his description of the view out one window, of a total emptiness, not even black, gave me shivers when I first read it, many years ago. It is a beautiful literary description of the concept of a 'null'. I think that I didn't fully understand the concept of null, void, myself until I read the Heinlein story.
trønderen wrote:
'null' is nothing, not a numeric value, but a void.
Which arises after learning to count and has nothing to do with difference between numeric nothing or nothing at all. What has Heinlein to say about having no apples 40.000 years ago? Would it be 0 apples, null apples, or would the net result of no apples be the same?
Bastard Programmer from Hell :suss: "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
-
In Norwegian, the name of numeric zero is 'null'. So Norwegian kids 'sort of' have an excuse for confusing the two. But they are quite different. Zero is a distinct, well defined numeric value that you may treat 100% like any other numeric value. 'null' is nothing, not a numeric value, but a void. Emptiness. An abyss. Not at a valid numeric value. Some programming languages use the term 'void'; it is really much more descriptive. I feel like digging up my old Robert Heinlein collection to re-read the short story—And He Built a Crooked House[^]. The story tells about a crazy architect (in California, obviously :-)) who designs a house which is a 3-dimensional projection of a 4-dimensional cube, a tesseract. The night before the house owners move in, there is an earthquake that makes the house fold up as a true tesseract, in 4 dimensions, not just as a 3-dim projection. I believe that Heinlein has taken liberties in his description of how a real tesseract would appear. But his description of the view out one window, of a total emptiness, not even black, gave me shivers when I first read it, many years ago. It is a beautiful literary description of the concept of a 'null'. I think that I didn't fully understand the concept of null, void, myself until I read the Heinlein story.
trønderen wrote:
'null' is nothing, not a numeric value, but a void
This is not strictly true. In any (programming) language null is a value representing an abstract concept, just like an integer is a value representing an instance of a specific class of numbers, which are themselves an abstract concept used to quantify the world. It is true 'null' is the concept of 'not having a valid value' (i.e. nothing) but it is represented in a program using a value in various different lexical forms; null/NULL/etc. The OP clearly raised a very a good question that could, perhaps, be more pointedly made with the more abstract question; Why do so many developers not understand abstraction?