0

I'm just really curious because some codes really follow a format like this. Examples include serial.begin(), serial.println() and when I used servomotors the left part was the name of the servomotor, which I declared. I want to know what concept does the code with a format of Text1.Text2() refer to? What do you call Text1 and Text2? Are there official or commonly used terminologies for the concepts and parts such as "variable", "statement", "code"?

To add to my understanding, it appears that Text1 refers to an object and that Text2 has the concept of "function" where it performs something related to the object. Though I would think that another terminology would be possessed by Text2 other than function to distinguish it from a function since it is required to be written in the format I mentioned, which next to the object with a period separating them and no spaces at all.

7
  • the names differ amongst different programming languages ... your question has nothing to do with the Arduino, so it is off topic here .... look at details about a programming language of interest ... see what the names are
    – jsotola
    Mar 25, 2021 at 4:30
  • w3schools.com/cpp/cpp_classes.asp
    – jsotola
    Mar 25, 2021 at 4:38
  • @jsotola: It's not mainly the names that differ, but their semantic meaning. What Text1.Text2() could mean differs greatly by language, even if this may be a syntactically valid statement in many languages.
    – PMF
    Mar 25, 2021 at 6:31
  • Text1 is an instance of some class xxx; xxx::Text2() is it's method function.
    – KIIV
    Mar 25, 2021 at 7:16
  • 1
    As @KIIV wrote, the overall concept is the class concept. A class is the build description of an object with its own member functions and member variables. From a class you can declare instances as variables in your code. Thats, what Text1 is here: An instance of a class. Text2() in turn is a member function of that class, which can act upon the variables of that particular instance. You can google tutorials about C++ classes to find out more. Note, that in C/C++ classes and structs are very similar. So you use a similar syntax to refer to member variables of a struct instance.
    – chrisl
    Mar 25, 2021 at 8:00

1 Answer 1

1

The over-arching concept is Object Oriented Programming (OOP).

The terms I was taught at University - taking Serial.println() as an example:

  • Serial is an instance of a class (in this case HardwareSerial), sometimes called an object.
  • println() (a function in a class) is a method of a class.
  • A "variable" in a class is called a property of a class.

A commented code example:


class Foo { // This is the *class*

    public: // These symbols are accessible from outside the class

        int bar; // This is a public property

        void baz() { ​// This is a public method
        }

    private: // These symbols are only available from inside the class

       ​int meep; // This is a private property

       ​void moop() { // this is a private method
       }
};


Foo bar; // Instantiate an instance of the Foo class and call it bar.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.