Vocabulary I don't understand

Hello,

I’m not really understanding some of the vocabulary used in the lessons for Bulls and Cows. My confusion also increases because I don’t know if certain words are synonyms. While I’ve tried looking online, I feel like I’m in the Matrix when I do.
Here is a list of the vocabulary I don’t understand. If you know the definition: please state it, give an example, and whether it connects with any other word on the list.

  1. Class:
  2. Object:
  3. Variable:
  4. Instance:
  5. Constructor:
  6. Initializing:
  7. Instantiating:
  8. Declaring:

I am getting pretty confused (so it’s hard to continue learning), so thank you for any help! :+1:

Thank you so much,
Enrico

1 Like

You can internet search all of these things to learn more or grab a book. I just put this together quickly. The only real way to begin to understand these things is to just start writing code, because do to nearly everything, you will be forced to work with these things.

Class: Probably nothing stops you from creating 1 million lines of code in 1 class but it would be really difficult scrolling up and down finding stuff. So a class allows you to break apart stuff in a way that functions cannot. Classes are nice when they are kept to a few hundred lines of code or less.

As an example of making two classes, if you have code that deals with alarms, you can put that into a class named lets say Alarms and then you can have a class called CharacterAI that uses class Alarms to set, trigger, or whatever an alarm. You can by all means have all the alarm code in CharacterAI class but then say you have building alarms now what? To have alarms all over the place is confusing so you have class named Alarms and can even have multiple classes for alarms such as AlarmTrigger, AlarmDisable, AlarmEnable, etc. Now you can quickly find what you want, use, and can quickly fix bugs, etc. But you can just have one Alarms class and that may be fine. That is subjective to each person. Whatever you do is up to you.

Object: Can be nearly anything. Object oriented programming. We create objects all the time as as in real life, a car is an object and is also made up of other objects and those objects are made up of objects too.

Variable: int i is a variable as in it can change. We can give it another value.

Instance: https://stackoverflow.com/questions/22206044/difference-between-object-and-instance-c Maybe best to say you have one instance of something. If you create a new one of that thing then you have another instance of it. Even an application can have multiple instances so that it was opened 2+ times and you see double or triple but can do something different in each instance (if it were designed to be able to - most applications are single instance).

Constructor: You can use, you don’t have to use. Its just the first place to setup some stuff when a class object is created if wanting (or if possible) to do that there.

Initializing: Give something a value or make it useful. Its like a house without people which is only actually useful when there are people using it. You can declare a house but without people its useless and that can be a problem.

Instantiating: To create a new instance of or new object of. I find it quite worthless to have a word for this but someone felt its worth it lol.

Declaring: int i is declaring that there’s an int of i. And then to initialize it would be to give it a value.

@QueueButton Thank you so much.
So what I got from your answer is that:

  • Classes are just a way to organize code or “encapsulate” it.
  • Objects can be anything, but can you give me an example (in code, not just an analogy please)? Using your analogy: if a car is a class is the car also an object? Also, if the speedometer is a variable does that also make it an object? In int speedometer; is int the object or is speedometer the object?
  • And after looking at the Stack Overflow link, what is a type?
  • Also, is the constructor just another way to encapsulate code? Based on the Bulls and Cows game that’s what I’m understanding.

Everything else I understand so so much better. Anyways, I’ll continue practicing in hopes that I’ll get better!
Thank you again, :wink:
Enrico

  • Classes are a way to define your own type, for example you could have a Person class that represents a person, it could store their name, age, address, etc.
  • Obect: There’s the C++ definition of an object which is just some region in memory that holds some value of some type. e.g.
    int i  = 42;
    
    i would be an int object.
    Then there’s the Object Oriented Programming definition which is just an instance of a class. C++ calls them “objects of class type”.
  • Instance: same thing as above
  • Constructor is something classes have which constructs an object of that type.
    std::string Name = "Dan";
    
    Will call one of std::string's constructors
  • Initialisation giving the object a value when it is created.
  • A type defines what values a variable can hold and the operations performed on it. e.g.
    int a = 1 + 2;
    std::string s1 = "hello";
    std::string s2 = ", world!";
    std::string s3 = s1 + s2; 
    
    For + on two int's does addition, whereas + on two std::strings performs concatenation.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.