2021-06-17
1152
#vanilla javascript
Juan Cruz Martinez
53152
Jun 17, 2021 â‹… 4 min read

Refactoring cascading conditionals in favor of readability

Juan Cruz Martinez I'm an entrepreneur, developer, author, speaker, YouTuber, and doer of things.

Recent posts:

Rust logo over black marble background.

Handling memory leaks in Rust

Learn how to manage memory leaks in Rust, avoid unsafe behavior, and use tools like weak references to ensure efficient programs.

Ukeje Goodness
Nov 20, 2024 â‹… 4 min read
Robot pretending to be a person.

Using curl-impersonate in Node.js to avoid blocks

Bypass anti-bot measures in Node.js with curl-impersonate. Learn how it mimics browsers to overcome bot detection for web scraping.

Antonello Zanini
Nov 20, 2024 â‹… 13 min read
Solving Eventual Consistency In Frontend

Solving eventual consistency in frontend

Handle frontend data discrepancies with eventual consistency using WebSockets, Docker Compose, and practical code examples.

Kayode Adeniyi
Nov 19, 2024 â‹… 6 min read
How To Use Lazy Initialization Pattern With Rust 1.80

How to use the lazy initialization pattern with Rust 1.80

Efficient initializing is crucial to smooth-running websites. One way to optimize that process is through lazy initialization in Rust 1.80.

Yashodhan Joshi
Nov 18, 2024 â‹… 5 min read
View all posts

3 Replies to "Refactoring cascading conditionals in favor of readability"

  1. Nice article, just one thing I’m not sure I’d the best advice, particularly to beginners –

    It’s often not considered a best practice to use `&&` and `||` operators as control flow.

    The main priority in code design should be readability, and for someone reading these, it primarily implies just a Boolean expression, rather than control flow. If/else is explicit control flow and so it’s much clearer, particularly when it’s contains side affects.

    Another problem with this approach is that it suggests fewer lines is better, when in some cases, like this one, fewer lines is just increasing the information density, and not making anything clearer.

  2. Excellent suggestions! All small readability improvements that my coworkers and I have been adopting recently. A fun note, for those using typescript and map objects, try using Record.

Leave a Reply