all InfoSec news
Code Smell 145 - Short Circuit Hack
June 30, 2022, 1:37 p.m. | Maxi Contieri
DEV Community dev.to
Don't use boolean evaluation as a readability shortcut
TL;DR: Don't use Boolean comparison for side effect functions.
Problems
Readability
Side Effects
Solutions
- Convert short circuit into IFs
Context
Smart programmers like to write hacky and obscure code even when there is no strong evidence for this improvement.
Premature optimization always hurts readability.
Sample Code
Wrong
userIsValid() && logUserIn();
// this expression is short circuit
// Does not value second statament
// Unless the first one is true
functionDefinedOrNot && functionDefinedOrNot(); …
More from dev.to / DEV Community
Jobs in InfoSec / Cybersecurity
SOC 2 Manager, Audit and Certification
@ Deloitte | US and CA Multiple Locations
Security Architect - Hardware
@ Intel | IND - Bengaluru
Elastic Consultant
@ Elastic | Spain
OT Cybersecurity Specialist
@ Emerson | Abu Dhabi, United Arab Emirates
Security Operations Program Manager
@ Kaseya | Miami, Florida, United States
Senior Security Operations Engineer
@ Revinate | Vancouver