Forty Years of Computer Languages

C++ and object oriented programming


When programs grow: hundred of thousands of statements, the management become difficult with C-type languages. There are too many parts to manage, with too many correlations. A typical example of over-complex software is a graphical user interface, with a lot of intercorrelated elements: as windows, scroll bars, menu of different types, etc. Other examples are computer games, a very, very difficult and complex software.

The solution is to subdivide the problem in smaller parts, communicating with clear and standardized interfaces. Each part can be developed and can evolve in an autonomous way, as long as the interface doesn't change.

There is no support, in programs like FORTRAN or C, for this thing; a good solution for this problem is object oriented programming, introducing the concept of classes in computer languages.

Classes are similar to the structures of the C language: collections of heterogeneous things (named class members), but contain also the functions acting on them.

Some of the functions can be called outside the class and constitute what is called the interface of the class. They are refferd as "public members". Other functions are "private", used into the class, can't be wieved from the outside.

The programmer have to write a description of the class (the class declaration), usually placed in an header file. This description is used in the program to create object entities build with all the features of the class. These are named "instances" of the class; the class acts as a model for real object constructions.

By using the object oriented approach, a problem can be easily subdivided in smaller parts. It's not just a trick to make programming easier, it is also a different way of organizing the software structure and a new way to analyze the problems.

The focus is more on data than on procedures, and understanding the data and finding the best representation of data in term of classes is the key point of an object-oriented project.

This is not easy to do, and I've sometimes seen the object oriented approach leading to an over-structured software, an intricate beast impossible to manage. But, if used in the correct way, the object oriented approach is a very, very powerful tool.

Unfortunately, object programming is today also a common trend, all recent computer languages have classes, and object programming is used everywhere, most of times to add useless complexity to simple problems.

Classes where added to the C language by Bjarne Stroustrup, in the late seventies, Stroustrup took the classes from the Simula language and ported them to C, creating the language: "C with classes", to be used at the AT&T research laboratories. The language was renamed "C++" ,in 1983.

C++ is a language written by a programmer for programmers, with a very user-oriented approach, aimed at solving real problems and not designed following an abstract design scheme; moreover it was an extension of C, one of the most used language in that period. For these reasons C++ had a wide diffusion and became one of the most used object oriented programming languages.

It was the preferred language for games and user interfaces, but also many science projects migrated to C++, as many big software projects at CERN. The success of C++ greatly contributed to give big emphasis to object programming.

The addition of classes to C++ didn't lead to a very clear language structure, and C++ looses the elegant essentiality of C. There are a lot of subtle details in C++ classes usage; too many features added, and more are introduced at each release of the standard. Some features are complex and can lead to very intricate software, as: inheritance details, templates and operator overload.

C++ seems more a patchwork of all the possible features, rather then a well conceived project. Too many things have been stuffed into the simple and elegant C structure.

But C++ is still a good language, and it is compatible with C, being (nearly) a superset of the C language. And you don't need all the features of C++ to write good programs.

In fact, after a careful reading the books of Meyers [1], I decided not only that I don't need all the C++ subtleties, but also that relying on the fine details of a language is very dangerous. Your software risk to be linked to a specific implementation of the language, it is more complicated, more difficult to read and to modify, impossible to translate in another language, or to port to a different architecture.

In computer science "simple is beautiful"; software subtleties has to be avoided. With modern, fast computers, extreme efficiency can be happily given away in exchange of a simpler structure [2] ; the real hassle isn't software writing, but maintenance. Software should be written from the beginning with the idea of make maintenance easy.

Some features of C++, and in general of object oriented languages, worth to be mentioned here, because they are major steps toward a greater level of abstraction in computer programming:

This is not all, they are adding new particular features to C++ at any revision. We had a revision in 2014, another in 2017; for revision details see: https://isocpp.org/std/status



Notes

1
"Effective C++" and "More Effective C++", by Scott Meyers,Addison Wesley 2005, 1996
2
Struggling with some tricky structured software (written by myself), I once realized that: "simple is beautiful" is a must in computer programming.
But sometimes "dumb is beautiful" is a better choice.
This text is released under the "Creative Commons" license. Licenza Creative Commons