C++ jargon

Initially I thought of writing a new part in my series of C++ teachings, but I changed my mind. I start reading a C++ FAQ and I kept reading and reading. Interesting stuff out there and I strongly recommend to go through (in any case, if you’re making any search about any C++ topic on Google, this will be displayed among first 4-5 most relevant webpages, so it is hard to miss it).

I don’t know whether or not the title indeed reflects the content of this post, but it seemed to me that this FAQ site was depicting the way a C++ programmer thinks. The fact that this post is commenting some of the topics in the aforementioned web-site and that the manner in which some hints are outlined and some C++ insights are explained guided me to the idea that the author is speaking into a “C++ jargon”.

I decided to go through those items and to highlight those which popped to my attention, just as I did it with the video courses. This won’t be some kind of short overview of the FAQ, but only my view of some topics which I considered to be more interesting.

One of the interesting discussions is at topic no6 – Big Picture Issues

One thing which I totally agree upon is that business perspective should rule. The author asks rhetorically:

Is it important to know the technical definition of “good OO“? Of “good class design“?

And then the answer comes:

You might not like this, but the short answer is, “No.” (With the caveat that this answer is directed to practitioners, not theoreticians.)
Mature software designers evaluate situations based on business criteria (time, money and risk) in addition to technical criteria like whether something is or is not “good OO” or “good class design.” This is a lot harder since it involves business issues (schedule, skill of the people, finding out where the company wants to go so we know where to design flexibility into the software, willingness to factor in the likelihood of future changes – changes that are likely rather than merely theoretically possible, etc.) in addition to technical issues. However it results in decisions that are a lot more likely to bring good business results.

Any purely technical definition of “good,” such as “good OO” or “good design” or anything else that can be evaluated without regard to schedule, business objectives (so we know where to invest), expected future changes, corporate culture with respect to a willingness to invest in the future, skill levels of the team that will be doing the maintenance, etc., is dangerous. It is dangerous because it deceives programmers into thinking they are making “right” decisions when in reality they might be making decisions that have terrible consequences. Or those decisions might not have terrible business consequences, but that’s the point: when you ignore business considerations while making decisions, the business consequences will be random and somewhat unpredicatable. That’s bad.

Totally agree! I’m just thinking of MISRA C guidelines (please correct me if I’m wrong !!): the driving forces of those rules are the requirements of the automotive market (or better said, real-time market in general). As far as I’ve seen it this is some kind of ANSI-C standard adjusted for the industry needs. The standard, or the theory has to follow the industry trend and not vice-versa.

Another thing which I saw is emphasized is that virtual functions (…and implicitly dynamic binding) are the core of Object-oriented programming.

Bottom line: C++ without virtual is not OO.

Maybe we have to go back to the roots of object-oriented programming … but not now :).
I did not know about the difference between object-based and object-oriented programming… it seems to be a very important thing. As far as I’ve seen

“programming with classes but without dynamic binding is called “object based,” but not “object oriented.””.

Topic #7 – classes and objects: it looked very appealing to me note 7.5
How does C++ help with the tradeoff of safety vs. usability?

But first of all … what is safety and what is usability, in terms of object oriented programming?
Since always I was thinking that encapsulation is quite synonym with safety. Well #7.8 strikes me with a clear answer:

Encapsulation != security.

Encapsulation prevents mistakes, not espionage.

To be honest I do not know what the author is meaning by this.

Then, what is usability? This can be “safely” I found under #7.7. Just to resume it with my own stupid words, it is the ability of a certain object oriented language to use multiple instances of its classes.

What? What are you talking about??

I do not know so exactly what is here referred as “class method”, I would rather think that the author is talking about static methods.
Let’s just pay attention to the example with the assignment operator:

Consider assignment operator Foo::operator=(Foo const& x). This assignment operator will probably change the data members in the left-hand argument, *this, based on the data members in the right-hand argument, x.

Usually an assignment operator is overloaded as a function, which takes as an argument the right-hand side operator (of the assignment =), this is why Foo const& x is in between parenthesis, and assigns it to the destination, left-hand side. Due to the fact that it takes as a parameter a member it is necessary to overload the assignment operator as a friend function, in order to gain access to non-public members

The difference between class and struct keywords:
(Is it just about the difference between a C++ struct and a C++ class?)

Emotionally, most developers make a strong distinction between a class and a struct. A struct simply feels like an open pile of bits with very little in the way of encapsulation or functionality. A class feels like a living and responsible member of society with intelligent services, a strong encapsulation barrier, and a well defined interface

Many times I also had the same feeling. Actually I do not know why structures aren’t used more often. They support inheritance, don’t they? They can have overloaded operators, don’t they? They can have virtual functions, don’t they?

As per my understanding, in C++, the only difference between classes and structs is that the default access specifier is private for classes, and public for structures.

Well, there are always things to learn …


2 Responses to C++ jargon

  1. kellogs says:

    If I am not wrong, there are 3 differences between structs and classes, but this one is the most well known. I forgot the other two as well 😀

    >>Encapsulation prevents mistakes, not espionage.

    To my mind, the author is talking about meanings of keywords such as private / protected / public. You do not make a method private so other coworkers cant see what it does / cant change things so that they could call it. You are letting them know how to design their part of the system so they do not fiddle with critical data that should not be fiddled with.

    That C++ FAQs site is not the easiest one to grasp. Personally, I dont agree on virtual being atthe core of C++. Everything makes it a it is, not just virtual. Basically, every single program written in c++ could be as well translated in C. But by doing so you are going to loose many fellow programmers off track, and eventually yourself as well. C++ is a very good way of bringing discipline into our code / coding skills / standards and nothing more. Yes, it is difficult, but given the complexity of today’s applications, it might have been 5 times more difficult – still worth learning (of course, I am ignoring interpreted and java-like languages).

    • Honestly I would not bet that C++ is a very good way of bringing discipline into our code / coding skills / standards and nothing more.
      Just have a look at what this guy is saying about poor reasons to reject C++ .
      Basically everything that you can do it in C can be done also (even better, some people say :)) in C++, vice versa does not work so smoothly.

      well…. you would reply and shut my mouth off … that C++, compared to C, is almost inexistent in the embedded world …

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: