Tom Clark
Aug 10, 2024

--

Lots of languages (even mainstream ones like Python) have no switch statement (probably because of the zen of Python: there should be one, and preferably only one, way to do something!).

So I prefer if-else knowing that programmers from a wider variety of languages will be able to read and understand the functionality of my code.

(Also because I grew up in those languages… so, you know, habit!)

A big exception is if I’m writing in JavaScript; you commonly find cases where you want a big set of switch statements (eg redux reducers) and the syntax is neater in my opinion

--

--

Tom Clark
Tom Clark

Written by Tom Clark

Fluid Dynamicist at the core, lover of chaos theory. Experienced scientist, developer and team lead working in wind energy — from startups to heavy industry.

Responses (3)