D and Nim

weaselcat via Digitalmars-d digitalmars-d at puremagic.com
Sun Jan 4 18:09:39 PST 2015


On Monday, 5 January 2015 at 01:56:20 UTC, Ary Borenszweig wrote:
> On 1/4/15 9:27 PM, bearophile wrote:
>> Walter Bright:
>>
>>> Nim:
>>>
>>>   for neighbour in nodes[nodeId].neighbours:
>>>
>>> D:
>>>
>>>   foreach(immutable route neighbour; 
>>> nodes[nodeID].neighbours){
>>>
>>> Correctly written D:
>>>
>>>    foreach (neighbour; nodes[nodeID].neighbours){
>>
>> I don't agree, the good D way is:
>>
>> foreach (immutable neighbour; nodes[nodeID].neighbours) {
>>
>> D programmers should apply const/immutable to every variable 
>> that
>> doesn't need to mutate.
>
> Why?

Implies intention of the variable at declaration & gives the 
compiler more opportunities for optimization


More information about the Digitalmars-d mailing list