[HN Gopher] Short Tutorial on Python's ChainMap
       ___________________________________________________________________
        
       Short Tutorial on Python's ChainMap
        
       Author : rcshubhadeep
       Score  : 24 points
       Date   : 2021-05-18 05:55 UTC (17 hours ago)
        
 (HTM) web link (pythonsbyte.substack.com)
 (TXT) w3m dump (pythonsbyte.substack.com)
        
       | cellularmitosis wrote:
       | Chainmap is nifty for implementing lexical scope in interpreters
        
       | wodenokoto wrote:
       | I like that the author starts with a use-case and then solves it
       | by using the class that the article sets out to introduce.
       | 
       | I do feel like the article lacks depth in describing what a
       | chainmap actually is, how I can be sure which key takes
       | precedence and lastly, I am not quite sure if I am convinced if
       | the method for sanity checking values scales very well.
        
         | angrais wrote:
         | Also to add: do people still use "isinstance" for comparing
         | types? Always has help like an antipattern to me.
        
       | ctur wrote:
       | This is not a well written article. The Python documentation
       | (https://docs.python.org/3/library/collections.html#collectio...)
       | is clearer.
       | 
       | TLDR from the docs: ChainMap groups multiple dicts or other
       | mappings together to create a single, updateable view.
        
         | TameAntelope wrote:
         | > It is often much faster than creating a new dictionary and
         | running multiple update() calls.
         | 
         | This is the important detail. This is much faster than how
         | you'd solve it pre-3.3.
         | 
         | I found myself wondering why this required a new class in the
         | stdlib until that line.
        
           | amelius wrote:
           | It would be nicer if Python just optimized the old way.
        
             | laurencerowe wrote:
             | Semantically they're not the same. In the 'old way' adding
             | a key to one of the original dicts does not change the new
             | dict. Whereas the new key will appear in the ChainMap.
        
       ___________________________________________________________________
       (page generated 2021-05-18 23:02 UTC)