[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] people hating python for game dev.



Luke Paireepinart wrote:
> Ah, not to say anything negative about your code,
> since the number of opcodes is small,
> the whole "if -elif" branch (which in a C++ emu would probably be a switch)
> is okay because it's concise.
> However, in a larger subset of opcodes,
> it starts too look ugly and hard to manage.
> I know there's a more elegant approach to this,
> and I've thought about it a lot.

Just do a search for "switch" in the Python Cookbook
(http://aspn.activestate.com/ASPN/Cookbook/Python/) and it will show you
the usual patterns to replace a switch in Python.

The most common, AFAICS, is to put your the callbacks in a dictionary
and then look them up by opcode.

Chris