News for hackers. Stuff that matters.
Re:Go 1.18 by dialogbox on Tuesday March 15, 2022 @06:37PM (#30692861)
IMO using Optional type means the inner value must be not null. And if it's Some(null), it should mean exactly same as None.
Re:Go 1.18 by uryga on Tuesday March 15, 2022 @07:22PM (#30693267)
distinguishing `Some(null)` and `None` is often considered a feature of Optional ;)

to use a tired example: when getting a value out of a map via some `myMap.get(key)`, you may want to distinguish "not present" = `None` and "present, with value null" = `Some(null)`

the right solution is to just not have nulls in the first place, then there's no problem ;)

Re:Go 1.18 by alophawen on Tuesday March 15, 2022 @10:53PM (#30694795)
(Assuming we are discussing the Option type from rust)

Some(null) is not a valid result.

The whole point of the Option type is to let you know:

a) we got a result: Some(value)

b) there is no result: None

Re:Go 1.18 by andrewjf on Wednesday March 16, 2022 @10:32AM (#30699303)
It's trivial to store a null pointer in an Option::Some().

  struct Foo;
  
  fn main() {
      let option_with_null: Option<*const Foo> = Some(std::ptr::null());
  
      dbg!(option_with_null);
      dbg!(option_with_null.is_none());
  }
Output:

  [src/main.rs:6] option_with_null = Some(
      0x0000000000000000,
  )
  [src/main.rs:7] option_with_null.is_none() = false



https://play.rust-lang.org/?version=stable&mode=debug&editio...
Re:Go 1.18 by alophawen on Wednesday March 16, 2022 @03:58PM (#30703290)
As the creator of the function, you should try to adhere to the conventions and not try to break them.
Re:Go 1.18 by andrewjf on Wednesday March 16, 2022 @06:57PM (#30705226)
I don't disagree, but:

> Some(null) is not a valid result.

It is a valid result. Null pointer and Option::None are still different things, is all.