Completing C code with D style

forkit forkit at gmail.com
Wed Nov 10 06:47:32 UTC 2021


On Wednesday, 10 November 2021 at 04:54:58 UTC, Stanislav Blinov 
wrote:
> On Tuesday, 9 November 2021 at 11:03:09 UTC, forkit wrote:
>
>> They both produce exactly the same output.
>
> But do vastly different things.
>
>> But I tell ya.. the cognitive load .. well.. it increased 
>> dramatically ;-)
>
> Of course it did. Cuz you overthunk it. Dramatically.
>
> Your D version allocates memory, for no good reason. I mean, to 
> store results, but you already have storage for them, so kinda 
> pointless. Your C version, OTOH, stores results on stack (so 
> again, why did you allocate for them in D?..), but allocates 
> some "string builder" for... what, exactly?
>
> The program is filter, or sort + partition. Requires 0 
> allocations in C or D.

Thanks for your feedback.

This was not production code. It took a few minutes to do it on 
my pc, just for a little fun. So I doubt that I 'overthunk it' in 
such a small amount of time ;-)

Also, my thought process began from the basis that the number 
data was immutable, and that the final data need to be stored, so 
that it could be manipulated etc... at will. I also wanted the 
use to a message, as to what they chose (hence the manipulation 
of memory for a message that could not be know in advance of the 
user making those choices).

btw. My pc has 24GB of main memory, and my CPU 8MB L3 cache. So I 
really don't give a damn about allocations .. not one little bit 
;-)

Now if I were running a million processes across 1000's of 
servers, I probably would give a damn.


More information about the Digitalmars-d-learn mailing list