[Python-3000] String literal representation of integers (octal/binary discussion)

Patrick Maupin pmaupin at gmail.com
Mon Mar 19 02:28:25 CET 2007


On 3/18/07, Thomas Wouters <thomas at python.org> wrote:
> On 3/18/07, Patrick Maupin <pmaupin at gmail.com > wrote:

> I don't think this is the right term. It's certainly confusing, considering
> "string literals" are the stuff in quotes. A less confusing name is just
> 'integer literals'.

OK, if it is agreed that 'literals' is not confusing in a PEP title.
Like most English words, 'literal' has multiple meanings, and many
English speakers seem to believe that "literally" means something
entirely different.

>
> >     - There is a strong desire for binary support in the language.
>
> I have yet to see this 'strong desire'. I've seen people remark that they
> think it'd be nicely symmetric, but requests for actual usecases have always
> gotten low responses, as far as I remember. I've done quite a bit of
> bitfiddling with Python, with the struct module or with hexadecimals and
> bitwise operations, and in none of those cases would a binary literal have
> been helpful; they're way too verbose and impossible to get right/debug.

I have personally written output functions for this multiple times, as
apparently, have several others.  The discussion about PEP3101 didn't
seem to have any detractors, so binary is apparently going to be
supported for output.

Also, as many in the discussion pointed out, it's precisely this
reason (impossible to get right/debug) which is why you might want to
cut and paste a literal from, e.g. a register document, but
(admittedly) the use case for input is not as strong as the case for
output, until you throw the symmetry argument in.

> > But the Python community has its share of minimalists (each with
> > his own idea of the proper subset), so, for example, Mattias
> > Engdegård wrote: "only decimal, hex and binary constants are
> > of general use at all" while Thomas Wouters opined that octal
> > and hexadecimal should remain but binary was only for misguided
> > students doing their homework.
>
> This strikes me as a rather snide and childish paragraph -- and not just the
> part about me, which you got wrong. What I said was "they're invariably new
> programmers tackling the problem as an exercise, or trying to get at the
> 'pure bits' of an int to perform bitwise operations in an inefficient
> manner."

The point of the paragraph was to illustrate that there is not 100%
convergence on the required set of supported bases, and I think you
are currently proving that point for me quite handily. :)  I wasn't
trying to be snide, but I was trying to condense what you said a bit.
(As you note later, the document is already quite long!) To me, a "new
programmer tackling the problem as an exercise" infers somebody doing
(either mandated or self-inflicted) homework.  I can take it out or
try again.

> > So, in general, humans communicate "normal" (non-computer)
> > numerical information either via names (AM, PM, January, ...)
> > or via use of decimal notation.  Obviously, names are
> > seldom used for large sets of items, so decimal is used for
> > everything else.  There are studies which attempt to explain
> > why this is so, typically reaching the expected conclusion
> > that the Arabic numeral system is well-suited to human
> > cognition. [3]_
>
> I'm not sure why all this matters to the PEP, really. Do we really have to
> justify having decimal, hexadecimal and octal literals? It's _way_ oversized
> if you ask me :)

There was some apparently serious discussion about "Hey, why not just
support ALL the bases?"

I agree that the PEP is quite large, which is why the rationale is at
the end.  But the discussion had several passionate people (with valid
points!) arguing things like the number of supported radices and
whether 0123 should be a decimal number, so when Guido said:

Great! Mind writing up writing up a PEP that summarizes the discussion
(a bit)? In particular it should explain (a) why we need octal
literals; (b) why leading-zero is bad; (c) why we don't need general
bases; (d) why 0t is the best choice. Oh, and please add 0b too;
there's no formal proposal for that yet. Thanks!

(some of which, as you can see, has already changed since he wrote
this) I wanted to try to capture all sides of the discussion, as much
as possible, so that when somebody asks a question about why we did or
didn't do something, we can truthfully say that the PEP answers their
question.

Thanks,
Pat


More information about the Python-3000 mailing list