# Decimal arithmatic, was Re: Python GUI app to impress the boss?

Magnus Lyckå magnus at thinkware.se
Sun Sep 29 18:58:33 EDT 2002

```Steve Holden wrote:
> Of course, none of this is necessarily an argument that f-p is the *best*
> representation for money, but I'm always amused to see people arguing
> against it on general grounds when it's perfectly acceptable for many such
> purposes *when correctly used*.

My opinion is that Python has a lot of the features
required to become "the next COBOL".

Yes, I admit it sounds horrible, I hate COBOL as much
as anybody ;) but try to understand what I mean.

Python has the potential to be used to quickly and in
a practical way build millions of applications and tools
by people who aren't always from a CS, math or engineering
background.

Python also has the potential to become the next BASIC--a
simple language for education, autodidacts and power-users.

It can also become the next Pascal, but I don't think we
need to change any language features for that.

But to suit beginners and...well, amateurs...we need to
follow the principle of least surprise.

It IS surprising for a lot of people that
>>> 4/5
0.80000000000000004

You know that Steve, you see it here on c.l.py now and then.

It IS surprising for some people that for some numeric
values of 'w':
>>> 1+w+w+w+w == w+w+w+w+1
0

And
>>> 4/5
0

was certainly surprising for many, and that was
changed. The other big surprise was obviously

>>> w = 5
>>> print W
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
NameError: name 'W' is not defined

but that I think, is not so difficult to explain:
We don't consider w and W to be the same thing.
It's a design decision, and it could have been the
other way. Guido choose this way, just like he choose
= for assignment and == for equality, instead of
:= and = as in Pascal. End of story.

But we can't explain why floating point arithmetic
works the way it does without going into details the
groups I refer to feel that they shouldn't have to
understand.

It's a bit like demanding that a car driver understands
the physics and chemistry of combustion engines. You
can't sell a lot of cars if you need a degree in science
to drive them...

Or, to put it the other way around, you can sell a lot
more cars if people can drive them without a B.Sc, and
you can "sell" Python to a lot more people if they don't
need a B.Sc. to understand it...

On the other hand, I feel that when you make the tool
so simple that it can be handled by any fool, any fool
will be put in charge of the tool, and regardless of the
quality of the tool, they will make a mess because they
lack the required thinking ability.

In other words, we who actually understand computers and
problem solving will have to clean things up. But
a) I'd rather fix real logical problems in the business
sphere than correct trivial programming blunders, and
b) We shouldn't make life more difficult than needed for
those who are clever enough, but just don't have the
expertize in our field. Finally,
c) we don't think that pen and paper ought to be difficult
to use, so that people need to learn a lot of things
unrelated to the ideas they want to put in writing.

Maybe this not such a big issue as I sometimes think it
is, but I do feel that Python is way ahead of the
competetition from a pedagogic perspective in most cases,
but this is one where it's...average.

Perhaps the right trade-off is still to educate the
programmers, and to build tools or routines to prevent
problems. But I think the issue is worth discussing.

It seems to me that a really smooth handling of dates,
times and decimal numbers would make Python even more
useful for most people who don't program today, but
could benefit from it if they did...

--
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus at thinkware.se

```