On 11/25/17 5:13 PM, Adam D. Ruppe wrote:
On Saturday, 25 November 2017 at 16:16:52 UTC, A Guy With a Question wrote:
If D chooses it's defaults to make errors stick out, why not just error at declaration if they don't explicitly set it to something.

It technically did:

https://dlang.org/spec/function.html#local-variables

"It is an error to use a local variable without first assigning it a value. The implementation may not always be able to detect these cases. Other language compilers sometimes issue a warning for this, but since it is always a bug, it should be an error. "


But that paragraph was never implemented (it is a bit easier said than done to actually detect given if conditions and stuff too, especially in the early days of D when the compiler didn't even make any effort to track such things, though it does now...). The compiler author took the easy way out of initializing them to invalid values instead.

While it is more realistic to implement technically now than it was years ago when the current behavior got in, I think we're at the point now that so many people use it as a convenience thing on ints and nulls that there'd be hell to pay if the compiler actually started calling it an error :(


I rely on the default value initialization all the time! I don't know how that would jive with structs, since they are technically local variables, but usually are valid without initialization.

What about AAs? Would you have to do = []?

-Steve

Reply via email to