Comments (10)
It's a pretty strong rule, I agree about readability but it adds a lot of verbosity and repetition in variable names.
Also this is a generic guideline and not just for JS, in other languages I think they use the word List to differentiate from Maps or other types.
I think I prefer to enrich the name of the variable with what it contains:
var userNames = ['Gabri', 'Tom', 'Dave']
In this way we have more confidence about the type of value, names implies string.
from naming-cheatsheet.
Hi, I agree with in languages that there is a List type this have a different meaning, but in JS there are two more points to use.
- Some English words does not add 's' in the end in plural form and this contributes to typos for non-English speakers.
- Prefixes and suffixes do a better job of exposing the purpose of the variable
IMHO
from naming-cheatsheet.
Hey. Thanks for suggesting this.
Also this is a generic guideline and not just for JS, in other languages I think they use the word List to differentiate from Maps or other types.
This is an excellent point. "List" may indeed mean different things cross-languages and suggesting it in these guidelines may color them towards certain languages more than others.
That being said (and I think I should mention this in the guidelines), none of the suggestions on this page are written in stone. It's possible to deviate from them and it's perfectly fine. One of such deviations may be the addition of the List
suffix to a variable name that represents a list of values. There's nothing wrong with it. Just keep in mind that it's quite context-dependent and perhaps not generic enough to recommend.
from naming-cheatsheet.
Ok i don't know if there are some issue in some language but we find the same repetition in other cases for example in naming function like: shouldUpdate.
users or userNames doesn't fix the problem, i've used that just for example.
from naming-cheatsheet.
Yes probably it doesn't completely solve the problem you described and it doesn't fit with any situation but sometimes it can help.
Adding List
or relative type (Array, Set, etc...) to all variable names is referred to as "Hungarian Notation", and is considered bad (and useless) practice especially if you are using a statically typed language. These are some useful references:
https://en.wikipedia.org/wiki/Hungarian_notation#Disadvantages
https://www.joelonsoftware.com/2005/05/11/making-wrong-code-look-wrong/
from naming-cheatsheet.
I agree with @fagnervalente,
for example:
policy → policies
much better policyList
IMHO
The Hungarian notation @mantovanig is an entire code style, here we are discussing just for arrays and just to understand the type at first glance like for boolean types (isVisible
)
from naming-cheatsheet.
I don't think preventing typos for non-English speakers is the goal of these conventions, but maybe it can be for a specific team.
The Hungarian notation @mantovanig is an entire code style, here we are discussing just for arrays and just to understand the type at first glance like for boolean types (isVisible)
It's a naming convention, and here we are discussing about naming conventions. The example about boolean types is a bit different, you are not repeating the type inside the name. IMHO
from naming-cheatsheet.
It's a naming convention, and here we are discussing about naming conventions. The example about boolean types is a bit different, you are not repeating the type inside the name. IMHO
Yes is a naming convention but talks about all the types not only list, and I agree with you naming things fpBatteryPercentage
or nSize
doesn't make any sense, and this is probably why is a bad practice.
Btw Hungarian notation is a little bit different see example here:
https://en.wikipedia.org/wiki/Hungarian_notation#Examples
Hungarian rgUser
Proposal userList
from naming-cheatsheet.
I understand that your proposal is only for arrays but the concept is the same, except that in your proposal it is suffixed.
In Systems Hungarian notation, the prefix encodes the actual data type of the variable.
from naming-cheatsheet.
Btw List
is only the way to define a plural not the type.
We have redundancy if we use for example usersList
from naming-cheatsheet.
Related Issues (20)
- Plurals Considered Harmful HOT 4
- Add recommendation on how to handle unsafe async / remote fetch functions HOT 4
- isRoot or hasParent? HOT 2
- Incorrect order of arguments HOT 1
- React prop: disabled Vs. isDisabled HOT 4
- Role-based names vs. Information Repetition HOT 1
- JavaScript getter/setters (S|Get keyword) HOT 5
- Use of singular/plurals for compound terms HOT 2
- add translation version link in readme.md HOT 4
- verb suggestions HOT 2
- Negative boolean variable names HOT 1
- Counter-example to avoiding `a` as a variable name HOT 1
- Why can't I jump to the anchor link in the Readme document? HOT 2
- Suggestion: difference between verb `remove` and `delete` HOT 2
- Questions about naming functions? HOT 1
- Suggestion: Change [Reflect the expected result] to [Reflect the positive result]
- What about abbreviation / Acronyms? HOT 1
- State-of-being verbs HOT 1
- Add Create Action
- [suggestion] Add type naming conventions & recommendations
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from naming-cheatsheet.