Unexpectedly nice case of auto return type
Basile B.
b2.temp at gmx.com
Fri Dec 6 19:32:38 UTC 2019
On Wednesday, 4 December 2019 at 12:54:34 UTC, Basile B. wrote:
> On Wednesday, 4 December 2019 at 03:17:27 UTC, Adam D. Ruppe
> wrote:
>> On Wednesday, 4 December 2019 at 01:28:00 UTC, H. S. Teoh
>> wrote:
>>> typeof(return) is one of the lesser known cool things about D
>>> that make it so cool. Somebody should write an article about
>>> it to raise awareness of it. :-D
>>
>> you know i probably will write about that next week. so be
>> sure to like, comment, and subscribe so you never miss my next
>> post and then give me all your money on patreon so i can keep
>> bringing you content :P :P
>
> I've just made the refact using typeof(null) and gained 78 SLOC
> The pattern was:
>
> void issueError();
>
> and then in the code, in a dozen a function returning different
> classes types
>
> if (...) {
> issueError();
> return null;
> }
>
> now this becomes:
>
> typeof(null) issueError();
>
> if (...)
> return issueError();
>
> I wish I knew that trick before. I prefer typeof(null) in case
> I would translate to another language. I tend to type the
> static type when I know it anyway.
more -520 lines today.
More information about the Digitalmars-d-learn
mailing list