Skip to content

Instantly share code, notes, and snippets.

@sapegin
Created May 30, 2023 08:23
Show Gist options
  • Save sapegin/a46ab46cdd4d6b5045027d120b9c967d to your computer and use it in GitHub Desktop.
Save sapegin/a46ab46cdd4d6b5045027d120b9c967d to your computer and use it in GitHub Desktop.
// How do you avoid name clashes between functions, variables, components, and types?
// OK
const crocodiles = getCrocodiles({ color: 'green' })
// ???
const isCrocodile = isCrocodile(crocodiles[0])
// OK
const user: User = { name: 'Chuck Norris' }
// ???
function User(props: { user: User }) => <p>{props.user.name}</p>
@sapegin
Copy link
Author

sapegin commented Jun 15, 2023

Thanks everyone for the great suggestions! @rauschma @darekkay @kosminen

I took many (combined with my own experience) for my book's chapter on naming:

https://github.com/sapegin/washingcode-book/blob/master/manuscript/Naming_is_hard.md#tips-to-avoid-name-clashes

@vitalets
Copy link

My suggestions:

// add "action" to function name, general pattern when storing variable from getter function: const xxx = getXxx()
const isCrocodile = getIsCrocodile(crocodiles[0]);

// name types / interfaces with "I":
const user: IUser = { name: 'Chuck Norris' }
function User(props: { user: IUser }) => <p>{props.user.name}</p>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment