DEV Community

Discussion on: Keeping your code clean by sweeping out "if" statements

 
khtony profile image
Breton F

@Rasmus

We may not see the problem with the same lens. I ll just try to make my points clearer. Hope we could agree later.

A map is a contract and practically a function. You give it a key it does some magic and return back to you a value. Your map implementation is up to you. So by providing a specific map and boom you can do stuff of your imagination. This for me is flexibility as you pick your map based on your requirements.

Unit tests burden
With the map/function version, I give a key and I get back a value. I do not need to go for all possible keys for my unit tests. Because what I m interesting in is the contract i.e ability here to translate an error code to something else.