Simple clean code #1
Dec 02, 2024 am 08:01 AMChange this:
if (user.active === true && user.age >= 18 && user.email !== null && user.email !== undefined && externalParams === true) return true;
To this:
const { active: userIsActive, age: userAge, email: userEmail } = user; const minimalAge = 18; const userAgeIsValid = userAge >= minimalAge; const userHasConditionsToRegister= userIsActive && userAgeIsValid && userEmail && externalParams; if (userHasConditionsToRegister) return true;
You might be thinking, "But you've increased the code by a lot, before, I only had one line!" And yes, you're absolutely right! However, fewer lines of code aren't always better than more lines.
When working with other developers and frequently maintaining the codebase, small details like the ones I've shown can make a big difference. In just a few seconds, anyone can understand the logic and rules behind the code. Additionally, if you need to add another condition, it becomes easy and clear to do so.
The above is the detailed content of Simple clean code #1. For more information, please follow other related articles on the PHP Chinese website!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Replace String Characters in JavaScript

Custom Google Search API Setup Tutorial

8 Stunning jQuery Page Layout Plugins

Improve Your jQuery Knowledge with the Source Viewer

10 Mobile Cheat Sheets for Mobile Development
