How much C++ syntax do you need to know?

closed account (z0My6Up4)
I was thinking that experienced c++ programmers surely don't memorize every single detail of syntax of the language. My guess is that what is most important is a good understanding of fundamental ideas instead of concentrating on specific syntax.

For example one should understand the ideas of inheritance, polymorphism and exception handling but there is no need to memorize the syntax details as this can be looked up when needed.

So can you share your views on this?
there is no need to memorize the syntax details
There is no need to memorize details of use of all standard library members, just know what it can offer you.
You do not need to know every single bit of syntax to start ptrogramming either.
But you should know it after some time as it is basic building blocks of language and without knowing it you won't be able to use C++ efficiently (for example, if you do not know about mutable keyword existence, you cannot look it up and know about some useful features it can suggest). Some of those things are pretty obscure but sometimes they helps.

For example of obscure things:
What the difference between:
1
2
decltype(x)
decltype((x))
What does following declaration means:
1
2
3
4
class foo {
//...
    operator FILE*() & ;
}
What is the problem with following line: std::cout << "enter date in format ??/??/??";
Last edited on
@MiiNiPaa
I've never seen those before, I was able to find out what the first and third are but not the second example.
It looks like a conversion operator but the & is throwing me off.
Last edited on
In the real world, simpler is better. The problem with using obscure features of a language in a professional environment is that the next person who looks at the code might have no idea what you were trying to do. For that reason I try to avoid complicated things when something simple will do. If I need an obscure language feature, I add a comment saying what I'm doing.
flint wrote:
one should understand the ideas of inheritance, polymorphism and exception handling but there is no need to memorize the syntax details as this can be looked up when needed

That's only the beginning: as you use inheritance, polymorphism, exception handling, or any other major language feature, you look up the syntax, make mistakes, encounter corner cases, and eventually the syntax becomes familiar.

I was thinking that experienced c++ programmers surely don't memorize every single detail of syntax

Experienced C++ programmers don't memorize them on purpose.

(and of course with C++ being fairly complex, people tend to forget the details of anything they don't use for a while. If someone knows all of its syntax, they must have just single-handedly written a new C++ compiler frontend)
Last edited on
Experienced C++ programmers don't memorize them on purpose.
Exactly my point. You might not know how exactly given part would behave, but you know there is the catch and can look it up. Likewise when you writing something, you know that there is language faculty which can help you and you know enough to look it up.

Ref-qualified conversion operator makes following code illegal for example:
1
2
3
4
//Cfile is a RAII wrapper over C style file ponter
//Opens in constructor, closes it in destructor
FILE* file = Cfile("somefile.dat");
C_library_function(file);


Trigraphs is the part of the language I hate. You need to be vary around code which contains two question marks in a row.

decltype trickery is used when writing heavy templated code. Also possible problems/possibilities of
1
2
3
return x;
//vs
return (x);
were discussed recently somewhere in General Programming
experienced c++ programmers surely don't memorize every single detail of syntax of the language

The syntax of C++ is actually quite compact and not difficult to learn. If you've learned C, there is a modest additional amount to learn as far as pure syntax is concerned. C++14 has expanded that somewhat, but the delta over C++11 is not terrible.

Where I believe the challenge in learning C++ comes, is from the STL. The STL is part of the language, but technically not part of the syntax since the STL is written in C++. There are many headers to learn (even more in C++14). However, sites such as this have a good reference section on the STL headers. Some headers such as iostream, you'll become familiar with quickly, others are more obscure and require using them frequently to know them well. You will also find that many STL headers have a hierarchy to them. e.g. iostream relies on istream which in turn relies on ios and ios_base.

It also helps to have a good understanding of macro programming. In C++, this is called template programming, but really templates are just a big macro facility.
Last edited on
Topic archived. No new replies allowed.