[Python-ideas] non-Pre-PEP: Syntactic replacement of built-in types with user-defined callables (Take 2... fewer newlines!)

Jim Jewett jimjjewett at gmail.com
Tue Jan 29 14:34:32 CET 2008


On 1/28/08, Talin <talin at acm.org> wrote:
> Taro wrote:
> > Built-in types such as float, string, or list are first-class citizens ...

> >     myfloat = 1.0

> > User-defined classes are second-class citizens, requiring data to be
> > manually converted from a type:
> >     mydecimal = Decimal("1.00000000000000001")

> The problem I see with this is, what if you need to use both decimals
> and floats together?

Then don't overwrite the float type.  :D

> I've often thought that there should be a shorter spelling for decimal
> numbers, but I was thinking that a simple suffix letter would suffice:

>      mydecimal = 1.0000000000000001d

That solves a slightly different problem.  It expands the set of known
types to include Decimal, but it doesn't let you say:

    For this run, make all strings be instances of MyString,
    which is a string subclass with extra logging to help me debug.

> And if you really are suffering repetitive strain injury from having to
> type 'OrderedDict' 100 times in your code, it seems to me that you could
> just avoid creating each one individually, and instead have an array of
> inputs which gets converted to an array of OrderedDict.

When I have wanted this, I didn't have an array; I had existing code
with string literals sprinkled throughout.  I wanted to minimize
(diff-visible) changes because I knew I would back them out once the
debugging or testing were done.

-jJ


More information about the Python-ideas mailing list