-
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.
AliasSeq
can be used. - avoid unnecessary templates
- avoid use of Phobos (
std.traits
andstd.meta
are ok) - use fully qualified local imports (
std.algorithm.comparison : equal
instead ofstd.algorithm: equal
) - follow the D-Style
- avoid constraints for internal API
- don't duplicate API headers for internal functions
- provide
const
guarentees for parameters - use
scope
for function parameter where it can be used (combine withconst
toin
) - 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.math
usemir.internal.math
if possible (aliases to LLVM internals) - instead of
a / 2
use `a * S(0.5) etc - use type constructor
double(0.4)
- order structs after types (bool and enums at bottom)
- functions after
this
constructor
- infinite loops should use
for (;;)
instead ofwhile (true)
- if possible, replace
if
withswitch
- prefer
switch
withdefault
overfinal switch
(one jump less)