Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XS✔ ◾ Rule changes for CTF #9611

Merged
merged 2 commits into from
Nov 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions rules/use-clear-meaningful-names/rule.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Names should always describe at first glance what something represents.

## ⚠️ Avoid mental encoding

It’s easy to invent codes to keep names short, like `cstmrMgr` to represent a "customer manager" - and you might feel clever doing it. But this kind of shorthand requires other developers (or your future self) to mentally decode each abbreviation. There’s no good reason not to simply call it `CustomerManager` (although there are reasons to avoid "manager" as a name, see [Do you avoid generic names like “manager,” “processor,” “data,” or “info”?](/avoid-generic-names)).
Keep names obvious. It’s easy to invent codes to keep names short, like `cstmrMgr` to represent a "customer manager" - and you might feel clever doing it. But this kind of shorthand requires other developers (or your future self) to mentally decode each abbreviation. There’s no good reason not to simply call it `CustomerManager` (although there are reasons to avoid "manager" as a name, see [Do you avoid generic names like “manager,” “processor,” “data,” or “info”?](/avoid-generic-names)).

## Be verbose

Expand All @@ -53,14 +53,18 @@ Full, meaningful words make your code readable and maintainable.
:::
:::bad
Bad example - Being clever for you can cause confusion to others - they might misinterpret "energy" as something else, like power or ammo. Then if you add enemies, would you name their energy variable `nmeNrg`?
:::
:::



:::greybox
`PlayerHealth` - clearly describes the specific kind of "energy" (health) and who it belongs to (the player)
:::
:::good
Good example - instantly understandable to anyone reading the code
:::
:::



Now let’s say you’re working on an invitation and activation feature. You need a variable to store the validity period for an invitation - the live time.

Expand All @@ -69,30 +73,37 @@ Now let’s say you’re working on an invitation and activation feature. You ne
:::
:::bad
Bad example - others will have fun deciphering this one
:::
:::



:::greybox
`InvitationTimeRemainingInDays` - no explanation needed here!
:::
:::good
Good example - leaves no room for misinterpretation and makes the purpose obvious
:::
:::

:::greybox
`UserValidator` - this class is responsible for validating a user
:::
:::bad
Bad example - Validating what exactly? Login credentials? Profile information? Something else?
:::
:::



:::greybox
`UserValidationHandler` - indicates it’s an engine responsible for executing multiple rules to handle user-related validation

`UserNameLengthValidator` - validator is for a specific aspect of a user - the length of a username
`UserEmailFormatValidator` - validator for another specific aspect - ensures email contains "@" and a domain
:::
:::good
Good example - the definition of the classes is in their names
:::
:::



:::info
**Remember:** Names should always describe what something represents without mental gymnastics to decode it.
Expand Down
Loading