More appropriate way to name a list

Asked

Viewed 105 times

1

Hello I would like to ask a question about attribute names. What would be the most appropriate way to name a list? Let’s assume that I have an attribute which is a list of Ufs. What would be the right way to name it? ufs? listaUfs?

In the book Clean Code, author Robert Cecil Martin says:

" The name of a variable, Function, or class, should Answer all the big questions. It should Tell you Why it exists, what it does, and how it is used. If a name requires a comment, then the name does not Reveal its Intent. "

Bearing this in mind I ask: putting the word "list" in this attribute is relevant information or is redundancy?

I would also like to know if it is correct to use plural words to name an attribute or not?

2 answers

6

First, what you call an attribute is actually called a field.

In general listaUfs is a form of hungarian notation and this is not usually considered appropriate. Probably only ufs is the best thing. For lists and other collections the plural is usually more interesting, but for fields other than collections is not suitable. I just don’t know if it should be a list with this, maybe another way could be better, but it depends on the context. The important thing is that lista is redundant in most scenarios, but may have some that might make sense.

A case that can be useful is when the variable name should state the implementation detail and be a list, but this is very rare and almost always an error.

In some cases it is better to look for another more relevant name, but it is not always easy to find, this same I do not know a better one. Some have collectives. But it is necessary to be careful, I have seen people suggesting that a list of players is actually a team, but there are also those who disagree after all a team is not only a list of players, a team is probably even an object that has a list of players, among other things.

-4

You can name it in the way that best suits your project. The only rule you should keep in mind is to always follow the camelcase pattern. Always starting with lowercase letter in the first word and uppercase in the second. Example:

listUfs or listUfs or listDeUfs....

at last...

  • minhaArrayDeUfs is suitable for you?

  • yes if only you are the one who will touch code kk

  • 2

    I think it is not good to write a code that only you understand. You may abandon this code and after a while need to maintain. Then only God will know how to maintain this code, and I’m sure he won’t want to do that. https://answall.com/q/13890/3774

  • Well this is a point of view...... There are people who find everything in the mess and get lost in the storage and vice versa. How to explain this? In my case, I’ve been learning everything I know myself. I don’t have college in IT but I consider myself a good Android programmer. I have my own housekeeping methods and never get lost in them...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.