Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

15
  • 2
    Nice. But I'm not fully agree. Uninitialized variables are not allowed to use in modern languages. I can't think a way an object can be invalid in modern languages (in C++ for example it can if the constructor threw an exception). <continuation in next comment...> Commented May 28, 2020 at 6:00
  • 1
    Unsafe code is, ah, unsafe. By design it does not prevent you from accessing low-lever API, and with power comes responsibility. Programmers usually don't use unsafe code, and if they do, they separate it to other classes/modules/packages/dlls/etc.. Also I don't understand why embedded or real-time system can't have constants, especially since compilers nowadays are smart enough to inline compile-time constants when that makes sense. Commented May 28, 2020 at 7:54
  • 1
    And about validity, if the object access triggers NullReferenceException (or NullPointerException, TypeError, ...) that means unexpected null. This is exactly the situation that nullable types I'm talking about (and Option types, of course) are here to prevent Commented May 28, 2020 at 7:56
  • 3
    I disagree with "Null is a problem because it's overloaded" specifically because Optional has exactly the same problem. Therefore this is not a reason to prefer Optional to Null. Commented May 28, 2020 at 23:11
  • 2
    @ChayimFriedman No, Rust's unsafe blocks do not allow you to dereference NULL (usually the pointer to the memory location 0x00000000). They allow you to circumvent a few compiler checks, including the restriction on dereferencing arbitrary pointers (which could potentially be 0, aka NULL). Commented May 29, 2020 at 15:05