How about adding rational fraction to Python?

Lie Lie.1296 at gmail.com
Tue Feb 26 09:59:44 EST 2008


On Feb 26, 9:02 pm, cokofree... at gmail.com wrote:
> > That's creepy for people that are new to programming and doesn't know
> > how CPUs work and are used to general mathematics. That means most
> > people. As programming language are now more accessible to regular
> > people without specialized Computer Science degree, it is a just
> > natural trend that computer arithmetic must be done in an expectable
> > manner as seen by those general population not by people who holds a
> > CS degree.
>
> Couldn't disagree with you more, the fact they don't specialise in
> Computer Science shouldn't be a reason to follow their "expected
> outcomes", they should be informed of the standard CS approach. I'm
> all for punishing people for making "well I thought it would always do
> the following..." thought process. The quicker they learn certain
> methods and expectations are wrong the quicker they get used to the
> proper thought patterns.

The problem lies on which maths is the real maths? In real world, 3/4
is 0.75 is 0.75 and that's an unchangeable fact, so programming
languages that do other things is either wrong or have their reason to
do that. Python, C, and other programming languages that uses integer
division by default choose to do default integer division because CPUs
execute integer division faster than floating division, but it doesn't
change the fact that 3/4 is equal to 0.75 but is not equal to 0.

I think a CS should understand that the choice of default integer
division was actually a workaround for the expensive operation, not
because 3/4 actually equals 0. As the more educated person, they
should still expect 3/4 to be 0.75 but could understand why if the
language they're using gives 0. Commoners are the less educated,
languages should appeal to as much people as it could, and giving 3/4
== 0 is the best way to confuse some people right away, instead giving
3/4 == 0.75 would just make the more educated CSs search for the
"regular"  division operator.

It is better to think this way:
CSs supposed brain thought:
try:
   print 3 / 4
except IntegerResult:
   print 'integer division workaround'
   if wants[floatdivision]: print 'searching for float division
operator'
   elif wants[integerdivision]: print 'that was already correct'

Commoner's supposed brain thought:
try:
   print 3 / 4




than this way:
CSs supposed brain thought:
try:
   print 3 / 4
except FPointResult:
   print 'This language is a jerk'

Commoner's supposed brain thought:
try:
   print 3 / 4

The first set of brain thought appeal to everyone, everyone is happy
with the result. The second set of brain thought kills a CS guy and
gives unhandled error to a commoner. DO you still think that default
integer division is better?



More information about the Python-list mailing list