pragma once vs include guards
All modern compilers understand the include guards and treat them with the same optimization as pragma once.
That said, if I expect my code to be most compatible I will use both #pragma and #include.
1 2 3
|
#pragma once
#ifndef DUTHOMHAS_MYFILENAME_HPP
#define DUTHOMHAS_MYFILENAME_HPP
|
From 2012:
http://stackoverflow.com/questions/13339392/should-i-still-use-include-guards-and-pragma-once
naming pattern
My personal pattern is: my personal tag (DĂșthomhas) + the simple filename + file type.
This proactively prevents conflicts with similarly-named libraries I may use from other people's projects.
If you wish, you may also salt the name with the date-time. I'll do this if I am developing a library: DUTHOMHAS_201608011244_MYFILENAME_HPP, for example. This prevents mix-ups between versions of the same library... But that is totally unnecessary most of the time.
underscoresÂ
Any leading underscore in global/file-level view is reserved for the compiler implementation to use.
So, unless you are writing a compiler's library, avoid leading and trailing underscores.
This is by design in order to to prevent collisions: the compiler's library naming conventions are different than user library naming conventions. My "list" library won't collide with the <list> library.
And while I'm at it, I should also wrap all my stuff in a namespace. Again, my personal namespace is "duthomhas"; chances are if you find anything using that namespace it was written by me [or some loser poser stealing my stuff].
Hope this helps.