Hi,

Am 2011-04-16 um 13:32 schrieb Ted F.A. van Gaalen:

> Hi there.
> 
> I am probably not the first, and will not be
> the last person to come up
> with this suggestion, neverTheLess:
> 
> To increment a numeric value I would like to write:
> 
> aNum := 1.
> aNum ++.             to increment it
> aNum --.             to decrement it
> 
> instead of:
> aNum := aNum + 1.
> 
> For reasons of efficiency and readability.
> 
> Why?
> Most, if not all, of today's computer processors
> ( they used to be called microprocessors :o)
> have INCrement en DECrement instructions,
> which are much more efficient than addition
> and subtraction instructions.
> (less clock cycles, perhaps even just one)
> 

Interestingly, this is already done when using a JIT,
eg, the CogVM. 

But what is more important is, that in Smalltalk, Integers
are unmodifiable.

There are different concepts:

in C,

i++

means,

"increase the number in the memory cell that i represents"

however, in Smalltalk,

i ++

would mean

"send the object that is stored in i the message #++"
And if a number, eg 42, is stored in i, then this would mean
"send 42 the message #++"
but what should the result be?
should 42 transform itself into 43? 
Moreover, it is bad style in Object-Oriented programming to
rely on side effects of a message:
You're implicitly saying
"I want the state of the object in i to change and rely on it 
later-on"

whereas 
i := i + 1
is explicitly saying

"I want a number greater than i and work with it later-on"

> Of course, the work should to be done by primitives,
> which directly utilizes the processor's INC, DEC instructions.
> 
As I said this is subject to a JIT.

> So, wouldn't it be convenient to implement these ++ and ---
> methods in Pharo? and VM.  I am not sure, but I suspect also a number
> of system classes e.g. in     do: [:i|...]   would perform better,
> wenn this method/ instruction is supported?
> 

I don't think so.

So Long,
        -Tobias

Reply via email to