Loosely inspired by how much people seemed to enjoy a similar question I asked on Games about unappreciated titles. But answers don’t have to be media related (they still can be though).

  • Hamartiogonic
    link
    fedilink
    arrow-up
    8
    ·
    1 year ago

    NA and NULL values.

    In R (programming language) they have some interesting differences. You can think of a vector as a train with many cars, and each can hold a number. Let’s say I have train with three cars and I store the number 2, 3 and 5 in them. That would be a normal well behaved vector (2, 3, 5).

    I could take away one of those numbers and leave that seat vacant. It could look like this (2, NA, 5).

    If I tell you to find the third number in that vector, that’s easy. It’s 5. If I tell you to find the ninth one, that just doesn’t make sense and the answer would be NULL.

    So in other words, NA is a vacant seat with no number sitting in it. NULL is a place where there is no seat to begin with.

    • Acters@lemmy.world
      link
      fedilink
      arrow-up
      4
      ·
      1 year ago

      I personally think if you are writing code and you reference outside your memory space, then you should receive an error. I guess a null is already considered an error value, but I think notifying why you got a null would be great.

      NA is not applicable or?
      I don’t like this approach

      • Hamartiogonic
        link
        fedilink
        arrow-up
        2
        ·
        1 year ago

        The best thing about R is that it was written by statisticians. The worst thing about R is that it was written by statisticians.

        I guess this NULL thing would be one of those cases.

        NA would not be applicable, because it’s a placeholder for a missing value. In data analysis, you tend to have have lots of NA-values, and dealing with them is super common. Every function needs to be able to handle them gracefully. For instance mean(someValues, na.rm=TRUE) would be a command for calculating the mean of a particular vector while igrnoring all NA-values. Super handy. Excel handles these missing values in a very annoying manner, but that’s a topic for another rant.

        NULL can be considered an error value, but obviously it’s not very helpful because it doesn’t tell you what went wrong. Obviously, R does have all sorts of error messages, but in this case it just says NULL instead. If you find that some variable has NULL in it, you can be pretty sure something went wrong and it’s most likely due to going outside the space of a particular variable. Likewise interger(0), character(0) or logical(0) are the results you get when you’re searching for something that doesn’t exist. Not really my favorite type of error.

    • mindbleach@sh.itjust.works
      link
      fedilink
      arrow-up
      2
      ·
      1 year ago

      Javascript arrays begin empty, even when sized, and in a way that’s different from NaN. If you do new Array(12).map( (value, index) => index ) to get a counting list, you get… nothing. .map() does not iterate over those indices. But if you do new Array(12).fill(0).map( (value, index) => index ) then it works. .fill() does iterate over those values. Why? Because screw you, that’s why.

      If you examine the empty array in the console, it reports “12 empty slots,” and all values come back as “undefined.” But if you pass it through JSON.stringify, those all become nulls. Why aren’t they nulls in the first place? See previous answer.

      • Hamartiogonic
        link
        fedilink
        arrow-up
        1
        ·
        1 year ago

        Never done anything with javascript, but it sounds like a lot of fun, just like writing VBA in Excel. You know, there’s a reason why I tend to move my calculations to R as soon I can see that Excel is about to consider giving me headaches.