A few notes on choosing between Go and D for a quick project

Paulo Pinto via Digitalmars-d digitalmars-d at puremagic.com
Fri Mar 20 14:04:59 PDT 2015


On Friday, 20 March 2015 at 20:31:49 UTC, Walter Bright wrote:
> On 3/20/2015 3:59 AM, Paulo Pinto wrote:
>> On Friday, 20 March 2015 at 10:50:44 UTC, Walter Bright wrote:
>>> Since 'line' is never referred to again after constructed, 
>>> even a simple
>>> optimizer could elide it.
>>>
>>> It would be easy to test - accumulate the lines in an array, 
>>> and check the times.
>>
>> Which the default Python implementation doesn't have, hence my 
>> comment.
>
> After all these years, the default Python implementation 
> doesn't do fairly basic optimizations? I find that a bit hard 
> to believe.
>
>> Also even if it did have one, it cannot elide it as it cannot 
>> guarantee the
>> semantics of the generators/iterators side effects will be 
>> kept.
>
> I wonder why keeping a string would be a side effect.
>
> I'm not saying you're wrong, I don't know Python well enough to 
> make such a judgement. It just causes me to raise one eyebrow 
> like Spock if it does work this way.

The side effect is not keeping the string, rather generating it.

for var in exp:
    do_something()

if exp represents a iteratable or a generator, even if var is 
thrown away the loop needs to be preserved to keep the semantics 
of calling next() on the instance object that executes the  
for..in loop.

Put other way, does DMD throw away foreach loops even if the 
compiler cannot prove if  opApply () or popFront() generate side 
effects, assuming the variable isn't being used?

--
Paulo


More information about the Digitalmars-d mailing list