-
Notifications
You must be signed in to change notification settings - Fork 10
SPERR Style Guide
Samuel Li edited this page Apr 19, 2022
·
2 revisions
(This is a collection of style guidelines that are not very well organized yet.)
- Use the AAA (Almost Always Auto) style. More discussion on this style can be found on this Herb Sutter's post.
- When using macros (e.g.
#ifdef QZ_TERM
) for selected compilation, if there's only one section (i.e., no#else
or#elif
) then don't add a blank line just for the macros. If there are more than one section (i.e., with#else
or#elif
) then use a blank line before#ifdef
and after#endif
.
SPERR strongly discourages the use of raw pointers in its code base for safety,
performance, and other reasons.
Instead, programmers should consider using smart pointers (mostly
std::unique_ptr<>
) and containers (e.g., std::vector<>
).
However, there are a few exceptional cases where raw pointers make a lot more
sense and they can be used.
Overall, the use of raw pointers needs to be looked
at on a case-by-case basis
- When SPERR interacts with other projects and they might give SPERR a raw pointer.
- Example: when SPERR takes in input from NetCDF libraries, and NetCDF provides a raw pointer.
- Example: when SPERR calls ZSTD compression routines.
- When SPERR has to interact with C libraries that use raw pointers.
- Example: when SPERR calls
fread()
andfwrite()
fromcstdio
. (This isn't really a good example because we should look into usingfstream
s provided by C++. - Example: when SPERR provides a C API to others.
- Example: when SPERR calls
- When doing type punning stuff.
- Example: when SPERR puts 8 bytes representing a
double
to an arbitrary position in an output stream. - Example: when SPERR reads in a file from disk as
uint8_t
s, and treats the stream asdouble
orfloat
values.
- Example: when SPERR puts 8 bytes representing a
- When SPERR borrows code from other open-source projects and it's hard to
convert it away from raw pointers.
- Example: SPERR uses wavelet transform code from QccPack, which is written using raw pointers, and it's a little tricky (but not impossible), to convert.
- Q: If I want to specify a function to process a specific range of a long array,
what are my options?
- A: Pass in the begin and end iterators of the range. This is the convention of modern C++.
Lossy Scientific data compression with SPERR