On Sat, Mar 1, 2014 at 10:06 AM, Marko Rauhamaa <ma...@pacujo.net> wrote: > A colleague of mine taught me decades back that the whole point of OO > was the avoidance of if and switch statements. So if your code has an if > or switch statement, chances are you are doing something wrong.
This sounds like a classic case of a useful observation being taken out of context. On of the standard mantras about OOP is that you should not "use code to find code". By that, they mean, you should not do things like (pseudo-code): if type(obj) == Foo: frobnicate_with_foo(obj) else if type(obj_ == Bar: frobnicate_with_bar(obj) else: frobnicate_with_other(obj) But rather, you should let the class dispatch machinery handle figuring out which version of frobnicate() to call. That's a reasonable statement, but somehow that seems to have gotten twisted into, "If you're doing OOP, you should never have any 'if' statements". -- https://mail.python.org/mailman/listinfo/python-list