Rethinking JavaScript: Eliminate the switch statement for better code
Joel Thoms

Hey, couple thought. Im not sure switch statements are impure. They can be if you cause side effects, but so could any function.

Second nested ternary are evil. Really no reason to use them. Instead of making your code easier to reason about as functional programming should do the make it considerably more difficult to read and reason.

Lastly you could also replace switch with command or strategy pattern. While polymorphism is difficult at best in js, you could easily implement using a collection of functions. I use an ioc container that I wrote, dagon (shameless plug), which let’s me inject a dep that is a collection of modules. I can group all the strategies in a folder, inject the collection and iterate over them till one matches.

All in all I am enjoying your functional articles. I’m glad the ideas are getting some exposure.

A single golf clap? Or a long standing ovation?

By clapping more or less, you can signal to us which stories really stand out.