Math for rogues

About sophistry (sophism) in discussions and about OOP

Since writing comments in read-only mode is not allowed, I’ll risk writing in the sandbox again.


Reading a habr, I stumbled over one of the comments . Or rather, stumbled on a quote in this comment:
“I'm sure OOP is methodologically wrong. She starts by building classes. It is as if mathematicians would start with axioms. But no one really starts with axioms, everyone starts with evidence. Only when a set of suitable evidence is found, only then is the axiom derived on this basis. Those. in math you end up with an axiom.
The same thing with programming: first you must begin to develop algorithms, and only at the end of this work come to the point that you are able to formulate clear and consistent interfaces. It is precisely because of this confusion in OOP that refactoring is so popular - because of the inferiority of the paradigm, you are simply doomed to rewrite the program, at the very moment when you just decided to design it in OOP style. ”
(c) Alexander Stepanov, co-author of C ++, author of STL

Before turning to the essence of this article (or rather, to the analysis of Stepanov’s quoted quotation), I also want to recall a short article with a provocative announcement (“sophistry is mathematics for crooks”), which somehow caught my eye in a glossy magazine (which in itself is already strange; infrequently it is possible in such magazines to pay attention to something). The electronic version is here . Next, I will refer to the terms from this article, so I recommend that you familiarize yourself.

Watch your hands

Appreciate our quote in terms of oratory. But beautiful! As they say, watch your hands. It starts with an unexpected and loud statement, so it immediately attracts attention. Further, the speaker brings the listener (reader) to the analogy between the classes of OOP and the axioms of mathematics. This analogy further serves as the basis for the final chord: "you are simply doomed ..."! Applause. A curtain. Opponents are overthrown.

Honestly, it somehow never occurred to me to use OOP in such an orthodox version, as Stepanov describes. OOP in my understanding is just one of many very convenient tools. OOP (paradigm) is quite edible (even tasty) and without the default sauce, which without fail contains the key idea that everything is an object. OOP does not lose any of its charms if you turn to it as necessary, and not exclusively within the framework of its comprehensive key idea. Yes, it seems that the concept of OOP does not at all require the widespread use of exclusively objects. It would be a good idea to reformulate this very key idea, and switch from the “everything is an object” option, for example, to the “everything can be represented as an object” option. It can be represented, but it is not necessary to do it!

The foundation of the quote is an analogy between the proofs and axioms of mathematics on the one hand, and algorithms and interfaces of objects on the other. How substantiated is this analogy? Sounds like an anticipation of a foundation?

Axiom, if I do not confuse anything, there is some initial statement that is accepted as true without evidence, and itself serves as the basis for constructing other evidence (from a set of axioms only consistency is required - indeed, just like from interfaces; however, it is unlikely that the author of the quote is it meant). Yes, yes, somewhere in the corner of my memory there is a thought that many statements, once considered simply axioms, eventually found their evidence. But this is not a reason to say that the train of thought of mathematicians always goes from evidence to axioms. Formally, axioms for some reason are among the theorems, and theorems are always proved, but this is also no reason to assert that the axiom is always derived on the basis of suitable proofs. Sounds like a FALSE SYLLOGISM?

Also in the quote, the development process from interfaces to algorithms is accepted as absurd (supposedly, there should first be algorithms, and only then - the formulation of consistent interfaces). I do not understand why. If I suddenly found it necessary (convenient) to use an object somewhere, then I start with drafts of its structure and interface (that is, methods through which it will be possible to exchange data with this object). In essence, here I just create some additional level of abstraction. I don’t go into the implementation details (algorithms) at this stage yet, and this, in my opinion, doesn’t interfere with coming up with a consistent interface. In procedural programming, when we run part of the code as a procedure or function, we too can very well start from the interface (insert a stub into the code — an empty function), and only then do the details of its implementation. And it does not look absurd. Of course, the development course in the opposite direction is quite possible: we first develop an implementation algorithm (or several at once), and then design it as a function or as a method of a created class. But this does not mean at all that one should always do this. Therefore, it seems to me that this part of the quotation also looks like the anticipation of the foundation.

Of course, I admit the idea that when developing really large and complex projects, things can be exactly as Stepanov describes. My experience does not allow me to judge this, so I leave this aspect to your judgment. Nevertheless, in any situation, this is also no reason to consider OOP methodologically incorrect, in principle, since there are a large number of situations that OOP methodology falls quite well on.

Ultimately, the key declared idea of ​​OOP - everything is an object - also looks like a narrowing of the choice. Well, why is “everything is an object” necessarily? Why not “everything can be represented as an object”? Or is it translation errors?


You and I often use this math for swindlers quite intuitively, simply as a stereotype (pattern!) Of communication. Maybe it’s worthwhile to describe it in the habr in the rules and prohibit use in the comments?

Threat. And I'm sorry if I messed up with programming theory or math somewhere. I will be glad to amend.

The purpose of this post was in no way to belittle the authority of Alexander Stepanov or anyone else, and even less to show "how smart I am." I just wanted to draw attention to the fact that when we learn to defend our opinions in discussions, we often come to the use of sophisms, and we don’t even realize this. It turns out such math for crooks.


Also popular now: