-
Notifications
You must be signed in to change notification settings - Fork 307
Coding Standards
Every program file should have the author's name and email-id at the start of file. Also, there should be a short descripion of your code, what is does and how it works.
At the end of file, mention time complexity and space complexity of your code.
// Name: Vikas Gola
// Email-id: [email protected]
// This code finds the maximum integer in int array
int findMax(array){
// let first element is max in array
int max = array[0];
for(int i=1;i<length_of_array;i++){
// checking for bigger number than current max
if(max > array[i]){
max = array[i];
}
}
return max;
}
...
// Time Complexity: O(n)
// Space Complexity: O(1)
You can use one of the indenatation style in your files from these but not both at the same time.
Indentation of every next level of block of code from the previous should be indent with 4 spaces or 1 tab. In the following example, if block have one level higher indentation than the for block.
Note:- Pull Requests having codes with bad indentation might be rejected.
for(int i=0;i<10;i++){
if(some_condition){
// your code goes here
}
}
Every code should have well written comments and they should use //
. Comments with /* */
are not allowed.
// calculate sum of even numbers from 0 to 10.
int sum = 0;
for(int i = 0;i<=10;i++){
// check for even numbers and add it to *sum*
if(i%2 == 0){
sum += i;
}
}
variables, constants, class names, function names etc. should have there names according to convention as discussed below.
- Try to keep names of variable, consts etc as clear as possible.
- Use UPPERCASE letters for constants
- Use UpperCamelCase convention for class naming.
- Use snake_case convention for variable naming.
- Use lowerCamelCase convention for functions etc.
// UPPERCASE letters
const PI = 3.1415
// UpperCamelCase
class YourClass{
// ...
}
// snake_case
int name_of_variable;
// lowerCamelCase
void findMinimum(){
// ...
}
Use spaces where it needed and make it look as clear as possible. Don't try to write 2-3 lines of code in one line and if you do make it clear. Don't make lines of code too lengthy.