Dice gen and analyser script for RPGs: comments sought

Paul Rubin http
Wed Sep 6 02:50:49 EDT 2006


Richard Buckle <richardb at sailmaker.co.nospam.uk> writes:
> Comments, insights and overall evaluations are especially welcomed re:
> * Cleanliness of design
> * Pythonicity of design
> * Pythonicity of code
> * Efficiency of code
> * Quality of docstrings
> * Conformance with modern docstring standards
> * Conformance with coding standards e.g. PEP 8
> 
> I look forward to receiving your comments and criticisms.

I looked at this for a minute and found it carefully written but
somewhat hard to understand.  I think it's maybe more OOP-y than
Python programs usually are; perhaps it's Java-like.  There are some
efficiency issues that would be serious if the code were being used on
large problems, but probably no big deal for "3D6" or the like.  In
particular, you call histogram.numSamples() in a bunch of places and
each call results in scanning through the dict.  You might want to
cache this value in the histogram instance.  Making histogram a
subclass of dict also seems a little bit peculiar.

You might find it more in the functional programming spirit to use
gencomps rather than listcomps in a few places:

        return sum([freq * val for val, freq in self.items()])
becomes
        return sum((freq * val) for val, freq in self.iteritems())

etc.



More information about the Python-list mailing list