Today, I found myself in a spirited debate with a fellow developer who specializes in Java back-end while I handle the front-end with JavaScript Angular. The REST service he provides sends me an object containing an enum, which I receive as a string and need to display in an Angular grid.
The enums themselves are quite self-explanatory.
Here are some examples of what I receive:
Person = {gender: "MAN", position: "IS_EMPLOYED"}
In the view, I need to show it as follows:
man is employed
My solution was simple yet effective:
Person.gender.toLowerCase() + ' ' + Person.position.toLowerCase().replace('_', ' ')
However, my counterpart found this method appalling and insisted that I create a mapper using if-else or switch statements like so:
If(Person.gender==="MAN") return "man"
Else if....
It's worth noting that the label name always matches the enum name, albeit in lowercase with spaces instead of underscores.
He expressed his strong disapproval of my approach, going as far as to call it bad coding, terrible, even sinful...
So the question remains: Is this practice considered good or bad (black-or-white), or can it be defended in certain scenarios?
Typed on my mobile device, hence the code examples not being enclosed in proper tags.