What the const modifier means after a method declaration - page 2

 
Vasiliy Sokolov:
Constant method is another example of the proverb "we wanted to do better, but it turned out to be the same as always". I think this is a motto for C++ at all. There is no practical use but it significantly complicates designing of OOP-programs because you constantly need to control the type of object being modified (it must be constant as well).

Can I give you an example of what you wrote about?

 
Vasiliy Sokolov:
The constant method is just another example of the proverb "we wanted things better but it turned out as usual". I think it's a motto for C++ at all. It is of no practical use but it significantly complicates the design of OOP programs because you constantly need to control the type of the object being modified (it must also be constant).

))) I've got an old Stroustrup book lying around, if burglars break into the house, I can easily beat them off with it, it weighs like a brick )) The old man put so much trouble in his tongue...

I remember a long time ago I got chased around in a job interview, they asked me a question and I couldn't answer it accurately. They brought me a book like this, I read it, and I asked, "Do you use it yourself?

I asked, - Do you use it yourself? - Guys are laughing, it's OK, no one has yet answered this question correctly, as no one uses it.

By the way, I've got a book on pluses from the early 90s, before the first standard was adopted. A normal digestible paperback book. But then Ostap got carried away ))

 
Alexey Kozitsyn:

Can I have an example of what you wrote about?

Alexey wrote an example. A constant method cannot change its class members. What seems to be the problem? Just don't use the const modifier. But then there are difficulties in inheritance (especially fromstandard library): designer defined virtual method const, but in derived class, method needs to change something in its data - and there's a plug because of const. Without it, the method will not be overridden, and with it, the derived method cannot change its own class data.

What is the main mistake in introducing such a modifier for class methods? The main principle of inheritance is violated: specialization and refinement. The base class prohibits the derived class method from working with its internal data. And there should not be such a situation.

 
Vasiliy Sokolov:

Sharpe reeks a mile away ))

There's nothing const obstructing, no need to blather on.

 
Комбинатор:

Sharpe reeks a mile away ))

I'm not denying it. Sharpe really is a perfect, great and beautiful language.

Combinator:

Const does not complicate anything, don't blah-blah

Ok, let's say one can always get rid of const. But why don't you briefly explain by example, what does const do? What is its real use? By example, and preferably not written out of thin air.

 
Const is one of C++'s striking metaphors: first you diligently lay elaborate traps all over the code, and then you get out of your own traps - that's the whole process of C++ programming.
 
Vasiliy Sokolov:

...

What is the main mistake of introducing such a modifier for class methods? The main principle of inheritance is violated: specialization and refinement. The base class prohibits the derived class methods from working with its internal data. But there mustn't be any such thing.

Maybe it is some part that is passed from creators to simple users. Like the start function in the Expert Advisor and the Bid and Ask variables.

When you make everything yourself, there is no sense to bother with all sorts of const.

 
Vasiliy Sokolov:

I'm not denying it. Sharp is indeed a perfect, great and beautiful language.

...

Great. But it's a long way from perfect.
 
Dmitry Fedoseev:
Great. But it's a long way from perfect.
The Sharp is good, not because of any geniuses who made it, but because it's the last one. Before it, for 30 years they tried to kill with rakes of various sizes and fanciful configurations. C++ was a wonderful testing ground for it. After everyone was killed off, the Microsoft guys just spizzed off.... adopted the tried and tested concepts and created a syntactically clean language from scratch.
 
By the way, MetaQuotes also had a good chance to gradually "develop" MQL5 into a Robe-like monster a la C++. But deep knowledge in C++ (where there must have been sweat, tears and hatred) made them realize that they should not follow the advice of forum old-school C++ programmers. That's why we now have a syntactically clean and more or less strictly typified programming language. It's even amazing that we managed to create such a candy, based on a completely monstrous legacy. Mastery cannot be lost, as they say.