So, I can test if it's nil and it tells me it's not. I can test if it exists and it tells me it does, but if i try and do anything with it, it blows up.
In my code i had to change it to log_version = nil.as(String?) to get around this because it isn't clear how to test if a variable is uninitialized. It's probably in the doc's somewhere but I haven't found it, and i really don't think that the tests above should BOTH pass... I can see the argument against ! log_version.nil? passing, because it's not really nil. It's uninitialized but the fact that it passes the second test seems crazy. it's the most non-existent form of something. How can that be truthy?
The text was updated successfully, but these errors were encountered:
You can always model what you would have done with uninitialized with nil, and it'll be safer and cleaner code. The only use for uninitialized is for performance where you don't want to create a type union, but unless you really know what you're doing removing safety for a tiny increase in speed is unwise.
Unless you're binding C code then uninitialized is useful.
For reference, there's no way to know if a variable is initialized or not because it will contain entirely random data. If it's a reference it will likely point to uninitialized memory (at least on 64bit), if it's a struct it will contain garbled data. There's no sane way to detect what is uninitialized.