First we need to say that for those who have studied programming at least a little, this article will not be very useful, and for those who have given some C to many years, remember that nice time when C ++ was called “C with classes ", and generally knows more than two or three languages ​​- that is ridiculous. But the purpose of this monitor is not to surprise someone or complain about the fate of fate, but to prevent young and bright heads from falling into a panic if they are suddenly taken aback by the phrase “Tomorrow you start writing coursework / project / diploma in C ++, choose a topic. ” Well, that is, this text is focused, rather, on first-second-year students of relevant areas and enthusiasts who decided to master the language themselves.
Actually, I expect that the reader has some kind of programming knowledge, otherwise it is strange that he (or she) is reading this.
So, let's begin.
')
Blessed are those teachers who initially teach their students the language in which they give coursework. For we, for example, had a hard time with this - to clear our conscience we were offered to write something in Pascal, but no sane student who dreams of becoming a programmer will agree to such a setup. So, from experience there is - Pascal and some theoretical knowledge about object-oriented programming.
Looking ahead, I’ll say that not a single book on object-oriented programming says the simplest thing that becomes apparent immediately when you switch from a learning language to the same C ++, namely: “You don’t try, you don’t know.” By the way, again, about books - all language guides, textbooks "C ++ for dummies", lectures on the Internet, resources and everything else does not matter if you do not understand the meaning itself. This is quite obvious to a programmer who has mastered several languages, and indeed to a programmer in general - but for a beginner, this is not more than obvious. That is, at first it seems - the syntax, functions, operations ... It's terrible how much to learn! Panic-panic-panic begins with this, from volume, from the upcoming hellish and hard labor.
And the funny thing is that this is fundamentally wrong.
Syntax does not matter if you understand the logic of the language. In other words, if you understand the essence of the object-oriented (and combined) approach, you can do at least something.
And it begins with the truly correct phrase of our teacher: "The user is an idiot, so the programmer must think for him." It was at a time when we did not understand the wisdom that our master of minds spoke. but now he is auditioning. I will explain on the example of my coursework:
Constructor for the class "polynomials". The meaning of the main constructor is a dialogue with the user, padding from the keyboard. The coefficient and degree are entered at it. For those who immediately want to insert “And why can't I just type 3x ^ 4 + 5x + 7?” - for now it will be like this, then I will begin to pervert with the convenience of the user, and this is, nevertheless, my first experience with C ++. So, everything seems to be quiet and peaceful, but then a normal question appears - how will the user enter coefficients and degrees? In order, from the oldest to the youngest, from the youngest to the oldest, or is it chaotic at all?
And then the mathematician will say: you need to write to the user so that he enters, say, from the youngest to the eldest, and forget about it. In principle, any adequate person would say that. And this is all because the person is thinking about making it easier for himself. A student so much the more.
But where did you see a calculator that asks you to enter something in a way that suits him? This is probably the most unpleasant at the beginning of the thorny path of the programmer - to understand what is good for the user. And the fact that for the sake of this it is worth considering everything that this very user comes into his head is the tenth thing, you will think, you have to strain yourself. Everything for the user, everything for him, beloved.
In other words, I imagined that I myself use this program. And the first thought was: “What? Enter not as horrible? Oh, I'll find something else. ” Clearly, I do not aim at commerce (and indeed at distribution, but the trend is indicative.
So the
user should be comfortable - otherwise why bother to do dialogue with him? No, this, of course, I ran much ahead, it is closer to implementation than to the basics, but still. Most of the software in one way or another implies the human factor, which has to be considered when moving from the sandbox to the big sandbox.
We go further. There is one more thing that is not written in textbooks - more precisely, they write, but not in all. Here you want to insert a small lyrical digression.
Sometimes we believe that the Internet will give us much more than a textbook. Sometimes it is even true. Sometimes we skip past the advice of teachers, believing that we have no equal in what, in what, and in the search for information. So, this is true, but in the case of programming and, often, mathematics, these simple rules do not work. Perhaps this is the legacy of the school, I do not know. But when they say to you, “read such and such a book, everything is written in detail there” and they do not explain anything anymore - go read! For C ++ and, it seems to me, in general all object-oriented programming is such a book -
Bjorn Straustrup, "The C ++ Language" . Well, it is logical that the author of the language can tell about the meaning of the language and in general about where the legs grow from at the terrible word “classes”. I have not met a better approach to the question, although I have cracked quite a lot.
In all other sources, they immediately proceed to the implementation, to the subtleties, skipping the notional, “bolting”, layer. What gives unexpected complications. Well, that is, the entire introduction to the object-oriented is usually skipped, and this phrase remains an unknown animal. To be honest, here you can finish, but I will continue, I repeat the thought, suddenly it will come better.
Take, for example, a table. The object is a table. And the object of this has properties. Some Well, the material is glass, wooden, plastic; color - black, cream, blue-brown-crimson; shape - square, circle, oval, and so on. This, it seems, is intuitively understandable and by this all ears buzz to everyone, right?
But this approach is the base. That is, until that bright moment, when a neophyte sits down to write code,
he must tie a leaf and a pen, write out his objects and all their properties on him . And then cross out those that he does not need.
For example, you need to create a class "student" for the attendance table. A student has eye color, skin color, religion, illness, performance, marital status, relatives ... A lot of student properties. But specifically in this task it is important that the student wears or does not wear socks, how does he kiss his grandmother and so on?
The most interesting thing is that these seemingly understandable facts somehow float away, if not from that side, begin to get acquainted with the subject. There is such a phrase “even a hare can be taught to light matches”. In other words, even a philologist (with some effort) can be forced to write something in C ++ and there is a possibility that this “something” will work. But if you do not start learning from the right side, the task can suddenly crush its magnitude.
This is not only with C ++, of course, the same natural languages, since they remembered philologists, are studying in the same way. First, a certain idea is given on how to build sentences, what is the relationship between words, and then a dictionary base is acquired. Programming languages ​​are essentially the same.
I will repeat for the hundredth time, I do not discover America and do not pretend to the originality of the material - but, for example, I did not get such an article about two months ago, so I started a certain degree of panic - how, how, it is impossible to learn, it is unreal , it is necessary to urgently learn the functions, but I do not know them - and everything is in a circle.
If you understand how to do something, you can do it. And go from just to difficult. This is reminiscent of the construction of a booth for a dog - first one brick is taken, then a second brick, a third, a solution ... If, however, it is impossible to split the task into its component parts.
Which, by the way, applies not only to programming.
But when you don’t know how to write a function in C ++ that builds a degree - the Internet and reference books to help.
I understand that the article is full of naivety, and programmers have repeatedly made similar conclusions and shared them with the public. But if my experience helps at least one person who is faced with this problem is already a good idea.