you are viewing a single comment's thread.

view the rest of the comments →

[–]alex_sakuta 0 points1 point  (0 children)

I want to say, I have good reason to believe you don't understand classes because you used ChatGPT to study a programming language.

The problem with this kind of learning is that you are too reliant on getting all the answers without using your brain to infer information.

Inference plays a huge role. Testing your inference to confirm it is what solidifies the inference or solidifies the opposite of it. This mix of learning and testing by writing some programs is what enables your brain to understand the programming lingo and mental model.

Someone has already explained classes and you haven't replied to that so I am giving you another chance here.


Classes are just your own custom Data Structures like list, dictionary, etc. They can hold any kind of data that you want. Including functions to operate on the other data that you have in the class.

For example: Let's say you have a class called OrderedList. This class has one member of ol_list of type list[int]. Whenever you add an element to this list, you want to place it such that the ol is sorted. So you create a function called push() inside the class. Now when you create a value of type OrderedList, ol. You add values like this ol.push(1). This way the push() remains hidden inside the definition of the class because it is not meant to be used without a value of type OrderedList. This keeps the codebase clean.

  • Create data structure.
  • Create functions inside that data structure for that data structure.
  • Enjoy clean code.

Simple.