How about adding rational fraction to Python?

Arnaud Delobelle arnodel at googlemail.com
Tue Feb 26 10:44:03 EST 2008


On Feb 26, 2:45 pm, Carl Banks <pavlovevide... at gmail.com> wrote:
> On Feb 26, 9:29 am, "D'Arcy J.M. Cain" <da... at druid.net> wrote:
>
> > On Tue, 26 Feb 2008 08:55:22 -0500
> > "J. Cliff Dyer" <j... at sdf.lonestar.org> wrote:
>
> > > Of course.  That's why I think you ought to spell it 3//4.  Nobody gets
> > > confused when a strange operator that they've never seen before does
> > > something unusual.  Average Jo off the street looks at python code and
> > > sees 3/4, and immediately thinks "aha! .75!"  Show the same person 3//4,
>
> > Why do we care what A. Jo thinks?  I would hope that A. Programmer Jo
> > would see "int {OP} int" and assume int result.
>
> There's no reason why int op int would imply an int result.  It's only
> a convention in some languages, and a bad one.
>
> > A. Jo isn't going to be
> > debugging anything.
>
> > If 3/4 ever returned 0.75 in any language I would drop that language.
>
> Have fun dropping Python, then, chief.  Integer division with / is
> already deprecated, can be disabled ever since Python 2.4, and will be
> wholly removed in Python 3.0.
>
> Carl Banks

And of course A. Jo will love this:

Python 3.0a1+ (py3k:59330, Dec  4 2007, 18:44:39)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 3/5
0.59999999999999998

On a more general note, though, I believe that integer division is a
more important concept to CS than 'near exact' division.  CS deals
mainly with discrete objects (and one might say exclusively, given the
digital nature of modern computers), and integers are the more natural
numerical objects to associate with discrete things.  As with the
soccer example given by D'Arcy J.M. Cain, many objects can't be
chopped in halves or quarters (especially in CS) therefore float
division is no meaningless to them.

--
Arnaud




More information about the Python-list mailing list