Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Why do so many "developers" not understand 'null'?

Why do so many "developers" not understand 'null'?

Scheduled Pinned Locked Moved The Lounge
helpsharepointcollaborationbeta-testingtutorial
61 Posts 36 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Lost User

    jochance wrote:

    But most probably do not look at 0/null the same way as they look at other deeper mathematical concepts.

    Like ALL programmers, I had to deal with floats nearing zero, which is not NULL.

    jochance wrote:

    Null though? Null was maybe never destined to be anything but a logical error. [Coffee]

    Nope. Let me explain, little padawan; 0 is having no apples. null is having no concept of apples.

    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.

    J Offline
    J Offline
    jochance
    wrote on last edited by
    #51

    And here I might've supposed you'd want people talking less about things they have no concept of. What's really important is the ability to dictate to the apple that it is inferior, and they mostly left that out altogether. lol

    L 1 Reply Last reply
    0
    • J jochance

      And here I might've supposed you'd want people talking less about things they have no concept of. What's really important is the ability to dictate to the apple that it is inferior, and they mostly left that out altogether. lol

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #52

      jochance wrote:

      What's really important is the ability to dictate to the apple that it is inferior, and they mostly left that out altogether.

      That makes no sense at all. Pears are superior tough :thumbsup:

      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.

      1 Reply Last reply
      0
      • L Lost User

        What I actually said was

        Quote:

        In C zero and NULL are very much the same thing.

        Not that zero and null are the same everywhere.

        H Offline
        H Offline
        haughtonomous
        wrote on last edited by
        #53

        We're both right. You're referring to an implementation, I was referring to the concept, the abstraction if you like, where null represents "value unknown" (or "not yet defined").

        L 1 Reply Last reply
        0
        • J jmaida

          trønderen has also said it well. Even the C language has confusion on this topic. Yes, I too believe that they have distinct meanings. Remember my posing the question of why is this a valid statement in C zero = 0; value = malloc( zero ); value is not null nor zero. Why would I want to allocate zero memory? Here is what ChatAI says In the C programming language, calling malloc(0) is allowed and returns a pointer to a memory block of size 0. This is specified in the C standard, which states that malloc(0) is equivalent to malloc(1). The reason for this behavior is that malloc is intended to allocate memory dynamically, and a request for 0 bytes of memory is considered a valid request. Allocating a block of memory with a size of 0 can be useful in certain situations, such as when you want to create a zero-length array or when you want to allocate memory that you will later reallocate to a different size using realloc. However, it is important to note that malloc does not guarantee that it will return a pointer to a block of memory that is truly 0 bytes in size. The implementation of malloc may choose to return a block of memory that is larger than the requested size, in which case the additional memory will not be accessible to your program. Clear as mud.

          "A little time, a little trouble, your better day" Badfinger

          H Offline
          H Offline
          haughtonomous
          wrote on last edited by
          #54

          Forgive my ignorance, but what is the point or purpose of a zero length array? Or at the lower level, reserving zero memory space?

          T 1 Reply Last reply
          0
          • H haughtonomous

            Forgive my ignorance, but what is the point or purpose of a zero length array? Or at the lower level, reserving zero memory space?

            T Offline
            T Offline
            trønderen
            wrote on last edited by
            #55

            To declare that it is known, but has a zero length value. E.g. if my middle name is a zero length string, null, it is known that I have no middle name. If it is null, I may have a middle name not yet entered into the database.

            J 1 Reply Last reply
            0
            • L Lost User

              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?

              E Offline
              E Offline
              englebart
              wrote on last edited by
              #56

              The best concept I found to explain Java/C# object references to newcomers is to use a “leash” as the metaphor. Just because you have a leash in your hand, does not mean there is a dog on the other end. The object variable/leash is in the null/no-dog state. Many Java programming errors occur when multiple leashes are attached to the same dog. (And each leash holder thinks they have a unique dog!) [This is why immutable objects are a good idea] A new leash is attached to your dog every time you call a method and “pass” your leash by value. The method can “pull” your dog around or stuff it with treats. How do you free the dog so it becomes a stray so that the dog catcher/garbage collector can pick it up? Assign the variable/leash to null, of course. You can also mix types in with cat leashes vs dog leashes. This can work into leashes as interface holders. This works with C pointers to some extent. You can build on the metaphor to include pointer arithmetic. This is partly a reply to BillWoodruff but I wanted the reply at top level as I always found this a great metaphor.

              1 Reply Last reply
              0
              • B BillWoodruff

                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

                E Offline
                E Offline
                englebart
                wrote on last edited by
                #57

                See my leash metaphor further down

                1 Reply Last reply
                0
                • T trønderen

                  To declare that it is known, but has a zero length value. E.g. if my middle name is a zero length string, null, it is known that I have no middle name. If it is null, I may have a middle name not yet entered into the database.

                  J Offline
                  J Offline
                  jmaida
                  wrote on last edited by
                  #58

                  exactly. 0 means zero in contrast to 1 .. NULL means void or does not exist. However, this subtlety gets blurred by the programming and programmers making use of it. In C, Null is meant to be void address. zero is number 0. But if I do a boolean test on either one, I get false. If you print them they are both zero. Hence the blurriness. They are equivalent at programming level yet we know they mean two different things. Maybe C++ handles it differently. Go figure

                  "A little time, a little trouble, your better day" Badfinger

                  1 Reply Last reply
                  0
                  • H haughtonomous

                    We're both right. You're referring to an implementation, I was referring to the concept, the abstraction if you like, where null represents "value unknown" (or "not yet defined").

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #59

                    Exactly why I prefaced my remark "In C", to make it clear that I was talking about a specific situation.

                    1 Reply Last reply
                    0
                    • H haughtonomous

                      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.

                      J Offline
                      J Offline
                      Jeremy Falcon
                      wrote on last edited by
                      #60

                      In JavaScript, undefined and null are two distinct values. The former meaning not defined and the latter meaning no value. Different concepts completely.

                      Jeremy Falcon

                      1 Reply Last reply
                      0
                      • L Lost User

                        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?

                        U Offline
                        U Offline
                        User 11907673
                        wrote on last edited by
                        #61

                        Besides my full time job as a developer I also teach Computer Science one night a week at a community college. My observation is that the focus for young developers/students is HOW to do things rather than WHY things need to be done. Having mentored many developers over the last 40+ years I always focus on the WHY, because once they understand the WHY the HOW not only becomes fairly obvious they find they often have multiple HOWs to choose from. This is not unique to Computer Science, my 3 daughters are all teachers, High School English, High School Biology, and Elementary school. There is hope, perhaps slight and teacher dependent. The Elementary school teacher pioneered Common Core math in her school district and discovered kids she had taught math to that way in 1st and 2nd grade had significantly better performance in 4th grade. Of course, not universally, but sufficient to clearly see a difference.

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups