TumblrPulse

Your Window to Inspiration: Seamlessly Browse Tumblr!

Python - Blog Posts

4 years ago

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.


Tags
4 years ago

It’s interesting how as I’ve progressed as a programmer the things I turn to for therapy have also progressed. 

At first it was Scratch: after a span of getting frustrated by Python I would play with Scratch to at least make things that did what I wanted them to. 

A little while later I wrote HTML and CSS to feel good about myself, because even when the default padding for <body> screws up your positioning there’s at least SOMETHING on the screen instead of an aggressive error message.

Now, it’s python. When Scheme or Haskell or C or Java or C# (less so C# - it’s actually pretty nice) or even Javascript are bothering me I can always turn to Python to feel better. 

I wonder what it’ll be next? Maybe one day I’ll see C++ as my relief. Probably not. But maybe. Perhaps the final evolution of a programmer is when you can feel completely peaceful while writing Posix level C. Perhaps even assembly. Probably not. But perhaps.


Tags
5 years ago

I have so much respect for the ToString() method of Pandas Dataframes in Python.

If you’re wondering why, it’s because I’m currently trying to make a halfway decent depiction of a C# matrix multidimensional array that just puts my hashkeys in the right places and things are not going well at all. 


Tags
5 years ago
Django Actually Has A Built-in Tag Specifically For Generating The Latin Gibberish Used In Samples. They

Django actually has a built-in tag specifically for generating the latin gibberish used in samples. They already solved every real problem for developers, so they proceeded to solve problems you didn’t even know you wanted solved. 


Tags
Loading...
End of content
No more pages to load
Explore Tumblr Blog
Search Through Tumblr Tags