3 ms·
>Do you mean "valid programs where everything is initialized when an object is created will somehow fail to detect that"? Valid programs where a field is left
by Arnavion 5y ago
>Do you mean "valid programs where everything is initialized when an object is created will somehow fail to detect that"?
Valid programs where a field is left uninitialized at creation time, but the programmer makes sure it's initialized before it's used.
- pjc50 5y agoSure, so we can easily change the definition of "valid" so that you have to initialize them at creation time. shrug
- db48x 5y agoNo, I don’t think that this should be considered a valid program. I would never allow any code that creates a partly–initialized struct in any code that I maintain. I agree that it’s a hard problem, but I don’t think that language designers should use that as an excuse. I think that language designers should really double–down and require that every field be initialized, otherwise people will just forget. The code will be carefully written at first, but then someone new will come along and add a new field, and then the existing code is insufficient. With no errors from the compiler there is no way to ensure that the new programmer updates everything to accommodate the new field. Rust does pretty well in this regard, but you can still use unsafe blocks to get a partly–initialized struct if you really want one. I like Rust, but I wish that it went all the way and didn’t allow it at all.