[HN Gopher] TypedDicts are better than you think
       ___________________________________________________________________
        
       TypedDicts are better than you think
        
       Author : rbanffy
       Score  : 43 points
       Date   : 2024-10-10 17:56 UTC (5 hours ago)
        
 (HTM) web link (blog.changs.co.uk)
 (TXT) w3m dump (blog.changs.co.uk)
        
       | jjtheblunt wrote:
       | "thank you think" in a title is overtly condescending...you know
       | your audience and their educational deficiencies?
       | 
       | "than i thought" would be compelling to read.
        
         | crazygringo wrote:
         | Yup, using "you" in headlines is a pattern that needs to die.
         | 
         | I get that it's attention-grabbing, but it's because it's rude.
         | 
         | You don't know anything about me. You don't know what I think
         | or what I already know or what I won't believe.
         | 
         | I know it's not a big deal in the grand scheme of things, but
         | it's just one of those little aggravating things that makes
         | life just a little bit worse each time you come across them.
        
         | lopatin wrote:
         | It's a qualifier. In a sense, they _do_ know their audience
         | fairly well because someone who clicks on that link is
         | intrigued and feel they have more to learn about it. Anyone who
         | is pretty knowledgeable about the subject will go  "pff .. yeah
         | right" and not even click on it.
         | 
         | That said, it does annoy me too.
         | 
         | Also what annoys me is that I constantly try to play devils
         | advocate for things like this even if I don't always agree with
         | the conclusion of the advocate.
        
         | tptacek wrote:
         | This is the kind of copyediting advice ChatGPT gives. I think
         | everyone gets that the author doesn't know what you, in
         | particular, think about TypedDicts. Read things more
         | charitably; this is not a good use of time to discuss.
        
       | benmmurphy wrote:
       | <Option<Option<subscription>>
        
       | miohtama wrote:
       | Reasons to use dataclass(slots=True) instead of TypedDict
       | 
       | - Faster attribute access: your code is faster
       | 
       | - Slotted classes take less RAM, less L1 cache pressure, your
       | code is faster
       | 
       | - Wrist friendly to with .foobar instead of ["foobar"]
       | 
       | - Runtime error if you misspell an attribute name
        
         | fovc wrote:
         | It's Python. Does L1 matter at all? I assume anything you're
         | accessing is behind a few pointers and __dict__ accesses
         | anyway.
         | 
         | For me it's mostly about .attribute being more in line with the
         | rest of the language. Kwargs aside, I find overuse of dicts to
         | clunky in Python
        
           | gshulegaard wrote:
           | Nope, __slots__ exist explicitly as an alternative to
           | __dict__:
           | 
           | https://wiki.python.org/moin/UsingSlots
           | 
           | Whether or not the performance matters...well that's somewhat
           | subjective since Python has a fairly high performance floor
           | which makes performance concerns a bit of a, "Why are you
           | doing it in Python?" question rather than a, "How do I do
           | this faster in Python?" most of the time. That said it _is_
           | more memory efficient and faster on attribute lookup.
           | 
           | https://medium.com/@stephenjayakar/a-quick-dive-into-
           | pythons...
           | 
           | Anecdotally, I have used Slotted Objects to buy performance
           | headroom before to delay/postpone a component rewrite.
        
       | fat_cantor wrote:
       | Sorry, I gotta: THAT'S WHAT SHE SAID!
        
       ___________________________________________________________________
       (page generated 2024-10-10 23:00 UTC)