lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi Daniel:

On Wed, Jun 11, 2014 at 5:15 PM, Daniel Silverstone
<dsilvers@digital-scurf.org> wrote:
> On Wed, Jun 11, 2014 at 16:56:34 +0200, Francisco Olarte wrote:
>> > For example, the intent of  "i = i +1" could not be clearer.
>> > "++i" is shorter and sweeter for the programmer, but it is not clearer and
>> > it is not more expressive.
>>
>> I do not think you've picked a very good example. Many people, me
>> among them, parse '++i' as 'increment i' in one simple pass, and when
>> you have something like
>> ++a_very_long_variable_name_becuase_it_is_a_global, it's much clearer.
>
> I would have to respectfully disagree here.  Since I work with C a lot, I have
> to parse "++i" as "read the value of i, increment it, store it back to i, and
> evaluate to the new value of i"  since that is subtly, but importantly,
> different to "i++" which evaluates to the original value of i.

Well, I did that thinking of C, as I've been working on it for decades
( now more C++/Java, but this part they borrowed from C ), and I have
never got this problem.

Bear in mind I was thinking of ++i in the context of
statement=expression="++i;', not embeded in a larger expression ( I
nearly never embed autoincs except in nearly idiomatic things, like
*p1++=*p2++, curritem=item[++itemnum] or similar things. I did a lot
of this things in CP/M and the early MSDOS compilers, when optimizers
where slow and bad ( or plainly non existent ) and you could really
tune your critical loops, but in the last 10+ years I've found ist is
better to lay the code clear so the optimizer can do its job.

I say I was thinking of using it standalone because in C normally you
can move all the preincrements ( of counters / pointers ) before any
complex expression, all the postincrements after it ( as you can not
normally have two on the same var due to the lack of sequence points )
( and I also always use preincrement in this case, it was faster in
the old days and has always been clearer to me ( I read ++x as INC x ,
i++ as x, INC, but this may be due to habit ). In this case i just
read the blocks as increment this, and that, and the other one, then
do a silly thing, then increment this and whatever more.

> I find mutation operators to generally be unpleasant except as assignments (i += 1) for example.

IIRC In C i+=1 is equivalent to ++i, and has got the same exact
problems, but I see your point just with i += n.

I've also find many beginners grok 'i += n' ( as add n to i ) easier
than i = i + n ( these was when tutoring a couple of friends whose
teacher had the bright idea of teaching them C as the first
programming language, and ( tried to ) teach them arithmetic,
assignements, increments and declarations in the first two hour class,
they came out with some bizarre concepts ).


Francisco Olarte.