The daily D riddle

Amorphorious Amorphorious at gmail.com
Thu Feb 1 00:19:48 UTC 2018


On Sunday, 28 January 2018 at 06:44:40 UTC, Jonathan M Davis 
wrote:
> On Sunday, January 28, 2018 08:25:51 Shachar Shemesh via 
> Digitalmars-d wrote:
>> What will the following code print? Do not use the compiler:
>>
>> import std.stdio;
>>
>> struct A {
>>   int a = 1;
>>
>>   void initialize() {
>>       a = a.init;
>>   }
>> }
>>
>> void main() {
>>   A a;
>>   a.initialize();
>>
>>   writeln(a.a);
>> }
>>
>> I find this behavior unexpected.
>
> It does exactly what I'd expect it to do, though honestly, it's 
> the sort of thing I wish weren't legal, just like I wish that 
> it weren't legal to call a static member function via a member. 
> Maybe there are cases where it's useful, but it just seems 
> wrong.
>
> In any case, init goes with a type, not a variable, which is 
> why it acts the way it does.
>
> - Jonathan M Davis

One day you will hopefully learn that you are not the god of 
logic and just because you think something is right or wrong 
doesn't mean it is so.  What happens with people like you is that 
they end up causing more problems down the road because they were 
wrong and too ignorant to understand it. It's not your fault... 
blame it on evolution if you want, but what determines right and 
wrong  should be decided by mathematical proof, not gut feelings.


More information about the Digitalmars-d mailing list