On 08/07/2010 11:16 PM, bearophile wrote:
Jonathan M Davis:
I would have thought that being more idomatic would have resulted
in slower code than what Walter did, but interestingly enough, both
programs are faster with my code. They might take more memory
though. I'm not quite sure how to check that. In any cases, you
wanted some idiomatic D2 solutions, so there you go.
Your code looks better.
My (probably controversial) opinion on this is that the idiomatic D
solution for those text "scripts" is to use a scripting language, as
Python :-)
In this case a Python version is more readable, shorter and probably
faster too because reading the lines of a _normal_ text file is
faster in Python compared to D (because Python is more optimized for
such purposes. I can show benchmarks on request).
On the other hand D2 is in its debugging phase, so it's good to use
it even for purposes it's not the best language for, to catch bugs or
performance bugs. So I think it's positive to write such scripts in
D2, even if in a real-world setting I want to use Python to write
them.
I think it's worth targeting D2 to tasks that are usually handled by
scripting languages. I've done a lot of that and it beats the hell out
of rewriting in D a script that's grown out of control
Andrei