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

How should we name numeric properties? #60

Open
ThijsTyZ opened this issue Feb 17, 2021 · 9 comments
Open

How should we name numeric properties? #60

ThijsTyZ opened this issue Feb 17, 2021 · 9 comments
Assignees
Labels
question Further information is requested

Comments

@ThijsTyZ
Copy link

ThijsTyZ commented Feb 17, 2021

Let's assume there is a carousel and you can specify the amount of items that is visible at once. What would be a good name for that property? numVisibleItems? visibleItemCount? visibleLength? Something else?

It would be good if we have a standardized way for this so it is immediately clear what the purpose of a property like that is.

@ThijsTyZ ThijsTyZ added the question Further information is requested label Feb 17, 2021
@ThijsTyZ ThijsTyZ self-assigned this Feb 17, 2021
@pigeonfresh
Copy link
Contributor

I tend to use itemsInView

@Miguel-Bento-Github
Copy link
Contributor

This might depend on the language we use. I understand why you want numVisibleItems in JS but itemsInView in TS would probably be enough.

@ThijsTyZ
Copy link
Author

itemsInView sounds like an Array of items that is currently in view. Not like the number of items that is in view.

@ReneDrie
Copy link

numVisibleItems is not even allowed right? As it's a abbreviation of number? I use itemsInView for that as well, could also be totalItemsInView if that makes more sense.

@qiyu1987
Copy link

I would probably vote for visibleLength, or visibleItemsCount, the others seems can also mean array of items

@pigeonfresh
Copy link
Contributor

The only way to make these names 100% unambiguous is by naming it like: numberOfCarouselItemsInViewport. If you create a static of the type number I think something like DraggableCarousel.itemsInView gives enough information :)

@Miguel-Bento-Github
Copy link
Contributor

I feel like in a strongly typed language we shouldn't need the variable name to have a type.

@ThaNarie
Copy link
Member

Type information is not always (quickly) available when reading code. Like in online environments when reviewing the work.

So in my opinion, everything we can do to reduce ambiguity in naming will drastically improve the readability and understandability of the code. Finding the right balance is always tricky though :)

I think something like DraggableCarousel.itemsInView gives enough information

When reading that, to me it looks like a getter function that returns all the items that are currently in view.

I feel like in a strongly typed language we shouldn't need the variable name to have a type.

Indicating purpose doesn't mean you have to include the "type" in the name.

  • In the case of itemsInView it indicates it's a list (array).
  • In the case of visibleItemCount it's clear that's an amount (number).
  • Having isVisible indicates that it's a state (boolean).

None of them have the "type" in the name (array, number, boolean), but are still super clear.

@mmnathan
Copy link
Collaborator

I'd say visibleItemAmount or visibleItemLimit as it's a value you specify, a count to me indicates a set that exists and has its items 'counted'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

7 participants