[Tutor] creating classes while coding

Steven D'Aprano steve at pearwood.info
Mon Feb 21 12:44:04 CET 2011


Bill Allen wrote:
> I know that Python not only supports OOP, but is fundamentally OOP in its
> design.   Just in using the language and standard library, that much becomes
> obvious.   However, I do wonder a bit about the practice I have seen of some
> Python programmers to implement relatively short bits of code, that would be
> quite simple using functions and procedural code, with classes.   Some such
> code appears far more complicated than the job at hand really demands.   I
> know there is not always a single right or wrong way of accomplishing
> programming task, but why implement using classes unnecessarily?  When is it
> necessary?  When is it best practice?  I'll freely admit that I do not come
> from an OOP programming background, so designing classes is not my first
> impulse when writing code.  Am I missing something?


No, I don't think you're missing anything. Too many people come from 
Java, where (virtually) everything *must* be a class. There's a 
wonderful essay about the "Kingdom of the Nouns":

http://steve-yegge.blogspot.com/2006/03/execution-in-kingdom-of-nouns.html

Don't get me wrong -- object oriented programming has much to say for 
it, but it's not the be-all and end-all of programming. Python makes it 
easy to mix imperative, object-oriented and functional programming 
idioms into the one program. (The only major idiom that Python doesn't 
support well is logic programming, as used by Prolog.)



-- 
Steven


More information about the Tutor mailing list