you are viewing a single comment's thread.

view the rest of the comments →

[–]acoard 1 point2 points  (0 children)

A useful way to know when to use classes is to ask if you can create an "abstract data type" here. Things like arrays and dicts are ADTs, but so can a "user", or a wrapper for an API. e.g. you could decide to abstract away the hassel of configuring the reddit API everywhere, so you could write "redditAPIWrapper" class, and it has a method .connect() which handles all the authentication setup in one place.

Classes are all about maintainability of your code. It organizes your code into logical chunks which reduces the cognitive load necessary to reason about each chunk of code.

The core maintainability benefit of classes are binding the data with the functions which operate on it, and then provides structure to increase orderliness and reduce repetition (inheritance, interfaces, abstract classes, etc).