As I said in my reply to Adam Hladik above, from a performance standpoint, I think the compiler is going to optimize a switch statement with static cases, a series of if/else statements with static conditions, or an object literal into similarly performant hash tables. Yes, there's more memory to potentially allocate for an object versus (e.g.) a switch statement, but I suspect that the compiler will only allocate as many pages as the static object needs with instructions to allocate more pages on the fly if needed.

As for readability, I find lookup tables eminently readable, but I'm an old Perl hacker and "hashes" (in the Perl sense) are second nature to me. :D

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Aurelia Fenderson-Peters
Aurelia Fenderson-Peters

Written by Aurelia Fenderson-Peters

20+ years writing code of various sorts. Full of trans magic.

No responses yet

Write a response