Abdelrahman Awad
Software Engineer @Rasayel. Open-Source contributor.
For Simple Code
class Trnsltr {
}
You increased productivity by skipping 3 letters 👏
⛔
class Translator {
// ...
}
You increased productivity by skipping 3 letters 👏
✅
class UserService {
fetch (applicationId) {
// ...
}
}
Obviously you will always fetch users by their application id, duh!
class UserService {
fetchByApplicationId (id) {
// ...
}
}
✅
for (let x of things) {
// ...
}
✅
for (let thing of things) {
// ...
}
🛑
class Todo {
updateTodo () {
// ...
}
}
const todo = new Todo();
todo.updateTodo();
✅
class Todo {
save () {
// ...
}
}
const todo = new Todo();
todo.save();
🛑
function _getTargetNames(field, ruleSchema, ruleName) {
if (ruleSchema.params) {
const numTargets = ruleSchema.params.filter(param => param.isTarget).length;
if (numTargets > 0) {
const names = {};
for (let index = 0; index < ruleSchema.params.length; index++) {
const param = ruleSchema.params[index];
if (param.isTarget) {
const key = field.rules[ruleName][index];
const name = field.names[key] || key;
if (numTargets === 1) {
names._target_ = name;
break;
} else {
names[`_${param.name}Target_`] = name;
}
}
}
return names;
}
}
return {};
}
async function process () {
const user = new User();
if (user.isActive) {
const paymentMethod = await user.getPaymentMethod();
if (paymentMethod) {
if (paymentMethod.type === 'card') {
const validated = await paymentMethod.checkCVC();
if (!validated) {
console.log('User did not type their CVC correctly');
return false
} else {
await paymentMethod.pay(1200);
await paymentMethod.finalize();
return true;
}
} else if (paymentMethod.type === 'cash') {
await paymentMethod.finalize();
return true;
}
} else {
console.log('User does not have a payment method');
return false;
}
} else {
console.log('User is not active');
return false;
}
}
By Abdelrahman Awad