-4
\$\begingroup\$

I'd be afraid of the efficiency. Is there a better way?

\$\endgroup\$
1
  • 5
    \$\begingroup\$ What do you mean by "resource locator"? When and in which context and how often do you want to use it? Why do you prefer a string over an enum? Which language and platform? There are a lot of question marks left open, that make it nearly impossible to give you a reasonable answer. Voting to close as this is not a real question in its current state. \$\endgroup\$ May 22, 2013 at 18:03

1 Answer 1

1
\$\begingroup\$

Yes, it's perfectly fine to use a string as a key to look up resources. The "efficiency" of the check (the string comparison) isn't that damning on its own, especially if you do it intelligently and employ reasonable caching behavior, and so on.

A string has several advantages as well, such as affording you more data-driven flexibility than an enumeration will (since adding or changing enumerations usually means rebuilding code).

If the string look-ups ever do become a problem, according to your profiler, you can consider changing them to something else at that point.

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged .