SFML community forums

General => General discussions => Topic started by: jeans123 on February 24, 2017, 09:44:23 am

Title: Including SFML headers - specific or whole modules?
Post by: jeans123 on February 24, 2017, 09:44:23 am
Hi,

I don't know if that's good principle that I follow but I always try to be as much specific and precisely as I can in my programs.
So the question is - should I include whole module e.g
#include <SFML/Graphics.hpp>
or should I use specific header with functions I need:
#include <SFML/Graphics/Texture.hpp>

For now I prefer 2nd way because it doesn't include whole bunch of classes that I do not need.
What is good practise? And is it just for SFML or in general?
Title: Re: Including SFML headers - specific or whole modules?
Post by: Laurent on February 24, 2017, 10:20:39 am
Good practice is to include only what you need, in order to reduce header dependencies and speed up compile times. This is a global rule that should apply to any C++ code, so it's not different for SFML. The module headers are there only for convenience (you won't see the difference in compile time unless your project is really big).
Title: Re: Including SFML headers - specific or whole modules?
Post by: korczurekk on March 03, 2017, 09:11:24 am
I'd also like to point out another two advantages of using second option: