Esneyder Amin Palacios Mena
Software engineer at @livevox | co-founder of @H4ckdo
Sr. Software Engineer at @livevox, co-founder of @hackdo
Clean Code with Javascript
Talk:
Son una serie de normas y practicas que nos ayudan ha escribir codigo de calidad, facil de entener, probar y de mantener a lo largo del tiempo.
const nombre = "Andrea";
const age = 20;
console.log(`Mi nombre es: ${nombre} y tengo ${age}`);
const a = Date.now();
const b = 22;
const c = prompt();
const d = build(a, b, c);
// d ???
const age = prompt("Please insert your age");
const name = prompt("Please insert your name");
const currentTime = Date.now();
const user = buildObjectUser(currentTime, age, name);
function buildObjectUser(time, age, name) {
if (time <= 340548639 && age >= 19 && age <= 25) {
return { time, age, name, promition: true };
}
return { time, age, name, promition: false };
}
function buildObjectUser({ currentTime: time, age, name }) {
const isValidTime = time <= 340548639;
const hasMinimumAge = age >= 19;
const hasMaximumAge = age <= 25
const isValidForPromition = isValidTime && hasMinimumAge && hasMaximumAge;
if (isValidForPromition) {
return { time, age, name, promition: true };
}
return { time, age, name, promition: false };
}
const age = prompt("Please insert your age");
const name = prompt("Please insert your name");
const currentTime = Date.now();
const user = buildObjectUser({ currentTime, age, name });
function buildObjectUser({ currentTime: time, age, name }) {
const isValidTime = time <= 340548639;
const hasMinimumAge = age >= 19;
const hasMaximumAge = age <= 25
const isValidForPromition = isValidTime && hasMinimumAge && hasMaximumAge;
return { time, age, name, promition: isValidForPromition };
}
function applyPromotion(user) {
if (user.promotion) {
processPromotion();
return true;
} else {
rejectPromotion();
return false;
}
return false;
}
if (user.promotion) {
applyPromotion(user.promotion);
} else {
rejectPromotion();
}Buena practica
Minimiza la probabilidad de introducir bugs
Software confiable y robusto
// https://jestjs.io/
//
test('promotion should be true', () => {
const paylaod = { currentTime: 236763, age: 20, name: "Paola" }
const user = buildObjectUser(payload);
expect(user.promotion)).toBe(true);
});
test('promotion should be false', () => {
const paylaod = { currentTime: 236763, age: 40, name: "Paola" }
const user = buildObjectUser(payload);
expect(user.promotion)).toBe(false);
});
Sr. Software Engineer at @livevox, co-founder of @hackdo
By Esneyder Amin Palacios Mena