The Benefits of C ++ as the First Language for Learning Programming

    Good day to all!

    This article is about why it is still worth choosing C ++ as the first programming language for teaching students, and a little about the problems of teaching at universities. Part of the judgment regarding the learning process is based on personal teaching experience (three years, while studying for graduate school), as well as on communication with teachers and students.
    The advantages of the C ++ programming language are considered specifically for training and from the point of view of a better understanding of the basic concepts. The remaining candidates for the role of the first language (Pascal / Python / C # / Java) are not considered, so as not to incite a holivar. I note once again: not for industrial development and not in terms of such a subjective criterion as convenience.
    It was written under the impression of a frankly advertising post “Delphi XE5 as the basis for teaching programming” (at the time of writing, only the “from Google” version is available ).

    0 Introduction


    To begin with, I would like to note that for students of non-specialized specialties the question of choosing the first programming language is not considered. The basics of algorithms (if necessary) can be mastered even in Python, even in C ++ (Java, C #, Pascal, etc.). In this case, the simpler the language, the better: it is necessary for people to form at least some culture of algorithmic thinking and understanding of basic constructions. For students of some specialties (legal, economic, humanitarian), the study of YP is not required at all.
    Despite the obviousness of the above, many first-year economics students are taught Pascal programming in computer science workshops. Students who still do not really know how to work with MS Word. The benefits of such activities are very, very doubtful. Likewise, math students can learn C ++ / C # / Java programming for a couple of years ... but why? It is much more useful for the subsequent application of your knowledge to study programs like Mathcad, Simulink, Surfer, etc.
    Given the above, we consider the process of choosing the first language exclusively for students of specialized specialties (for example, "Software Engineering") and mixed specialties with a bias towards IT (for example, "Applied Mathematics and Computer Science"). Firstly, the curriculum of such specialties involves a sufficient number of lectures and practices (since the first language is considered, only the first course is taken into account): for two related disciplines (computer science and programming) about 230 hours, depending on the specialty. Secondly, the presence of interest and a certain mentality among students. Such students most often already tried to program, and perhaps even wrote a website / toy. Together, these two reasons provide a good basis for starting learning and lowering the threshold for entering language training. Also, graduates of the specialties in question will have to work in the software development industry in the future. Therefore, the choice of the first language is especially important for them.

    1 Why C ++?


    In the first year, a basis for further education is laid and the student’s approach to further knowledge is formed. The programming language plays an important role here.
    There are four reasons for choosing C ++ as the first programming language:
    1. Compiled language with static typing.
    2. The combination of high-level and low-level tools.
    3. Implementation of OOP.
    4. STL.

    Consider these reasons in more detail.

    Compiler . Here C ++ appears in all its glory. Many compilers, console commands, stages of program assembly ... Yes, the first program needs to be written in a simple text editor without syntax highlighting and autocomplete, to find how and how to launch it. This approach forms a person’s understanding of how everything works:
    • Program code is just text that will not work on its own.
    • The compiler is a separate program, which must specify what and how to do with the source code so that it turns into an executable file. A text editor is also a separate program for writing source code.
    • There are build options, and there is more than one compiler.
    • The source code written by the programmer can be pre-processed and modified (for example, by a preprocessor).

    A future specialist will realize that the code itself does not start (in the future, it may be interested in how, for example, the Python interpreter or JIT compilation works). A person will ask himself questions: “Why?”, “What is the difference?”, “How?”. There will be no illusions that everything works by pressing two magic buttons or in the interactive command line. The student will know that the build process of the program can be customized and that the source code can be processed by third-party programs. In the future, when using the IDE, a person will understand that this is just a convenient set of programs that performs most of the routine operations and, if there is insufficient flexibility, it can be abandoned or expanded.

    Static typing.Using an example of a language with static typing, it is easier to understand what a data type is, why it is needed and what it depends on. You can see what constitutes an announcement, definition and initialization. The use of the C ++ language makes this clearly visible, which contributes to a further understanding of how these mechanisms work in other languages. In addition, one can understand with real examples how unsigned integers differ from signed integers, how double and single precision numbers differ, how a character differs from a string, etc.

    High-level and low-level tools.The use of tools such as pointers and dynamic allocation of memory allows us to understand (or further contributes to understanding) what a stack, heap, call stack, stack promotion, etc. In addition, in practice, an understanding of the concept of addresses and address arithmetic is fixed. The examples demonstrate that memory must be allocated, freed, because it is not infinite, that there are memory leaks. In the future, when learning languages ​​with GC it will be easier to understand what it is.
    Separately, it is worth noting a simple mechanism for transferring values ​​by reference, value, pointer, and object transfer. What are mutable and non-mutable parameters. In the future, these concepts can be used in the study of other languages. The student will understand, for example, that an object in the N language is passed by reference, and if its value is changed in a member function, then it will change everywhere.

    Implementation of OOP.This is a relatively clean implementation of OOP without any syntactic sugar (relative to some other languages). Clearly defined access levels to class members, the possibility of multiple inheritance, and dynamic polymorphism make it possible to quickly master the basic concepts of OOP (abstraction, inheritance, encapsulation, and polymorphism). Pointers and dynamic memory allocation make it possible to understand such important mechanisms as upcasting and downcasting. In the future, based on this knowledge, you can easily understand all the syntactic sugar in other languages. The need to control resources (including the “rule of three” or already the “rule of five”, taking into account C ++ 11), capturing them in the constructor and releasing them in the destructor also contribute to a deeper understanding of OOP.
    It is worth noting such an important point as non-forced OOP. That is, this approach to programming is applied when it is convenient, and it can be mixed, for example, with functional programming. This helps to build an understanding that the means of implementation are selected based on the task.

    STL. The very concept of C ++ templates, code generation and applying a wide range of algorithms to various containers has a positive effect on the learning process. Everything is on the surface here and it is clear why it is possible to create a vector of integers and a vector of custom objects based on one container class. Why it is possible to apply some operation to a sequence of objects or how to sort objects for which a built-in comparison operation is not provided. You can understand how elements are accessed and learn about iterator categories. In addition, an understanding of generalized programming is consolidated.

    2 A bit about learning problems


    The learning process is perhaps one of the most significant obstacles in order to implement everything that is written about in the previous paragraph. This question probably does not concern top IT universities, but if we take ordinary educational institutions, then there is a shortage of qualified personnel and poor motivation of students. For most practical disciplines, specialists directly involved in software development are rarely involved. For example, a person who did not use STL in real projects is unlikely to be able to explain how to do this, and most importantly why. As well as a teacher who sincerely believes that programming in Delphi with forms is already a real OOP, given that all code (without a hint of your own classes, abstraction and encapsulation) is written in a button-click handler with the very understandable name “Button1 ", not conducive to the learning process. There are problems on the part of students who do not really understand where and why they went. Many students are not motivated to further learning and understanding, as well as to self-education. Despite the fact that such students and teachers complement each other perfectly, at the end of the training, a specialist applying for a junior vacancy will not work.

    3 Conclusion


    At the moment, in the world of software development, the situation is that the price is knowledge of certain technologies and the experience of their application, not understanding. Modern society needs many programmers who can perform strictly defined functions. Developing development technologies also contribute in part to this. It is possible that the majority of developers who can simply use a certain set of tools will never encounter the “law of holey abstractions”. However, people applying for the positions of leading developers involved in optimization and architecture issues need a deeper understanding of how everything works. One of the factors leading to such an understanding may be the refusal of the right choice of the first programming language. Based on this, the C ++ language, which is statically typed,

    Also popular now: