by __mharrison__ · 3y ago · 0 comments
I don't teach dataclasses until I teach intermediate classes because I like my students to understand decorators beforehand.
This make me wonder if I should experiment with teaching dataclasses instead of __init__ (and just hand-wave decorators and types)...
Sure technically (the best type of correct) it is not a constructor.
Where would this be important? Maybe it could be taught as part of "language lawyer" course.
I teach OOP around lesson 10. Each lesson is about 2hours.
Complete beginnners to programming are able create basic classes and even inheritance.
Some people like OOP some stick with imperative style. Some migrate to more functional style (which I personally advocate).
Going through this old thread: https://stackoverflow.com/questions/6578487/init-as-a-constr... puts me firmly into "this is hair-spliting" camp.
FAANG interviews?
Knowing that __new__() comes before __init__() is probably useful, as the deeper one gets into a language the more important it is to understand the lifecycle of an object. Otherwise, the only thing I can think of that's special is understanding that and how it works as a singleton.
In short this is irrelevant for those interviews. It’s definitely relevant if you do python as a day job.