Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Clean C++ Design  (Read 6047 times)

0 Members and 2 Guests are viewing this topic.

Robert42

  • Newbie
  • *
  • Posts: 31
    • View Profile
Clean C++ Design
« 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

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Clean C++ Design
« Reply #1 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 and forum discussions. For specific topics, the videos from C++Now or Channel 9 can be interesting, too.

There is also a famous list of good C++ books on Stackoverflow.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Robert42

  • Newbie
  • *
  • Posts: 31
    • View Profile
Re: Clean C++ Design
« Reply #2 on: May 23, 2013, 10:22:20 pm »
Nice! Thank You!! :)

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Clean C++ Design
« Reply #3 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 (the GotW series). At the top of the homepage, you also see a category "Elements of Modern C++ style", which might be quite useful.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Clean C++ Design
« Reply #4 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 ;)).
« Last Edit: May 24, 2013, 12:42:18 am by FRex »
Back to C++ gamedev with SFML in May 2023

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Clean C++ Design
« Reply #5 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.
« Last Edit: May 24, 2013, 02:13:55 pm by Nexus »
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

MorleyDev

  • Full Member
  • ***
  • Posts: 219
  • "It is not enough for code to work."
    • View Profile
    • http://www.morleydev.co.uk/
Re: Clean C++ Design
« Reply #6 on: May 25, 2013, 01:45:05 pm »
Day 1 Keynote - Bjarne Stroustrup: C++11 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.
« Last Edit: May 25, 2013, 06:43:52 pm by MorleyDev »
UnitTest11 - A unit testing library in C++ written to take advantage of C++11.

All code is guilty until proven innocent, unworthy until tested, and pointless without singular and well-defined purpose.

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: Clean C++ Design
« Reply #7 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
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

 

anything