Giter Club home page Giter Club logo

Comments (10)

mantovanig avatar mantovanig commented on May 12, 2024 3

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.

fagnervalente avatar fagnervalente commented on May 12, 2024 3

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.

kettanaito avatar kettanaito commented on May 12, 2024 2

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.

tomma5o avatar tomma5o commented on May 12, 2024

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.

mantovanig avatar mantovanig commented on May 12, 2024

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.

tomma5o avatar tomma5o commented on May 12, 2024

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.

mantovanig avatar mantovanig commented on May 12, 2024

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.

tomma5o avatar tomma5o commented on May 12, 2024

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.

mantovanig avatar mantovanig commented on May 12, 2024

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.

tomma5o avatar tomma5o commented on May 12, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.