C++ full include paths
Created by: wangkuiyi
Our include convention is that if a header file is in the same directory as the source file, we don't have to specify the full include path.
For example, if a.h
, b.h
, z.h
, and a.cc
are in the same directory paddle/pserver
, we'd write the following in a.cc
:
#include "a.h"
#include "b.h"
#include "z.h"
#include "paddle/math/matrix.h"
#include "paddle/utils/stringprint.h"
However, most auto format tools (Emacs plugins, clang-format, etc) sort header paths enclosed in double-quotes ("). This is reasonable because it
- allows us to find included header files efficiently in the alphabetical order, and
- keep header files in the same directory (package) staying together.
However, the sorting would reformat our code as:
#include "a.h"
#include "b.h"
#include "paddle/math/matrix.h"
#include "paddle/utils/stringprint.h"
#include "z.h"
where "a.h" and "z.h" are no longer staying together, even if they are in the same directory.
So, I propose here that we always write full include paths. If so, we'd have
#include "paddle/pserver/a.h"
#include "paddle/math/matrix.h"
#include "paddle/pserver/b.h"
#include "paddle/pserver/z.h"
#include "paddle/utils/stringprint.h"