Python vs Ruby

Greg Jorgensen gregj at pobox.com
Mon Jan 29 18:36:36 EST 2001


In article <95438n$j2f$1 at tyfon.itea.ntnu.no>, "Magnus Lie Hetland"
<mlh at idi.ntnu.no> wrote:

> I know. I noticed after posting.
> (That's what you get for being cocky ;-)

I hate when that happens (to me).

> Well... I thought my version "correctly" disallowed 0 as an argument.

I wouldn't complain if you disallowed 0, but your code returns 1 for fib
(0). If you use the old definition where there is no fib(0), the
function should throw an exception. If you use the other definition
(the first hit I got when I used Google to look up fibonacci) fib(0)
should return 0. We should both throw exceptions for n < 0 (or 1 in
your case).

At least fib(0) = 0 doesn't break the sequence... fib(2)=fib(0)+fib(1)
iff fib(0) = 0.

> > And I avoid the range() call.
>
> Yes you do indeed. I guess I just dislike for-loops simulated
> by while-loops in generals <wink>, but in Python it seems it
> might actually be a good idea.

I would use a for loop if there was a form that didn't iterate over a
sequence when I just want to count from a to b. It's my years of
programming in C that prevents me from resisting the urge to decrement
a loop counter down to 0. And of course in C a for loop IS just a while
loop in fancy clothes.

> happy-to-spend-time-on-anything-useless'ly y'rs

Yeah me too.

--
Greg Jorgensen
Portland, Oregon, USA
gregj at pobox.com


Sent via Deja.com
http://www.deja.com/



More information about the Python-list mailing list