Posted by
Igor Stasenko on
Apr 21, 2011; 8:17am
URL: https://forum.world.st/again-tp3464038p3465369.html
On 21 April 2011 07:58, Tobias Pape <
[hidden email]> wrote:
>
> Am 2011-04-20 um 22:18 schrieb Ted F.A. van Gaalen:
>
>> Thanks Tobias and Igor for your thoughts about this increment/decrement theme.
>> @Tobias: what kind of side effect(s) are you talking about? I don't
>> understand, sorry.
>
> No problem, I wrote a bit complicated.
> What I mean is that
> i++
> instructs the object ‘i’ to change its state, ie, increment
> itself.
> However, the Object in ‘i’ is meant to be an
> integer. So, how to interpret that? say, ‘i’ is 5.
> Essentially,
> i++
> says
> ‘five, change your state to be six’
> But that would imply, because all integers are the respecive same
> over the image, that all fives are suddenly sixes.
>
> The point is,
> in C, variables denote memory cells, and it is a common
> operation to say ‘memory cell, increment your content by one’,
> whereas in Smalltalk, a variable denotes an object and
> such an increment is rather senseless on integer objects.
>
> In other words, each integer in a Smalltalk image is
> a kind of Singleton.
> ( as
> 1 = 1 " => true"
> 1 == 1 " => true"
> )
> Hence,
> | a b |
> a := 1.
> b := 1.
> a = b " => true (a and b have the same content)".
> a == b "=> true (ie, they are the indentical object)".
>
> "but"
>
> a ++. "hypothetical"
> a = b "=> ??, probably false".
> a == b " => ??, can't think of that".
>
yes, because variables in smalltalk are references to objects. and
variables in C are memory pointers.
A ++ operator is evil, because you cannot override or redefine it
(like any other message). And it works only for numbers (no pointers
in smalltalk)
and so, completely falls out of object model.
>
> So Long,
> -Tobias
>
--
Best regards,
Igor Stasenko AKA sig.