2
ltlian
6y

I've been getting a lot of mixed input on this lately and I'm curious to gauge the public opinion on it.

For key identifiers in key/value pairs (eg. days of the week, high/med/low, etc), is it preferable with semantic string naming wherever possible, or are int enums usually preferred for being more clean and robust?

I suppose it's a case of "it depends". I tend to use stringed keys myself since they are more readable but I do think it's a hassle with asserting case insensitivity and how the keys can be accessed as properties - "sometimes, probably".

People often comment on it when they see it, and it turns into this weird mutual "why strings?" vs. "why ints?".

Comments
  • 1
    @irene That's a good point and is actually one of the things that had me conflicted. I have this small set of none:0,low:1.5,high:2 .0 pairs and there's no readability to gain there. My only argument for it was "well I used named labels everywhere else ~"
  • 2
    @ltlian If you’re using a compiled language, an enum with static labels will give you the readability of strings, the safety of compile-time resolution, and zero cost to performance, unlike for example looking up a string at runtime (which is fast but not free). It’s pretty much win-win-win.
Add Comment