-
Notifications
You must be signed in to change notification settings - Fork 20
Developer guide
Sebastian Wilzbach edited this page Jun 29, 2016
·
7 revisions
A list of tips & tricks.
- no magic constants in code like
1e-6 - check for all types.
AliasSeqcan be used. - avoid unnecessary templates
- avoid use of Phobos (
std.traitsandstd.metaare ok) - use fully qualified local imports (
std.algorithm.comparison : equalinstead ofstd.algorithm: equal) - follow the D-Style
- avoid constraints for internal API
- don't duplicate API headers for internal functions
- provide
constguarentees for parameters - use
scopefor function parameter where it can be used (combine withconsttoin) - all non public code for testing should be in internal
- use local imports & avoid global imports (except for needed types for methods)
- no
^^-> use pow and powi (^^ isn't lowered to pow, this is an open bug in D) -
sgn->copysign - instead of
std.mathusemir.internal.mathif possible (aliases to LLVM internals) - instead of
a / 2use `a * S(0.5) etc - use type constructor
double(0.4)
- order structs after types (bool and enums at bottom)
- functions after
thisconstructor
- infinite loops should use
for (;;)instead ofwhile (true) - if possible, replace
ifwithswitch - prefer
switchwithdefaultoverfinal switch(one jump less)