On Wed, Aug 5, 2020, 10:38 <2QdxY4RzWzUUiLuE@potatochowder.com> wrote:
On 2020-08-04 at 10:58:51 -0400, Todd
wrote: My main issue with this is that, in my opinion, dunders are not something a beginner should be messing with anyway. By the time someone is experienced enough to start working on this, they are also experienced enough to understand that special cases like this exist for historical reasons.
Ouch.
Who am I to tell beginners what they should and shouldn't be messing with, and in what order? IMNSHO, history (let alone understanding it) comes *way* after writing a few dunders, even if you don't count __init__ as a dunder.
I should have been more clear, I was talking about these specific dunder methods. Overriding indexing isn't something that people will typically deal with before understanding the sequences indexing acts on, which is all they really need to understand to make sense of the current API. And history is hard to avoid. Why is it "def" instead of "function"? Why do dunder methods use "__" at all? Why does indexing use 0 instead of 1? Some things they are just going to need to accept are the way they are, and these are all things people are almost certainly going to need to encounter before making their own classes. Special cases aren't special enough to break the rules.
But they're aren't really any rules being broken here. It may be a sub-optimal solution in this case, but not a forbidden or even uncommon approach.