-
Notifications
You must be signed in to change notification settings - Fork 13
1. Principles & Conventions
Following is an outline I've put together of a few coding guidelines to help you all understand my code and in your own programming.
By far the most important is the SOLID principle (this will make you a better programmer!), available here: https://youtu.be/huEEkx5P5Hs
I will leave you to look it up (many articles available online), but here are the five points (the first one/two are most important!):
- S — Single responsibility principle (A class/function must not have/accomplish more than one purpose!)
- O — Open closed principle (A class's functionality must be closed for modification but open to extension!)
- L — Liskov substitution principle
- I — Interface segregation principle
- D — Dependency Inversion principle
A class encompasses Functionality, Input and Output. the Functor Class Design Principle allows creating an object that behaves like a function. By definition it must have an operator()() function, which executes its funcitonality.
You provide it input either as parameters, or through an "Input Class" (either through the operator or an Init(...) function). You can also access its output results either as internal members, or regroup them in a "Result Class".
- Class FunctorParams { ... }
- Functor functor;
- functor(FunctorParams); OR functor.SetParams(FunctorParams);
- Class FunctorResults = functor.GetResult(); OR Class FunctorResults = functor._results;
I typically create data by value in the root module, and then pass it to subsequent modules or store it in dependent classes by pointer, to minimize data reallocation/unnecessary memory usage caused by passing by value.
I also avoid passing by reference, because it gets tricky with constructor Member Initialization Lists (i.e. a reference value MUST be initialized in the constructor, whereas a pointer can be declared/passed as NULL).
The following rules must be applied to all declarations.
- Variables: camelCase
- Functions/Classes/Enum values: PascalCase
- Class Member Variables: underscore _camelCase
- File Name (.cpp/.h): PascalCase (least specific first, omit redundant terms)
- Hit Ctrl+Shift+F
- Enable "Use Regular Expressions"
- Look in "Entire Solution"
- Search for ^(?([^\r\n])\s)[^\s+?/]+[^\n]$
- Scroll down to bottom of search window
- Line count indicated by "Matching Lines"