C++
Peter da Silva
peter-200306 at taronga.com
Sat Jul 19 12:39:51 PDT 2003
David Leimbach wrote:
>int a,b,c;
>...
>a = b + c;
>Integer d, e, f;
>d = e + f; //implicit temporary between the result of e and f being
>assigned to d?
> //can the compiler optimize this away?
>
>Basically you have a similar situation where the compiler doesn't know
>that the way you overloaded the
>operators even does what addition does.
I think the biggest mistake in any language that's trying to be a full blown object oriented language is to have anything that's not an object. I supposed C++ can be excused this, because it started out as a preprocessor for C, but there's no excuse for integers in Java not being full blown objects.
Why? Because when you need a full blown object, you have to create one, and all of a sudden all that work that's been put into the common case to make it run fast gets lost.
In Smalltalk, all those variables are objects, but the compiler can still generate one or two instructions with no "object" level operations for a = b + c.
And it can even do it in a lot of cases where you'd have expected a method send.
So to answer the earlier question... Smalltalk would be an interesting alternative. :)
More information about the Kernel
mailing list