Kanban | Programming | Testing | Selenium | Scrum | Architecture Programming Without Ifs: Better Alternatives to Conditional Logic May 16, 2025
Neil Chaudhuri
LinkedIn

Neil Chaudhuri
LinkedIn
I have always stood on a programming soap box that conditionals and booleans are insidious. They are like the second thing we learn on the first day of class and are so straightforward, but before you know it, they’ve added so much sneaky complexity to our code in the real world! Here are a few alternatives to conditionals and booleans agnostic of programming language:
State machines
Use state machines to model your workflow rather than conditionals to test repeatedly where you are in a workflow. For example, XState in JavaScript/TypeScript and Temporal in many languages both provide state machines.
Content negotiation
If your API needs to respond with either JSON or XML based on an HTTP Accept
header, configure a post-processor that serializes the output
into the right rendering once you’ve represented it as an object in memory. For example, Spring Boot developers writing in Java and Kotlin do this with MessageConverter
s by default.
Maps
Use a map data structure rather than conditional logic to fetch data. Every language has maps.
Guards, filters, and interceptors
Different programming languages and frameworks use these terms in different ways, but broadly speaking, these are all ways inspired by Aspect-Oriented Programming to decouple the primary business logic of an HTTP API endpoint from cross-cutting decisions that have to be made in advance