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

 
It's not uncommon to intentionally use such constructs as well:
const TYPE1 Method( const TYPE2 Input ) const;
And if I don't just change the object's internal data, but also don't access it, I immediately write the method as static. For me, using const and static greatly increases readability/understanding of my own code. And it often allows me to catch bugs or flaws in my own architecture at early stages of implementation.

I write everything only for myself. And it would seem that I'm not going to change some data I shouldn't anyway. But the desire to protect myself from my own stupidity makes me rivet OOP-architecture in such a way, that only what must be accessible to change. The rest is not. And here const + inheritance types are of great help. I recommend it.
 
Dmitry Fedoseev:

Maybe this is some part that is given from creators to ordinary users. Like the start function in the EA and Bid and Ask variables. When you do everything yourself, there is no sense to bother with all sorts of const.

Unfortunately, we have to drag all this ballast for the sake of compatibility. On the other hand, small C and C++ codes are very quickly ported to MQL (this was checked many times).
 

I've noticed an interesting tendency - in the vast majority of cases, those who don't know anything about it talk about the monstrousness of the pluses. Mostly sharpers, that's typical.

Yes, of course, Sharpe is better and more convenient when you need to make something as straight as a stick.)

 
zaskok3:
It's not an uncommon case when I use such constructs intentionally:
If I don't change internal object's data and don't apply to it, I specify the method as static. To me, using const and static greatly increases readability/understanding of my own code. And it often allows you to catch bugs or flaws in your own architecture at an early stage of implementation.
...

Oh guys. Have mercy on MetaQuotes. One of the primary commandments of a programmer: never use static. Second commandment: if you want to use static, see the first point:)

If static data are changed by one thread while another reads them, such wonders of multithreading programming appear, that one can recall this static like a bad dream.

But good for users in MQL: no multithreading and, consequently, no method will change static data before a user thread finishes reading it.

 
Vasiliy Sokolov:

One of the first commandments of a programmer: never use static. Second commandment: if you want to use static, see the first point:)

If static data are changed by one thread while another reads them, such wonders of multithreading programming appear, that one can recall this static like a bad dream.

Once again I'm convinced that the discussion will not work )
 
Комбинатор:

I've noticed an interesting tendency - in the vast majority of cases, those who don't know anything about it talk about the monstrousness of the pluses. Mostly sharpers, which is typical.

Yes, of course, Sharp is better and more convenient when you need to make something as straight as a stick.)

Classical masa b pluses: "You do not like cats? You just don't know how to cook them".

No, I don't deny, C++ like no other language can be tuned to development standards. But until you come to these standards you may be killed on such a rake that you either become a really good C++ programmer or give up and go to 1C to make ERP-tickets.

 
Vasiliy Sokolov:

The classic B-plusers masque: "You don't like cats? You just don't know how to cook them".

It's just the way it is.)

I have nothing against Sharp, I'm writing bots with it, it's convenient, fast.

I just don't like it when people sling mud about something that doesn't deserve it and moreover, something that no one is necessarily forced to use.

That goes for both the cons and the pros in general.

 
Комбинатор:

It's just the way it is.)

I have nothing against Sharp, I'm writing bots in it now, it's convenient, fast.

I just don't like it when people sling mud at something that doesn't deserve it and moreover something that no one is forced to use mandatorily.

This applies to both const and pros in general.

Ok, the world. It's just that discussion of C++ always descends into a hullabaloo.

Z.U. If somebody would explain me what the problem with const is, I'd appreciate it. I really don't understand it.

 
Vasiliy Sokolov:

Alexey wrote the example. A constant method cannot change its class members.

void bar(X& obj) const 
    {
        obj._x = 42; // OK! obj передается по ссылке и не имеет модификатора const
        _x = 42; // ERROR!
    }

Maybe I'm missing something, but... here. Alexey wrote that the constant method bar changes the object of its class obj. What is the problem?

Yes, obj is passed by reference, but the method hasn't become constant yet...

 
Alexey Kozitsyn:

Maybe I'm missing something, but... here. Alexey wrote that the constant method bar changes the object of its class obj. What is the problem?

Yes, obj is passed by reference, but the method still remains constant...

It is not his but an entirely extraneous one of the same type.