Any ideas for a new language inspired to Python?

2QdxY4RzWzUUiLuE at potatochowder.com 2QdxY4RzWzUUiLuE at potatochowder.com
Sun Aug 9 22:19:14 EDT 2020


On 2020-08-10 at 09:02:57 +1000,
Chris Angelico <rosuav at gmail.com> wrote:

> If you *really* want to get away from ints-as-objects, what I would
> recommend is emulating it. Some languages pretend that everything's an
> object, but for small integers (say, those less than 2**60), it
> doesn't store the object itself, it just stores the integer (with the
> low bit set, for example). It requires special-casing integers
> *everywhere* in the language executor (interpreter/compiler), and in
> return, you get to save about 20 bytes per integer compared to the way
> CPython does it. Is that worth it?

As always, it depends.

The special casing to which Chris referred is no worse than the special
casing that has to happen for every arithmetic operation anyway.  How
does Python calculate a * b?  Well, it depends on the type of a and the
type of b, and then dispatching to a special case multiplication
routine.  All that boxing and unboxing (pulling the actual values out of
the objects, creating new objects, memory management, etc.) can add up,
too.

If my application deals with arithmetic on millions or billions¹ of
small integers (say, those less than 2**60), then it can make a big
difference.  ;-)

¹ whether a billion is 1e9 or 1e12


More information about the Python-list mailing list