Critic my module

Chris Angelico rosuav at gmail.com
Sat Jul 27 11:15:50 EDT 2013


On Sat, Jul 27, 2013 at 3:53 PM, Devyn Collier Johnson
<devyncjohnson at gmail.com> wrote:
> Would a Python3 game module be more useful? I plan to make a function that
> rolls a die and prints the output (You got a 5) and other similar random
> games.

Taking someone else's module and learning to use it has a cost. Plus
there's licensing and other issues (if you release your library GPL3,
you force anyone who uses it to do the same - though I'm not 100% sure
how that goes with Python modules, since they're not 'linked' the way
others are), not to mention the time spent finding out that your
module even exists. For a module to be useful, all those costs
combined have to be lower than the cost of just writing the code
yourself when you need it.

On the other hand, it's VERY common for a programmer to have his own
*personal* utilities module. Stuff stuff in there whenever you think
it'll be useful, import it into your applications, et voila. The bar
is way lower for that. Your dice-roller is perhaps useful to yourself,
without being worth the effort for someone else to learn. Plus, you
get to decide exactly how much flexibility you need. Do you only ever
need to roll a single six-sider at a time? Then don't bother
implementing stuff like I did for Minstrel Hall, where we play
Dungeons and Dragons:

[ROLL] Rosuav (Gaston crit dmg) rolls 4d8: 7, 3, 6, 1, totalling 17.
[ROLL] Rosuav (Gaston crit dmg) rolls d6: 1 (elec)
[ROLL] Rosuav (Gaston crit dmg) rolls d10: 6 (burst)
[ROLL] Rosuav (Gaston crit dmg) rolls d8: 8 (thunder)
[ROLL] For 4d8+12 STR+10 ench+4 specialization+d6 elec+d10 burst+d8
thunder+20 PA, Rosuav (Gaston crit dmg) totals: 78

Okay, that's a somewhat extreme example, but it's common to roll
damage as, say, 2d6+13, which means two six-sided dice plus a constant
13. (This will result in damage between 15 and 25, with 20 being
significantly more likely than either of the extremes.) And even that
is probably a lot more complicated than you'll need for your
purposes... yet for a D&D system, a dice roller that can only do a
single d6 at a time is utterly useless. There's actually a dice roller
module on PyPI already [1]; and it's probably of no use to you,
because it's as complicated as I described above. I personally
wouldn't use it, though, because I can't see a license - which comes
back to the issues I listed above. Again, not an issue for your own
code; if it's your copyright, you can do with it as you wish.

[1] https://pypi.python.org/pypi/diceroll

ChrisA



More information about the Python-list mailing list