What are the prominent downsides of the D programming language?
Steven Schveighoffer
schveiguy at gmail.com
Tue Sep 29 13:01:54 UTC 2020
On 9/29/20 8:39 AM, ddcovery wrote:
> On Tuesday, 29 September 2020 at 11:35:02 UTC, FeepingCreature wrote:
>> On Tuesday, 29 September 2020 at 11:10:42 UTC, ddcovery wrote:
>>> * The "auto" Swiss knife: Yes, I know, "auto" is a powerful tool,
>>> but DLang libraries tends to force you to use auto because
>>> metaprogramming... it is really difficult to a newcomers to
>>> understand the Type returned by a template... and templates are
>>> everywhere.
>>>
>>> i.e.: If you read about Tasks
>>> (https://dlang.org/phobos/std_parallelism.html), for me is not
>>> obvious how to define an empty array of tasks.
>>>
>>> Imagine I have a "4 in a line" game and I want to evaluate with a
>>> thread each column of the game (a minimax algorithm)
>>>
>>>> ??? tasks = [];
>>>> for( int ixTask=0; ix<COLUMNS; ixTask++){
>>>> tasks ~= task!evalColumn(board.clone(), columns[ixTask],
>>>> maxRecursion - 1);
>>>> tasks[ixTask].executeInNewThread();
>>>> }
>>>> ...
>>>
>>> What do you have to place instead "???"
>>
>> I mean, you could do this:
>>
>> auto tasks = COLUMNS.iota.map!(ixTask =>
>> task!evalColumn(board.clone(), columns[ixTask], maxRecursion - 1)).array;
>> tasks.each!"a.executeInNewThread";
>
> Hi FeepingCreature,
>
> But "auto" remains :-D.
>
You don't like auto?
pragma(msg, typeof(tasks[]);
now, go back in and replace tasks[] type with whatever that says.
Swift is 99% type inference. It's strongly typed, and you almost never
see a type declaration. You *can* type it, but there's no need. People
get along swimmingly without having to specify types. It also makes your
code much more robust.
-Steve
More information about the Digitalmars-d
mailing list