4 ms·
Looking at this from a Java perspective, the behaviour of the example attached to the bug is valid. It would be a significant improvement if it gave a warning
by Mister_Snuggles 10y ago
Looking at this from a Java perspective, the behaviour of the example attached to the bug is valid.
It would be a significant improvement if it gave a warning when an uninitialized variable is used, but apart from that I wouldn't make any changes here.
- jordigh 10y agoThe comparison to Java isn't quite right, as D has structs which are like classes can be on the stack and classes which must always be a reference. So there's a bit of a syntactic inconsistency, where you might think that "SomeClass object;" would declare an object on the stack like "SomeStruct inst;" would, whereas instead it only declares a null reference. If classes can only be references, the syntax should enforce that more clearly. In Java, everything is a reference, so there is less inconsistency there.
- Mister_Snuggles 10y agoYeah, it's not a perfect comparison. I only chose it because I'm familiar with it and understand how that style of code would behave. I do agree that reading a line like "Blah varName;" is confusing when you don't know what 'Blah' is.