[Python-ideas] Allow attribute references for decimalinteger
Steven D'Aprano
steve at pearwood.info
Fri Nov 1 10:44:05 CET 2013
On Thu, Oct 31, 2013 at 04:10:46PM +0100, Ronald Oussoren wrote:
>
> On 31 Oct, 2013, at 15:35, Philipp A. <flying-sheep at web.de> wrote:
>
> > 2013/10/31 Greg Ewing <greg.ewing at canterbury.ac.nz>
> > In hindsight, things might have been better if the decimal point
> > were required to have at least one digit after it, but it's
> > probably too late to change that now.
> >
> > i disagree. i like writing “1.” for “float(1)” and “.1” for “1/10”. what’s the point of redundant zeros?
>
> Increased readability.
Then you might prefer writing 1.000000000000000000000000000000000 for
even more readability ;-)
But seriously... accepting "1." for float 1.0 is, as far as I can tell,
a common but not universal practice in programming languages. Being
tolerant of missing zeroes before or after the decimal point matches how
most people write, in my experience: dropping the leading zero is very
common, trailing zero less so, unless they drop the decimal point as
well. In a language like Python with distinct int and float types, but
no declarations, dropping the decimal point gives you an int. Not much
can be done about that.
As far as other languages go, ISO Pascal requires a digit after the dot,
but in my experience most Pascal compilers accept a bare dot: gpc
compiles "x := 23.;" but issues a warning. C appears to allow it: gcc
compiles "double foo = 23.;" without a warning. Ruby no longer accepts
floats with a leading or trailing dot.
Personally, I would never use "1." in source code, but I might use it in
the interactive interpreter. I think it's an issue for a linter, not the
compiler, so I'm happy with the status quo.
--
Steven
More information about the Python-ideas
mailing list