An Epistle On An “oh Duh” Moment I Just Had While Pondering Switch Functionality In Python.

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.

More Posts from Cssengineer and Others

3 years ago

Update: While fun and neat, I still have yet to find a suitable hobbyist use case for Go. 


Tags
10 months ago

Update: I never even gazed at the pond. And I do not intend to.

It’s high time I dip my toes into Rust


Tags
4 years ago

Looking at you, C++

I won't ever take you back.

And yet it hurts that you don't even want me to.

4 years ago

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.


Tags
4 years ago

The MySQL dolphin is adorable


Tags
5 years ago

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.

5 years ago

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.


Tags
3 years ago

LEDs are a critical component for any workflow


Tags
4 years ago
Went To React’s Website To Learn The Tic Tac Toe Tutorial (it’s About Time I Got Around To It) And

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. 


Tags
Loading...
End of content
No more pages to load
  • estrapaded
    estrapaded liked this · 3 years ago
  • jsttsj
    jsttsj liked this · 3 years ago
  • psychopathofhearts
    psychopathofhearts liked this · 3 years ago
  • lowercase-morass
    lowercase-morass reblogged this · 3 years ago
  • noor1109
    noor1109 liked this · 4 years ago
  • ptstd
    ptstd liked this · 4 years ago
  • inner-creative
    inner-creative liked this · 4 years ago
  • yourdailydoseofmisery
    yourdailydoseofmisery liked this · 4 years ago
  • castelann
    castelann liked this · 4 years ago
  • cornbreadcommunard
    cornbreadcommunard liked this · 4 years ago
  • marknicol
    marknicol liked this · 4 years ago
  • eldritch-horror-faggot
    eldritch-horror-faggot liked this · 4 years ago
  • radkittyphantom
    radkittyphantom liked this · 4 years ago
  • morbidnova
    morbidnova liked this · 4 years ago
  • onehellofashipper
    onehellofashipper liked this · 4 years ago
  • cssengineer
    cssengineer reblogged this · 4 years ago
cssengineer - An Agitated Programmer
An Agitated Programmer

he/himComplaining on Tumblr is a good alternative to punching my computer screen, right?

72 posts

Explore Tumblr Blog
Search Through Tumblr Tags