Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The primary reason to make YoutubeSearch a class is, in the future, implementing searching other video sites and taking advantage of inheritance in the implementation. That isn't demonstrated here, but the plumbing of "doing a request", "providing an iterator" and such could be promoted to the base class and subclasses are only responsible for knowing their domain.


YAGNI and besides you can still provide two layers of access, one being convenience functions on top of the class implementation.


Having YoutubeSearch be a class doesn't really bother me, especially since the point of the post was to demonstrate the use of __ methods, and you can't do that if you're using a method instead.

However, I discourage promoting inheritance (except in the guise of mixin, and even then...) as a way to factorize common functionalities. Composition is usually much better suited.


When you actually want to implement those other sites, you can replace the function by a class with a __call__ method.


There's no practical difference between a method and a class in this case.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: