RosettaCode factorial needs to use longs

bearophile bearophileHUGS at lycos.com
Sun Mar 9 03:28:34 PDT 2014


Russel Winder:

> That page appears to quietly ignore the fact that those 
> languages that
> use hardware integers cannot correctly compute factorial(25),

The D entry has the same problem. But a pre-condition could be 
added to limit the input.


> I wonder though if it would be better to split the examples up 
> rather
> than have a single entry. Nothing to do with the code content 
> just to do
> with the visual perception. The D code looks big and so bad, 
> whereas
> those that split up the examples look small and so good. Can I 
> suggest
> partitioning the D entry into four sub entries so as to make it 
> clear
> that explicit iteration, implicit iteration, recursion and tail
> recursion are all covered?

OK, I will split the D entry in four parts, but I think an 
average programmer is able to see that code is made of four 
separated functions that do the same thing in different ways and 
it's not a single large chunk of code needed to do the task. 
That's why I didn't bother with four entries.

(In Rosettacode some D entries are designed to be very short and 
sweet, other to be very fast, other to show the kind of elaborate 
code full of static typing and run-time tests you use in a piece 
of code that should be correct, and so on. So the code style 
varies on purpose to show various ways to write D. You can see 
this in the N-Queens problem D entries and elsewhere).

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list