Reddit Reddit reviews Advanced C++ Programming Styles and Idioms

We found 5 Reddit comments about Advanced C++ Programming Styles and Idioms. Here are the top ones, ranked by their Reddit score.

Computers & Technology
Books
Computer Programming
Microsoft C & C++ Windows Programming
Microsoft Programming
Advanced C++ Programming Styles and Idioms
Check price on Amazon

5 Reddit comments about Advanced C++ Programming Styles and Idioms:

u/gregK · 3 pointsr/programming

I disagree somewhat with that distinction. The reason I say this is that a few of the patterns in GoF where actually documented as idioms in Advanced C++ Programming Styles and Idioms and recast as patterns. On the other hand, some purists argue that the GoF patterns are not even real patterns in the Alexandrian sense, therefore they would all be idioms.

So if you are sticking to the GoF definition of patterns, they aren't much more than idioms. If you look at the Alexandrian patterns, then I might agree with you. A good distinction would be to limit idioms to language specific solutions and real patterns to solutions that arise independent of the language. I edited my reply above to reflect this.

u/alfps · 2 pointsr/cpp_questions

Regarding

> I am confused about why this is a copy constructor and not just a normal function:

> class Core {
> friend class Student_info;
> protected:
> virtual Core clone() const { return new Core(this); }
>
> private:
> Core cp; //sorry I think this is how it was declared, but I hope it is close enough
>
> // bunch of other code
> };

The clone function
is a normal member function, and is not a copy constructor.

However, the implementation (function body) of that function uses the class' copy constructor.

At one point the term virtual constructor was used about a clone function. I think but I'm not sure that that term was introduced or popularized in ¹a book by Coplien. Today that term is not much used, if it's used at all: I've never seen it used except in comments about terminology for clone functions. :)

---

Regarding

> First of all, I thought a copy constructor was in the form
>
> classname (const classname &obj) {
> // body of constructor
> }

That's one of the 4 forms a copy constructor can have.

The other three forms have formal argument types T&, volatile T&, and volatile const T&.

Formal argument type T, passing by value, is not a copy constructor, because you need a copy constructor to pass that argument, and a class can have just one copy constructor.

---

Regarding

> Did the act of copying those two cp pointers bring us to this statement?:
>
> virtual Core
clone() const { return new Core(this); }
>
> Or was it just calling clone()?

The Student_info copy constructor is executed as a result of an attempt to copy an instance. Usually it's an implicit call, e.g. via = initialization syntax, or passing an argument by value.

The Student_info copy constructor calls Core::clone, via the explicit call in theStudent_info copy constructor function body. Since the clone function is an ordinary member function, nothing special about it, in particular, it isn't a conversion function, it can't be called implicitly. So it will not be called out of the blue.

In the Core::clone function there is an explicit call of the Core copy constructor.

---

Note that the terminology I use here, talking about an explicit constructor call, is contested. It beats me why, but some quite competent people have insisted that constructors can't be called by user code, even after being pointed to e.g. the C++03 definition of default constructor (one that can be called without arguments). I only convinced one of them that that choice of terminology, not using the terms “call” or “explicit” about constructor calls, was impractical, and that was after several years, and via an argument that is a well known logical fallacy, namely, an appeal to authority: I finally found an article by the language creator Bjarne Stroustrup where he used these words.

---

Notes:*
¹ Googling indicates that the book by Coplien was “Advanced C++ Programming Styles and Idioms” published in 1991. That predates the first C++ standard by 7 years.

u/AnHeroicHippo · 1 pointr/cpp

Advanced C++ Programming Styles and Idioms is pretty unconventional: the author assumes you are already familiar with programming concepts and C++ syntax, and presents a plethora of C++ idioms, at least half of which are... let's say unconventional applications of C++'s power of abstraction, that make you think outside the box. Amazon's synopsis and the reviewers there do a better job at describing it though, so give that a read.

You should read an intermediate-level C++ book or two before diving into this one in order to truly appreciate its eccentricity (which should open your eyes considerably). It is a rather strange book: it reads more like a novel than a desktop reference.

u/Truth_Be_Told · 1 pointr/C_Programming

First note that Career/Job/Market is quite different from Knowledge/Intellectual satisfaction. So you have to keep "earning money" separate from "gaining knowledge" but do both parallely. If you are one of the lucky few who has both aligned in a particular job, you have got it made. Mostly that is never the case and hence you have to work on your Motivation/Enthusiasm and keep hammering away at the difficult subjects. There are no shortcuts :-)

I prefer Books to the Internet for study since they are more coherent and less distracting, allowing you to focus better on a subject. Unless newer editions are reqd. buy used/older editions to save money and build a large library. So here is a selection from my library (in no particular order);