Timeline for Private string constants for map keys
Current License: CC BY-SA 3.0
3 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Mar 25, 2016 at 14:15 | comment | added | sara | Well, assuming that your design in general is sound, I'd still say it's a lot better to represent a key by a constant symbol rather than by a literal. Ignoring the advantages like mitigating the risk of spelling errors, letting you change the value of the symbol rather than searching up each individual literal and so on, it's just good practice. If you feel like you get few benefits today, this lays a good foundation for tomorrow. If you put a key into a map, you'll get it out at some point, so you're almost guaranteed 2 usages. DRY kicks in right away. To me a const beats a literal any day. | |
| Mar 25, 2016 at 13:56 | comment | added | Karol Lewandowski | In my real project such classes create and render JSON objects. Values are evaluated basing on complex algorithms or retrieved from database. I will correct key names to make them more abstract. I agree that they can be confusing now. | |
| Mar 25, 2016 at 13:50 | history | answered | sara | CC BY-SA 3.0 |