Created
May 30, 2023 08:23
-
-
Save sapegin/a46ab46cdd4d6b5045027d120b9c967d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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> |
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
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