DEV Community

Discussion on: How to write cleaner functions.

Collapse
 
patricnox profile image
PatricNox

Interesting article you wrote there!

However,
I don't really agree with the switch case argument.

Arguably, it's way more clean looking when it comes to input handling. I tend to use it for preprocessing variables before transmitting them to a output or similar, it's nice to have them scoped.

Besides, 5 if conditions looks quite bad. Refactored to s switch case looks way better and much easier to read.

I'd probably also would love for the article to provide more proof of concepts to the arguments written.

it's very nice anywho. ✔️

Collapse
 
rektdeckard profile image
Tobias Fried

Kotlin when statement/expressions FTW

Collapse
 
genspirit profile image
Genspirit

Personally, I'm a fan of just using a Map instead of a switch. For me switch statements just seem overly verbose and less intuitive.

Collapse
 
olayemii profile image
OLayemii

Totally agree, switch is cleaner..

Collapse
 
singh1114 profile image
Ranvir Singh • Edited

I have to totally agree with @genspirit up here. Even I always prefer Map, dicts against switch statements. I have updated the article accordingly. Do give a look and let me know.