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

Author Topic: Including SFML headers - specific or whole modules?  (Read 2438 times)

0 Members and 1 Guest are viewing this topic.

jeans123

  • Newbie
  • *
  • Posts: 3
    • View Profile
Including SFML headers - specific or whole modules?
« 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?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Including SFML headers - specific or whole modules?
« Reply #1 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).
Laurent Gomila - SFML developer

korczurekk

  • Full Member
  • ***
  • Posts: 150
    • View Profile
    • Email
Re: Including SFML headers - specific or whole modules?
« Reply #2 on: March 03, 2017, 09:11:24 am »
I'd also like to point out another two advantages of using second option:
  • Shorter list of suggestions in IDE after typing sf::, you only see things that are useful in this exact file.
  • Makes big difference in IDE performance while using some sickly powerful code checkers, eg. Clang Code Model.

 

anything