A long long time ago, I started with Python 1.5 at web.de, founded the MoinMoin wiki project shortly thereafter, and am now enjoying the increased traction that Python recently gets from data science.
Because the number of code paths is reduced, and the intent of the code is way more clearer (get me a parser for this format). The code is actually simpler, because less chance for the unexpected.
Complexity is not just what is, but what could be.
I have nothing against elifs, it's a powerful and useful tool. And I use it a lot in my projects. But when I see 4-5 or more of them - Idk, it makes me cringe. Dictionary can help with that giving you a neat structure of what to do when you have this condition.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I still don't really understand why
elif
orelse if
smells, when dictionary with functions just make the code more complicated.Danger 1 - Dictionary with non-function gets compiled
Danger 2 - not in Python. Fall through in switch case statement
Because the number of code paths is reduced, and the intent of the code is way more clearer (get me a parser for this format). The code is actually simpler, because less chance for the unexpected.
Complexity is not just what is, but what could be.
I have nothing against
elif
s, it's a powerful and useful tool. And I use it a lot in my projects. But when I see 4-5 or more of them - Idk, it makes me cringe. Dictionary can help with that giving you a neat structure ofwhat
to do when you havethis
condition.