samedi 21 août 2021

Good practices in nested If conditions

Which of the below is a good practice. Second looks more readable for me but would like to know how others think.

Solution 1 :

case colorElementEnum.ICON:
        color = colors.buttonText;
        if (isHighContrast) {
          if (!titleColor) {
            if (disabled) {
              color = colors.lightGray;
            }
          }
        }
        return color;

Solution 2 :

case colorElementEnum.ICON:
        color = colors.buttonText;
        if (isHighContrast && !titleColor && disabled) {
              color = colors.lightGray;
        }
        return color;
  

Aucun commentaire:

Enregistrer un commentaire