An epistle on an “oh duh” moment I just had while pondering switch functionality in Python.
Every couple of months when I get back into some hobbyist Python development I find myself DuckDuckGo-ing “switch in Python” and am subsequently always reminded that that’s not explicitly a thing. You, of course, get that functionality from dictionaries.
I’ve always thought that was dumb, but today I was considering it and realized that it’s all because of the interpreted nature of the language. Switch statements have the wicked performance improvements over if ladders in compiled languages because the switch tells the compiler to put a bunch of branches in the intermediate assembly so a lot of unnecessary condition checks are skipped.
Without in-depth knowledge of how the interpreter works, it now becomes clear why you have to use the dictionary. It’s not the Python lords being pretentious and imposing their pythonic ways; you have to be more explicit to the interpreter about where to look for the logic to run because the interpreter doesn’t craft intermediate assembly, it just plows straight through. So a switch in Python would ultimately perform no better than an if ladder.
That doesn’t mean a switch wouldn’t make me happy, mind you.
Update: While fun and neat, I still have yet to find a suitable hobbyist use case for Go.
Update: I never even gazed at the pond. And I do not intend to.
It’s high time I dip my toes into Rust
Looking at you, C++
I won't ever take you back.
And yet it hurts that you don't even want me to.
Typing a paper for class and one of my subheadings reads, ”What’s the point of working?” And I didn’t think through how much that would affect my ability to write the rest of the essay.
The more I work with front-end dev the more respect I have for UX designers. It takes 2 hours for me just to make sure that when the window resizes I don’t lose all functionality.
I continue to be surprised today. Haskell is also cool, at least based on what I’m reading. I haven’t written any yet, though, so we’ll see.
Maybe I’m just in an open mood. Should I break out the old assembly docs and test that theory?
.... Nah, I definitely shouldn’t do that.
Went to React’s website to learn the Tic Tac Toe tutorial (it’s about time I got around to it) and was pleasantly surprised to see this. Way to go, React.
he/himComplaining on Tumblr is a good alternative to punching my computer screen, right?
72 posts