Carlos Obregón
Java Champion with 15 years of experience in software programming
if (StringUtils.isNotBlank(resultStatus)) {
if (resultStatus.equalsIgnoreCase(ERROR)
&& errorCode != null
&& StringUtils.isNotBlank(errorMessage)) {
obj.addProperty(STATUS, FAILURE);
if (errorCode == 361
&& errorMessage.localeCompare("unique_violation")) {
obj.addProperty(STATUS, UPDATE);
} else {
obj.addProperty(STATUS, FAILURE);
throw new ABCException(errorMessage);
}
} else if (resultStatus.localeCompare("ok")) {
obj.addProperty(STATUS, SUCCESS);
} else {
obj.addProperty(STATUS, FAILURE);
throw new ABCException(errorMessage);
}
} else {
obj.addProperty(STATUS, FAILURE);
throw new ABCException(errorMessage);
}
return convertedObject;
if (n % 2 == 0) {
// ¿Cuándo se ejectura?
}
if (n % 2 == 1) {}
if (n % 2 != 1) {}
if (n % 1 % == 0) {}
function esPar(n) {
return n % 2 == 0;
}
function esImpar(n) {
return !esPar(n);
}
if (esPar(n)) {
// ¡Nunca hay ambigüedad!
// siempre y cuando sepas leer
}
function esPar(n) {
return (n & 1) === 0;
}
class Sieve {
constructor(maxPrime) {
this.maxPrime = maxPrime;
createSieve();
uncrossAllNumbers();
crossObviousNumbers();
crossMultiplesOfKnownPrimes();
}
}
function ellipsy(text) {
if (text.length < 250) {
return text;
}
const cutIndex = firstSpaceAfter(text, 250);
const shortText = text.substring(0, cutIndex);
return `${shortText} …`;
}
function foo() {
if (condition) {
// code
// code
// code
// code
// code
} else {
// error handling
}
return ...;
}
function foo() {
if (!condition) {
return ...;
}
// code
// code
// code
// code
// code
return ...;
}
function foo(abc, def, ghi) {
if (!abc) {
throw new Error();
}
if (def <= 0) {
throw new RangeError();
}
if (!(ghi instanceof Function)) {
throw new TypeError();
}
// 😞
}
function bar(abc, def, ghi) {
Preconditions.requireNonNull(abc);
Preconditions.requirePositive(def);
Preconditions.requireFunction(ghi);
// 😃
}
function bar(abc, def, ghi) {
checkPreconditions(abc, def, ghi);
// 😃
}
By Carlos Obregón
¿Por qué el Código Limpio es tan importante? ¿Cuáles son los principios fundamentales del código limpio?