-
Notifications
You must be signed in to change notification settings - Fork 1
Code Style and Design Principles
Siqi Zhang edited this page Jul 15, 2019
·
2 revisions
- Use
<-
for assignment, not->
or=
- Functions purposed for side effect may return an invisible output that contains relevant information, if possible.
- Names for objects and functions should be nouns and verbs, in general.
- Names should be in
snake_case
, orSentence_snake_case
- Use OO system with strong justification only
- Choose S3 or R6, not S4 or RC
- When using R6, avoid complex design patterns
- Use loops with strong justification only
- Use
*apply
family, orpurrr
as alternatives - Choose
for...in
loop instead ofwhile
loop, wherever possible
- Use
- A functions written must have primary input as the first argument.
- When calling a function, all arguments must be named, except for the first or that of primary input.
- Do not use a long expression for argument default, use
NULL
and test for in function body. - Functions should be type stable