DEV Community

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

Collapse
 
grimthereaper profile image
Grim

I think that I'd prefer the if statements. Under the hood of whatever language you use, this is a more expensive operation, and things can go wrong if the map is messed with.

Collapse
 
tomazfernandes profile image
Tomaz Lemos

Hi Grim,

Just as a clarification, this map returns a immutable map, so you can’t really mess with it after it’s initialized.

As for the expensiveness, I don’t know if the Java compiler could do some kind of optimization for example.

Either way unless it’s a critical performance feature I prefer to optimize code for readability over what I think would be really small performance benefits.

Thanks for replying!