Clean Code: Naming functions and variables #26883
Replies: 4 comments
-
I think the context with regards to which this example comes into context is necessary here. Usually, flags (in this case, refered to as boolean variables) themselves aren't usually a great idea, but here, one can mistake them for functions (like if |
Beta Was this translation helpful? Give feedback.
-
@Lofty-Brambles Thank you for your insightful response. As a beginner in the field, I appreciate your perspective on the potential confusion that can arise from using In my research, I've found that the use of It's worth noting that the example code you provided, After a little more research, it appears to be a topic that sparks debates within the programming community, with varying opinions on whether to adopt these prefixes or opt for alternative naming conventions. Even when considering a different naming convention for the curriculum, it's important to acknowledge that the prefixes I think considering these facts and updating the curriculum to provide a broader understanding of this topic would be beneficial. |
Beta Was this translation helpful? Give feedback.
-
@TheOdinProject/javascript Can someone respond please. |
Beta Was this translation helpful? Give feedback.
-
Closing in favour of #28643 |
Beta Was this translation helpful? Give feedback.
-
Describe your suggestion
Under the section "Naming function and variables", the guideline suggests that
const isSelected = true;
is bad practice because it starts with "is", which goes against the recommendation that "variables should always begin with a noun or an adjective". I believe this might be a misconception. In fact, for boolean variables, it's actually a common and good practice in the JavaScript community to prefix withis
,has
, orcan
.These prefixes make it clear that the variable represents a boolean value, thereby enhancing the readability of the code. This convention is widely accepted and recommended in various coding standards and guidelines.
For instance, a variable like
isSelected
clearly indicates that it holds a boolean value, representing whether something "is selected" or not. This makes the code more understandable to the reader.Here are some references that support this convention:
I believe an update to this guideline in your curriculum would be beneficial for learners, especially beginners who are trying to grasp good coding practices. Thank you for considering my suggestion.
Path
Foundations
Lesson Url
https://www.theodinproject.com/lessons/foundations-clean-code
Checks
(Optional) Discord Name
developer007
(Optional) Additional Comments
No response
Beta Was this translation helpful? Give feedback.
All reactions