Read: Case Styles: Camel, Pascal, Snake, and Kebab Case
Read: What is camelCase, PascalCase, kebab-case and snake_case?
There is no accepted best practice on which case is the best to use. You may use any style you like to name your variables and functions, however it is important to remain consistent in using that style. Mixing styles is generally considered bad practice and must be avoided.
Bad Inconsistent Style:
let name = "John";
let Age = 25;
let is_married = false;
let salaryDetails = {
company_name: "MountBlue",
CompanyAddress: "Bangalore",
amount: 10000,
};
function PrintDetails() {
console.log(name, Age);
console.log(salaryDetails);
console.log(is_married ? "Married" : "Single");
}Good Consistent style:
let name = "John";
let age = 25;
let isMarried = false;
let salaryDetails = {
companyName: "MountBlue",
companyAddress: "Bangalore",
amount: 10000,
};
function printDetails() {
console.log(name, age);
console.log(salaryDetails);
console.log(isMarried ? "Married" : "Single");
}Here camelCase has been used, but you may use whatever style you prefer such_as_snake_case or PascalCase, as long as you remain consistent with your usage of that case.
Do not use thISWayOFNaMiNg.
Keeping your variable names as descriptive as possible includes naming variables in loops as well.
Bad Naming:
for(let i = 0; i < numbers.length; i++) {
console.log(numbers[i]);
}Good naming:
for(let index = 0; index < numbers.length; index++) {
console.log(numbers[index]);
}This applies to naming them when using higher order array methods as well:
Bad Naming:
const squares = numbers.map((number, i) => {
console.log(i);
return number * number;
})Good naming:
const squares = numbers.map((number, index) => {
console.log(index);
return number * number;
})Similarly, when working with matrices:
Bad Naming:
for(let i = 0; i < matrix.length; i++) {
for(let j = 0; j < matrix[i].length; j++) {
console.log(matrix[i][j]);
}
}Good naming:
for(let rowIndex = 0; rowIndex < matrix.length; rowIndex++) {
for(let columnIndex = 0; columnIndex < matrix[rowIndex].length; columnIndex++) {
console.log(matrix[rowIndex][columnIndex]);
}
}Though it is often better to be explicit with it as well:
Explicit and good naming:
for(let rowIndex = 0; rowIndex < matrix.length; rowIndex++) {
let row = matrix[rowIndex];
for(let columnIndex = 0; columnIndex < row.length; columnIndex++) {
console.log(row[columnIndex]);
}
}Improving your code readability is key to making it easier to work with your code for yourself and for everyone who works with your code.
An easy way to do that would be to add new lines between declaration and operations parts of your code.
Poor Readability:
const fs = require("fs");
let numbers = [1,2,3,4,5];
let pi = 3.14;
let squares = numbers.map(number => number * number);
console.log(squares);Good Readability
const fs = require("fs");
let numbers = [1,2,3,4,5];
let pi = 3.14;
let squares = numbers.map(number => number * number);
console.log(squares);An example without declaration:
Bad Readability:
function problem1(inventory, id){
if(!inventory || !id) return [];
for(let cars of inventory){
if(cars.id===id){
return cars;
}
}return [];
}
module.exports=problem1;Good Readability:
function problem1(inventory, id){
if(inventory == undefined || id == undefined) {
return [];
} else {
for(let cars of inventory){
if(cars.id === id){
return cars;
}
}
return [];
}
}
module.exports = problem1;Best Practices When Starting NodeJS Projects https://www.youtube.com/watch?v=X_UQbPnvSx4
Download the data from: https://www.kaggle.com/manasgarg/ipl
There should be 2 files:
- deliveries.csv
- matches.csv
In this data assignment you will transform raw data of IPL to calculate the following stats:
- Number of matches played per year for all the years in IPL.
- Number of matches won per team per year in IPL.
- Extra runs conceded per team in the year 2016
- Top 10 economical bowlers in the year 2015
Implement the functions, one for each task. Use the results of the functions to dump JSON files in the output folder
- Create a new repo with name js-ipl-data-project in Gitlab subgroup, before starting implementation of the solution
- Make sure to follow proper Git practices
- Before submission, make sure that all the points in the below checklist are covered:
- Git commits
- Directory structure
- package.json - dependencies, devDependencies
- .gitignore file
- Proper/Intuitive Variable names
- Separate module for functions
- src/
- server/
- 1-matches-per-year.js
- 2-matches-won-per-team-per-year.js
- public/
- output
- matchesPerYear.json
- ...
- output
- data/
- matches.csv
- deliveries.csv
- server/
- package.json
- package-lock.json
- .gitignore