SFML community forums

General => General discussions => Topic started by: Robert42 on May 23, 2013, 09:54:41 pm

Title: Clean C++ Design
Post by: Robert42 on May 23, 2013, 09:54:41 pm
Hey!

I am overwhelmed by the design of SFML. I like how intuitive it is to use. I wish which there were more Libraries with such a clean design.

I am programming C++ since about 10 Years. Most of the time I was hacking, until I got my hands on the book Clean Code by Robert C. Martin. Since then I am trying to improve the quality of my own code.

The Next book I am planning to read is the book "Modern C++ Design" written by Andrei Alexandrescu.

@Laurent & other Clean Coder: Do you know further Resources (books, websites) which might be useful to improve ones C++ Software Design
Title: Re: Clean C++ Design
Post by: Nexus on May 23, 2013, 10:17:40 pm
Modern C++ Design has a misleading title. It does not teach modern style, it shows unconventional features that you can implement with templates and metaprogramming. Not everything of it is directly useful in practice, but it shows interesting concepts. A part of it is out of date with C++11.

The classical books for best practices in C++ are Effective C++ and Exceptional C++. I have the latter, it's a very good book in my opinion. There is also a sequel called More Exceptional C++. Although it bases on C++98, most concepts are still valid. For C++11, I don't really have a single recommendation. I have gathered my C++11 knowledge by various articles like C++Next (http://cpp-next.com/archive/2009/08/want-speed-pass-by-value/) and forum discussions. For specific topics, the videos from C++Now (http://cppnow.org/) or Channel 9 (http://channel9.msdn.com/) can be interesting, too.

There is also a famous list of good C++ books (http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) on Stackoverflow.
Title: Re: Clean C++ Design
Post by: Robert42 on May 23, 2013, 10:22:20 pm
Nice! Thank You!! :)
Title: Re: Clean C++ Design
Post by: Nexus on May 23, 2013, 10:28:29 pm
By the way, meanwhile a lot of the original examples of Exceptional C++ are online on Sutter's Mill (http://herbsutter.com/) (the GotW series). At the top of the homepage, you also see a category "Elements of Modern C++ style", which might be quite useful.
Title: Re: Clean C++ Design
Post by: FRex on May 24, 2013, 12:33:27 am
How much experience and qualifications do you have Nexus? You seem most knowledgeable here except for Laurent(maybe even better than him..., no offense either of you, you're both great ;)).
Title: Re: Clean C++ Design
Post by: Nexus on May 24, 2013, 01:56:58 pm
How would you measure experience? The amount of years one has been programming is obviously not a good criterion, what this thread shows quite well. Looking at the written code is already much more promising.

A lot of people just want to develop their game and see C++ as a tool to achieve it as fast as possible. They had better use a different language, because C++ is absolutely merciless when you don't know it well. However, when you are interested in the language itself, it will be much easier to gain experience. It may sound boring for some people, but the impact on the written code is tremendous -- when knowing modern C++ techniques, life becomes much easier. It took me a few years to realize this, too. Although it requires some time and motivation, I think it is important to keep reading (good books and article series from C++ experts), even more since C++11 is a more and more present topic that inherently affects the code style.

Some older statements of mine related to the topic, in order to avoid repetition again and again:
Quote
And don't underestimate the importance of good C++ knowledge. By "good", I mean you know concepts like RAII, type erasure, functionals or templates. You understand why new/delete should be reduced to a minimum, and how STL components (containers, iterators, algorithms) interact with each other. How to decide between static and dynamic polymorphism. What other possibilities of abstractions exist in C++. Why you should avoid global variables where possible. And so on... The reason why this knowledge is crucial, even if advanced, is because it determines your everyday programming. You write code in a completely different way if you do not understand those topics -- usually, code is more complex and error-prone, harder to maintain and less efficient. You will see how much more fun it makes to maintain a project with a well-designed code base (and also how completely frustrating it is to spend days of debugging because of bad code).
Quote
In C++, there are several problems. Modern C++ techniques have only come in the 2000's with authors like Meyers, Sutter, Alexandrescu. And at the moment we are only seeing the first practical implications of C++11 being more and more supported. People interested in the language experience progress first, it takes a while until the "average developer" learns new idioms.

A second problem is the vast amount of terrible literature for C++. Many books have taught an antiquated C++ style, close to the beginnings at "C with classes". The same is true for C++ libraries, it is not easy to find a well-designed API as in SFML, especially in the field of game development. Inheritance overusage was, and still is, a big problem. Not only in C++ -- take a look at the Java standard library, especially the collections. Java has fewer abstraction tools than C++ -- in C++ they often were not used, although available.

I believe that this "not-usage" is not only a result of small practical experience, as many experienced people (in terms of finished projects) still don't use modern C++. It is rather also a consequence of the difficulty to find good articles or books, which in turn is due to the complexity of C++ and the slow spread of knowledge in the community. A lot of techniques can't be learned only by programming, thus I find it important to read about them, and to try to apply them in projects, beginning with the first project.
Title: Re: Clean C++ Design
Post by: MorleyDev on May 25, 2013, 01:45:05 pm
Day 1 Keynote - Bjarne Stroustrup: C++11 Style (http://channel9.msdn.com/Events/GoingNative/GoingNative-2012/Keynote-Bjarne-Stroustrup-Cpp11-Style), this lecture may be relevant to these interests :)

And to get away from just C++, any of Robert Martin's other works are obviously also good recommendations. Test driven design by example is an often recommended classic by Kent Beck, and I'd agree. Refactoring by Martin Fowler is also very recommendable.

Admittedly I'm not happy with most of the unit testing libraries for c++, which is why I am writting my own. (https://github.com/MorleyDev/UnitTest11)
Title: Re: Clean C++ Design
Post by: binary1248 on May 25, 2013, 05:40:18 pm
Maybe these links might be of interest to you. They were presented to me as part of a master lecture I attended at my university. The original is written in German but it is being translated into English.

http://www.clean-code-developer.de
http://www.clean-code-developer.com