sa2c / python-oop-novice

An introduction to object-oriented programming for Python users in research
https://sa2c.github.io/python-oop-novice/
Other
1 stars 5 forks source link

Non-actionable information about protocols #23

Open chillenzer opened 1 year ago

chillenzer commented 1 year ago

The information in "Duck Typing"'s section "Protocols" doesn't really sound actionable to me. What am I supposed to learn from this? And how can I apply this afterwards? As far as I know, Python doesn't have anything to enforce or abide by protocols explicitly (except for static typecheckers of course), so all you can do is know about it and do my very best to abide by protocols. Could we have this more actionable in some form?

Relatedly, using the Iterator protocol suggests that it could be about figuring out if something is iterable, which is surprisingly challenging/easy (depending on your allowed toolbox) to do reliably due to the different ways of being iterable.

chillenzer commented 1 year ago

Okay. Should've read on where you are heading there. Abstract classes are an option but not a great one because you don't get the duck typing anymore.

edbennett commented 1 year ago

I think the intended action here is to recognise the term "protocol" when the Python docs (or anyone else) use it, and be able to implement a protocol. There could potentially be another challenge around implementing another protocol if we can find a reasonable one—the problem starts to be come that understanding the problem to be solved and the protocol each become a non-trivial amount of work, even without starting the implementation.

I agree on ABCs not always being great, as duck typing is indeed nice.