Skip to content

Commit 0865857

Browse files
Merge pull request #8 from leapfrogtechnology/general-guidelines
General guidelines
2 parents af44f1a + 1ea9e61 commit 0865857

File tree

10 files changed

+143
-55
lines changed

10 files changed

+143
-55
lines changed

docs/02-1-files.md

Lines changed: 0 additions & 7 deletions
This file was deleted.

docs/02-2-classes.md

Lines changed: 0 additions & 8 deletions
This file was deleted.

docs/02-3-functions.md

Lines changed: 0 additions & 7 deletions
This file was deleted.

docs/02-4-variables.md

Lines changed: 0 additions & 7 deletions
This file was deleted.

docs/02-5-constants.md

Lines changed: 0 additions & 7 deletions
This file was deleted.

docs/02-6-folders.md

Lines changed: 0 additions & 7 deletions
This file was deleted.

docs/general-guidelines.md

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
---
2+
id: general-guidelines
3+
title: General Coding Standards
4+
---
5+
6+
* Firstly, it's recommended to use a static code analysis tools to analyze the code before it's pushed to the version control. For eg: eslint, tslint, pylint, codeclimate, sonar etc. Development Team should identify corresponding tool for their tech stack and use it to follow community wide general coding standards and avoid general bad practice.
7+
8+
* No hard coding, use constants/configuration values instead of hard-coding literal values.
9+
10+
* Do not store config as constants in the code. Use separate config files for storing application credentials such as passwords, access key etc. Make sure you add this file in .gitignore file.
11+
12+
* Group similar values under enums, constant groups or similar data structures depending on what the language allows.
13+
14+
* Avoid code duplication (DRY). If the same code needs to be reused in multiple places, create a extract a common function instead.
15+
16+
* While writing code make sure it doesn't violate SRP (Single Responsibility Principle). To be more specific take care of the following:
17+
18+
* A function/method should do only one task.
19+
20+
* A class should have only one concern or should take care of only one aspect.
21+
22+
* Avoid having more than 3 parameters in a function/method.
23+
24+
* Avoid creating God classes or utils that is capable of doing every thing from string manipulation to checking if user is authored. This is a big NO.
25+
26+
* Follow separation of concerns principles properly, and identify what type of code should go in which layer or tier eg: What type of code should be written in Model, View, Service and Controller etc.
27+
28+
* Write pure functions where ever possible. It keeps the code more understandable and deterministic, plus it helps to avoid unexpected run time issues due to mutation.
29+
30+
* If your project is following OOP approach, follow it precisely depending upon the language specific best practices. If the project is following a FP (Functional Programming) approach, use it's best practices. Don't try to mix multiple paradigm, which results in more chaos and confusion in the code.
31+
32+
* Avoid unnecessary else blocks as much as possible for better readability and cleanliness.
33+
34+
<!--JavaScript-->
35+
// Bad practice
36+
function nullIfEmpty(value: any) {
37+
if (typeof value === 'string') {
38+
return value.trim() === '' ? null : value;
39+
} else {
40+
return value;
41+
}
42+
}
43+
44+
// Good practice
45+
function nullIfEmpty(value: any) {
46+
if (typeof value !== 'string') {
47+
return value;
48+
}
49+
return value.trim() === '' ? null : value;
50+
}
51+
52+
* Avoid nested if blocks, multiple if blocks. No pyramid of doom.
53+
54+
* Break down or refactor code with complexity into multiple smaller chunks i.e functions/methods.
55+
56+
* DocBlocks / Doc comments – Add doc blocks for each and every function, class, interface, etc to clearly mention what they do. Docblocks also should mention the parameter types or return types clearly.
57+
58+
* Class level documentation, document public functions and interface. Follow language specific documentation standard.
59+
60+
* Also, make sure you write doc blocks, comments etc in proper english. Re-check your sentences, to ensure they're typo free.
61+
62+
* Different languages have different standards for doc blocks. Follow the language specific standard for doc blocks. For examples:
63+
64+
<!--JavaScript-->
65+
/**
66+
* Hit the twilio API to send notifications.
67+
*
68+
* @param {NotificationPayload} payload
69+
* @returns {Promise<object>}
70+
*/
71+
function sendNotification(payload: NotificationPayload): Promise<object> {
72+
return twilioClient.sendMessage(payload);
73+
}
74+
75+
<!--Python-->
76+
def rollback(id=None):
77+
'''
78+
Deployment rollback to the previous build, or
79+
the build identified by the given id.
80+
'''
81+
82+
(_, current_path) = setup_remote()
83+
history = load_history()
84+
85+
# If the current build in the history is not set yet or
86+
# there aren't any previous builds on the history
87+
# rollback is not possible.
88+
if not history['current'] or not history['builds']:
89+
remote_info('Could not get the previous build to rollback.')
90+
return
91+
...
92+
93+
* Avoid re-inventing the wheel. Use framework features, or utilities provided by libraries wherever possible instead of writing custom code.
94+
95+
* Don't hard-code text data/content in the code itself, instead put text content/messages in the internationalization files and use the content identifiers instead.
96+
97+
* Each Components, Classes, or Interfaces should be written in their own file. And the filename should be named same as it's identifier name. (This could be an exception for python).
98+
99+
* Follow language specific naming convention.
100+
101+
* Use PascalCase naming convention for Components, Classes, or interfaces, enums, or other custom types.
102+
103+
* Use camelCase for naming functions, variables etc.
104+
105+
* Use snake_case for naming database columns, table names etc.
106+
107+
* Use **CAPITAL_CASE_WITH_UNDERSCORES** for defining constants eg: const **PAGINATION_MAX_ROWS = 15**.
108+
109+
* Classes/Interfaces/Components/Services should be **named as a noun (singular)** as they represent a real world entity.
110+
111+
* For instance: **Person, PersonList, User, ArrayAggregator, PerformanceEvaluator, SourceAnalyzer, Inspector, TaskService, UserServiceTest** etc.
112+
Avoid prefixing them with verbs or naming them as plural entities. For example bad class names could be: **GetUser, Users, Todos, Listeners, GetUserById** etc.
113+
Functions or methods should be named as verbs or actions as they represent actions. So, function name should clearly say what that function does.
114+
Good function names: **getPersonList, fetchUsers, getCurrentUser, removeTodoItems, initialize, clear, flush, activate, isActive(), shouldNotify()**
115+
Bad function names are those that isn't meaningful to the task it does.
116+
117+
* A function should do one thing and should be named accordingly. **SRP(Single Responsibility Principle)** also applies here. If you have broken down the function following SRP then there won't be a function such as: **getUserByIdAndActivateItAndLogin**, **checkPeopleAndArchiveThem** (bad practice).
118+
119+
* All the releases should be properly tagged in git.
120+
121+
* Follow Major, Minor and Patch format. and include information about Production and Dev release.
122+
123+
* Patch - Bug fixes
124+
125+
* Minor - Feature additions/enhancements
126+
127+
* Major - Change in business logic.
128+
129+
* All the releases should be identified as pre-release in git if they are not released for production.
130+
131+
* Follow Gitflow.
132+
133+
* Sanity checklist document should be present.

