On 16/02/2021 05:45, Christopher Barker wrote:
Still OT ...
But I do think you need to consider not just your editor -- if
anyone else is going to read your code.
They're not (in any universe I can imagine).
Exactly -- the most important thing about style is that it be
consistent within a project's development team -- if that's just you,
then you're all set.
you also have other checks in there, so those would have to be
moved into the functions in the dict, maybe with wrappers (or not
-- depends on where you store some of that state data.
Exactly. Some wasted effort to turn a simple, contiguous,
transparent chunk of code into something more complicated, spread
out and harder to understand.
As i said -- depends on the rest of your code. It could make it less
spread out and easier to understand :-)
I don't understand how it could be less spread out when it starts as a
single contiguous piece of code. Perhaps I wasn't clear but when I said
"spread out" I meant multiple bits of code in different places in the
program. IOW how many parts it consists of (minimum = 1 = not spread
out at all).
For the most part using a dict to switch makes the most sense if the
same pattern will be used with multiple "switch dicts".
Again, turning simple straightforward into more complicated code.
(I'm quite capable of writing tricks like that *when I think
they're appropriate*; I've done it many times.)
I'm not sure I'd call it "tricks" -- but anyway, I've found that big
nested ifelses are rarely the cleanest solution -- but not never.
- Chris B.
--
Christopher Barker, PhD (Chris)
Python Language Consulting
- Teaching
- Scientific Software Development
- Desktop GUI and Web Development
- wxPython, numpy, scipy, Cython
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/python-ideas@python.org/message/WEHFV5TR5UZMV2QZE7AASFWDCJSAPHSE/
Code of Conduct: http://python.org/psf/codeofconduct/