D and Nim
Ary Borenszweig via Digitalmars-d
digitalmars-d at puremagic.com
Sun Jan 4 18:12:20 PST 2015
On 1/4/15 11:09 PM, weaselcat wrote:
> 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
The first, maybe (for me it's noise: if I want to mutate it, I do,
otherwise I don't).
For the second, the compiler can tell that if you don't assign anything
more to it then it's immutable. So I'm not sure the second one is true.
More information about the Digitalmars-d
mailing list