14. OBJECT-ORIENTED PROGR AMMING AND CLASSES

OOP is a programming language feature that allows you to group variables and func- tions together into new data types, called classes, from which you can create objects. By organizing your code into classes, you can break down a monolithic program into smaller parts that are eas- ier to understand and debug.

For small programs, OOP doesn’t add organization so much as it adds bureaucracy. Although some languages, such as Java, require you to organize all your code into classes, Python’s OOP features are optional. Programmers can take advantage of classes if they need them or ignore them if they don’t. Python core developer Jack Diederich’s PyCon 2012 talk, “Stop Writing Classes” (https://youtu.be/o9pEzgHorH0/), points out many cases where pro- grammers write classes when a simpler function or module would have worked better.

That said, as a programmer, you should be familiar with the basics of what classes are and how they work. In this chapter, you’ll learn what classes are, why they’re used in programs, and the syntax and programming con- cepts behind them. OOP is a broad topic, and this chapter acts only as an introduction.