docs/git/branching_naming_convention.md

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,10 @@ sidebar_label: Branch Naming Convention
77
#### The following convention should be followed:
88

99
* Branch name should exactly match with the corresponding JIRA ticket that you will be working on. `<project-name>-<ticket-number>`
10-
11-
Examples:
12-
* FHF-100
13-
* DEL-200
10+
* FHF-100
11+
* DEL-200
1412

15-
* If there's no JIRA or project management tool in use, the branch naming strategy should be feature specific.
16-
17-
Examples:
18-
* upgrade-php
19-
* add-button-tooltip
13+
* If there's no JIRA or project management tool in use, the branch naming strategy should be feature specific.
14+
* upgrade-php
15+
* add-button-tooltip
16+

docusaurus.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module.exports = {
2222
},
2323
{to: 'blog', label: 'Blog', position: 'left'},
2424
{
25-
href: 'https://github.com/facebook/docusaurus',
25+
href: 'https://github.com/leapfrogtechnology/coding-guidelines',
2626
label: 'GitHub',
2727
position: 'right',
2828
},
@@ -70,7 +70,7 @@ module.exports = {
7070
},
7171
{
7272
label: 'GitHub',
73-
href: 'https://github.com/facebook/docusaurus',
73+
href: 'https://github.com/leapfrogtechnology/coding-guidelines',
7474
},
7575
],
7676
},

sidebars.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ module.exports =
22
{
33
"docs": {
44
"Overview": [
5-
"introduction"
5+
"introduction",
6+
"general-guidelines"
67
],
78
"REST API": [
89
"rest-api/headers",

0 commit comments

Comments
 (0)