<p>Sponsored by Techmeme Ride Home podcast: <a href="http://pythonbytes.fm/ride"><strong>pythonbytes.fm/ride</strong></a></p> <p>Special guest: <a href="https://twitter.com/zooba"><strong>Steve Dower - @zooba</strong></a></p> <p><strong>Brian #1:</strong> <a href="https://www.cosmicpython.com/blog/2020-10-27-i-hate-enums.html"><strong>Making Enums (as always, arguably) more Pythonic</strong></a></p> <ul> <li>“I hate enums” </li> <li>Harry Percival</li> <li>Hilarious look at why enums are frustrating in Python and a semi-reasonable workaround to make them usable.</li> <li>Problems with enums of strings: <ul> <li>Can’t directly compare enum elements with the values</li> <li>Having to use <code>.value</code> is dumb.</li> <li>Can’t do random choice of enum values</li> <li>Can’t convert directly to a list of values</li> </ul></li> <li>If you use <code>IntEnum</code> instead of <code>Enum</code> and use integer values instead of strings, it kinda works better.</li> <li>Making your own <code>StringEnum</code> also is better, but still doesn’t allow comparison.</li> <li>Solution:</li> </ul> <pre><code> class BRAIN(str, Enum): SMALL = 'small' MEDIUM = 'medium' GALAXY = 'galaxy' def __str__(self) -> str: return str.__str__(self) </code></pre> <ul> <li>Derive from both <code>str</code> and <code>Enum</code>, and add a <code>*__str(self)__*</code> method.</li> <li>Fixes everything except <code>random.choice()</code>.</li> </ul> <p><strong>Michael #2:</strong> <a href="https://twitter.com/1st1/status/1318558048265404420">Python 3.10 will be up to 10% faster</a></p> <ul> <li>4.5 years in the making, from Yury Selivanov</li> <li>work picked up by Pablo Galindo, Python core developer, Python 3.10/3.11 release manager</li> <li>LOAD_METHOD, CALL_METHOD, and LOAD_GLOBAL improved</li> <li>“Lot of conversations with Victor about his PEP 509, and he sent me a link to his amazing compilation of notes about CPython performance. One optimization that he pointed out to me was LOAD/CALL_METHOD opcodes, an idea first originated in PyPy.”</li> <li>There is a patch that implements this optimization</li> <li>Based on: LOAD_ATTR stores in its cache a pointer to the type of the object it works with, its tp_version_tag, and a hint for PyDict_GetItemHint. When we have a cache hit, LOAD_ATTR becomes super fast, since it only needs to lookup key/value in type's dict by a known offset (the real code is a bit more complex, to handle all edge cases of descriptor protocol etc).</li> </ul> <p><strong>Steve #3:</strong> <strong>Python 3.9 and no more Windows 7</strong></p> <ul> <li><a href="https://www.python.org/dev/peps/pep-0011/">PEP 11 -- Removing support for little used platforms | Python.org</a></li> <li><a href="https://docs.microsoft.com/en-us/lifecycle/products/windows-7">Windows 7 - Microsoft Lifecycle | Microsoft Docs</a></li> <li>Default x64 download</li> </ul> <p><strong>Brian #4:</strong> <a href="https://www.davidpashley.com/articles/writing-robust-shell-scripts/"><strong>Writing Robust Bash Shell Scripts</strong></a></p> <ul> <li>David Pashley</li> <li>Some great tips that I learned, and I’ve been writing bash scripts for decades.</li> <li><code>set -u</code> : exits your script if you use an uninitialized variable</li> <li><code>set -e</code> : exit the script if any statement returns a non-true return value. Prevents errors from snowballing.</li> <li>Expect the unexpected, like missing files, missing directories, etc.</li> <li>Be prepared for spaces in filenames. <code>if [ "$filename" = "foo" ];</code></li> <li>Using <code>trap</code> to handle interrupts, exits, terminal kills, to leave the system in a good state.</li> <li>Be careful of race conditions</li> <li>Be atomic </li> </ul> <p><strong>Michael #5:</strong> <a href="https://twitter.com/anthonypjshaw/status/1318701123692236801"><strong>Ideas for 5x faster CPython</strong></a></p> <ul> <li>Twitter post by Anthony Shaw calling attention to <a href="https://github.com/markshannon/faster-cpython/blob/master/plan.md">roadmap by Mark Shannon</a></li> <li><strong>Implementation plan for speeding up CPython:</strong> The overall aim is to speed up CPython by a factor of (approximately) five. We aim to do this in four distinct stages, each stage increasing the speed of CPython by (approximately) 50%: 1.5**4 ≈ 5</li> <li>Each stage will be targeted at a separate release of CPython. </li> <li><strong>Stage 1</strong> -- Python 3.10: The key improvement for 3.10 will be an adaptive, specializing interpreter. The interpreter will adapt to types and values during execution, exploiting type stability in the program, without needing runtime code generation.</li> <li><strong>Stage 2</strong> -- Python 3.11: Improved performance for integers of less than one machine word. Faster calls and returns, through better handling of frames. Better object memory layout and reduced memory management overhead.</li> <li><strong>Stage 3</strong> -- Python 3.12 (requires runtime code generation): Simple "JIT" compiler for small regions.</li> <li><strong>Stage 4</strong> -- Python 3.13 (requires runtime code generation): Extend regions for compilation. Enhance compiler to generate superior machine code.</li> <li><a href="https://www.mail-archive.com/python-dev@python.org/msg110071.html">Wild conversation over here</a>.</li> <li>One excerpt, from Larry Hastings:</li> <li><em>Speaking as the Gilectomy guy: borrowed references are evil. The definition of the valid lifetime of a borrowed reference doesn't exist, because they are a hack (baked into the API!) that we mostly "get away with" just because of the GIL. If I still had wishes left on my monkey's paw I'd wish them away (1).</em></li> <li><ul> <li>(1) Unfortunately, I used my last wish back in February, wishing I could spend more time at home.*</li> </ul></li> </ul> <p><strong>Steve #6:</strong> <strong>CPython core developer sprints</strong></p> <ul> <li>Hosted by <a href="https://pythondiscord.com">pythondiscord.com</a></li> <li><a href="https://youtu.be/gXMdfBTcOfQ">https://youtu.be/gXMdfBTcOfQ</a> - Core dev Q&A</li> </ul> <p><strong>Extras</strong></p> <p><strong>Brian:</strong></p> <ul> <li>Tools I found recently that are kinda awesome in their own way - Brian <ul> <li><a href="https://mcbroken.com/">mcbroken.com</a> - Is the ice cream machine near you working? <ul> <li>just a funny single purpose website</li> </ul></li> <li><a href="https://vim-adventures.com/">vim-adventures.com</a> - with a dash. Practice vim key bindings while playing an adventure game. Super cool. </li> </ul></li> </ul> <p><strong>Joke:</strong></p> <p>Hackobertfest 2020 t-shirt <a href="https://twitter.com/McCroden/status/1319646107790704640">https://twitter.com/McCroden/status/1319646107790704640</a> </p> <p><img src="https://ift.tt/357LYVU" alt="Image" /></p> <ul> <li><a href="https://levelup.gitconnected.com/5-most-difficult-programming-languages-in-the-world-549c3cf91b23">5 Most Difficult Programming Languages in the World</a> <ul> <li>(Not really long enough for a full topic, but funny. I think I’ll cut short the last code example after we record)</li> <li>suggested by Troy Caudill</li> <li>Author: Lokajit Tikayatray</li> <li>malboge, intercal, brainf<em>*</em>, cow, and whitespace</li> <li>whitespace is my favorite: “Entire language depends on <em>space</em>, <em>tab</em>, and <em>linefeed</em> for writing any program. The Whitespace interpreter ignores Non-Whitespace characters and considers them as code comments.”</li> <li>Intercal is kinda great in that </li> <li>One thing I love about this article is that the author actually writes a “Hello World!” for each language.</li> <li>Examples of “Hello World!”</li> <li>malboge</li> </ul></li> </ul> <pre><code> (=<`#9]~6ZY32Vx/4Rs+0No-&Jk)"Fh}|Bcy?`=*z]Kw%oG4UUS0/@-ejc(:'8dc </code></pre> <ul> <li>intercal</li> </ul> <pre><code> DO ,1 <- #13 PLEASE DO ,1 SUB #1 <- #238 DO ,1 SUB #2 <- #108 DO ,1 SUB #3 <- #112 DO ,1 SUB #4 <- #0 DO ,1 SUB #5 <- #64 DO ,1 SUB #6 <- #194 DO ,1 SUB #7 <- #48 PLEASE DO ,1 SUB #8 <- #22 DO ,1 SUB #9 <- #248 DO ,1 SUB #10 <- #168 DO ,1 SUB #11 <- #24 DO ,1 SUB #12 <- #16 DO ,1 SUB #13 <- #162 PLEASE READ OUT ,1 PLEASE GIVE UP </code></pre> <ul> <li>brain**ck (censored)</li> </ul> <pre><code> ++++++++++[>+++++++>++++++++++>+++<<<-]>++.>+.+++++++ ..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+. </code></pre> <ul> <li>cow</li> </ul> <pre><code> MoO MoO MoO MoO MoO MoO MoO MoO MOO moO MoO MoO MoO MoO MoO moO MoO MoO MoO MoO moO MoO MoO MoO MoO moO MoO MoO MoO MoO MoO MoO MoO MoO MoO moO MoO MoO MoO MoO mOo mOo mOo mOo mOo MOo moo moO moO moO moO Moo moO MOO mOo MoO moO MOo moo mOo MOo MOo MOo Moo MoO MoO MoO MoO MoO MoO MoO Moo Moo MoO MoO MoO Moo MMM mOo mOo mOo MoO MoO MoO MoO Moo moO Moo MOO moO moO MOo mOo mOo MOo moo moO moO MoO MoO MoO MoO MoO MoO MoO MoO Moo MMM MMM Moo MoO MoO MoO Moo MMM MOo MOo MOo Moo MOo MOo MOo MOo MOo MOo MOo MOo Moo mOo MoO Moo </code></pre> <ul> <li>whitespace</li> </ul> <pre><code> S S S T S S T S S S L T L S S S S S T T S S T S T L T L S S S S S T T S T T S S L T L S S S S S T T S T T S S L T L S S S S S T T S T T T T L T L S S S S S T S T T S S L T L S S S S S T S S S S S L T L S S S S S T T T S T T T L T L S S S S S T T S T T T T L T L S S S S S T T T S S T S L T L S S S S S T T S T T S S L T L S S S S S T T S S T S S L T L S S S S S T S S S S T L T L S S L L L </code></pre> <ul> <li><a href="https://en.wikipedia.org/wiki/APL_(programming_language)"><strong>APL</strong></a>: <code>(~R∊R∘.×R)/R←1↓ιR</code></li> </ul>
from Planet Python
via read more
Subscribe to:
Post Comments (Atom)
TestDriven.io: Working with Static and Media Files in Django
This article looks at how to work with static and media files in a Django project, locally and in production. from Planet Python via read...
-
Podcasts are a great way to immerse yourself in an industry, especially when it comes to data science. The field moves extremely quickly, an...
-
Graph traversal algorithms are used to perform various operations on a graph data structure. In this article, we will use the breadth-first ...
-
In an earlier tutorial we've already covered how to open dialog windows. These are special windows which (by default) grab the focus o...
No comments:
Post a Comment