Discussing the article: "From Basic to Intermediate: Classes (II)"

 

Check out the new article: From Basic to Intermediate: Classes (II).

This article is intended to be as educational as possible, since the topic we will be discussing often causes considerable confusion in itself. Therefore, dear reader, please try to put what is explained here into practice. If you have any questions, be sure to leave a comment—after all, understanding destructors is no easy task.

One of the most difficult concepts to understand in object-oriented programming is the destructor. In most cases, destructors simply serve no purpose. Furthermore, since you, as a programmer, cannot explicitly call a destructor, it becomes even harder to understand why it exists at all. This certainly does not make it any easier for a beginner to grasp the concept of a destructor.

Old-school programmers like me, who have literally watched programming evolve over the years, also had a hard time understanding some of the new concepts and mechanisms that were emerging. Now imagine a programmer who is faced with all these ready-made concepts and has to understand them. What confusion! First and foremost, because many of these concepts are usually explained very poorly, turning what is simple at its core into a hydra-like monster: the more heads you cut off in an attempt to destroy it, the more complicated the situation becomes. The destructor is precisely one such concept. In this article, you will see that even though all of this seems complicated, it is actually very simple. Once you properly understand how it works, it will be much easier for you to determine when and how to use it in your classes.


Author: CODE X