Good, clean code is like a good book - it's easy to understand and a pleasure to read.
❌ const d = new Date();
✅ const date = new Date();
❌ const dc;
✅ const daysCounter;
{
❌ const date1 = new Date('2014-09-16');
❌ const date2 = new Date();
}
{
✅ const firstDate = new Date('2014-09-16');
✅ const currentDate = new Date();
}
❌ const crymdhms; // creation year, month, day, ...
✅ const creationTimestamp;
Dog
Dog.bark()
Use get, set, is for accessor, mutators and predicates
✅ UserController, TransactionController, WalletController
❌ UserController, TransactionDriver, WalletManager
{
balance.add(2) // 2 + 2 = 4
transactions.insert(2) // [2, 2]
}
Computer science, math, algorithm terms, design patterns
❌ CoinMarket
✅ CoinMarketAPI
❌ InterestForArtistPayment
✅ RoyaltyPayment
❌
if (user.set('name', 'John')) { ... }
{
✅
user.set('name', 'John');
if (user.hasName()) { ... }
}
{
function logIn (userName, password) {
if (verifyPassword(userName, password)) {
setLoggedIn(userName);
❌ redirectToProfile();
} else {
showError('Incorrect credentials!')
}
}
{
function logIn (userName, password) {
if (verifyPassword(userName, password)) {
setLoggedIn(userName);
} else {
showError('Incorrect credentials!')
}
}
if(isLoggedIn()) {
✅ redirectToProfile()
}
}
❌
console.log(e)
✅
throw new Error(e)
❌
// Check if the employee is eligible for benefits
if (employee.hours === REQUIRED_HOURS && employee.age > 65)
✅ if(employee.isEligibleForBenefits())