Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Maybe a naive question, please forgive if it is, but why does using a string make it harder to maintain?


As InclinedPlane said, Enums are more DRY and less error-prone. Even if you have to parse a String to an Enum, you only have to do it in one place (in the Enum definition), and then you only work with known objects. Also, if you want to refactor/auto replace, with an Enum object you are sure the value is correctly replaced everywhere (as the IDE knows to handle Enum), but if you want to replace a String you have to check all the occurrences of the string by hand, because some of them may be used for other purposes.


Enums are more "DRY"




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: