What about Magic strings?
See original GitHub issueDo you think that can be good to include something about magic strings?
Bad:
let posts = getPostsFromCategory('sports');
Good:
const categories = {
sports: 'sports',
economy: 'economy'
};
let posts = getPostsFromCategory(categories.sports);
Issue Analytics
- State:
- Created 7 years ago
- Comments:12 (3 by maintainers)
Top Results From Across the Web
Magic Strings - DevIQ
Magic strings are string values that are specified directly within application code that have an impact on the application's behavior.
Read more >Magic string - Wikipedia
In computer programming, a magic string is an input that a programmer believes will never come externally and which activates otherwise hidden functionality...
Read more >What is wrong with magic strings?
If a magic string is being written in multiple places you have to change all of them without any safety (such as compile-time...
Read more >The Magic Strings Anti-Pattern - Develpreneur
“Magic strings are string values that are specified directly within application code that have an impact on the application's behavior.
Read more >TypeScript - Taking The Magic Out of Magic Strings
Magic strings are string literals strewn about a code base that apply some kind of limitation to the code. They can be used...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Keyboard keycodes are another example you see in the front-end JavaScript world, where you have something like:
This is typically how I do things. I’ll also go a step further and add enums statically to my classes for more organized namespacing (rather than just having randomly floating constant objects).
This allows me to keep the enums very close to their intended usage. And it’s easier to expose since I don’t have to go around creating some unrelated global / flat constants container object.
person.gender
can be one ofPerson.GENDERS
in essence.