java java中列表变量的好名字

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10996681/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 03:20:18  来源:igfitidea点击:

Good name for a list variable in java

javanaming-conventions

提问by Ace McCloud

What of the following is used popularly or is the standard :

以下哪些是普遍使用的或者是标准的:

private List<String> names ;

OR

或者

private List<String> listOfNames ;

OR

或者

private List<String> namesList ;

采纳答案by Jeff Watkins

Once upon a time we had Hungarian notation, because IDEs didn't provide intellisense and programmers were too dumb to realise that having a 30,000 line long block of code was unreadable*. Nowadays IDEs are friendly, programmers have started using small, neat classes, we have JavaDoc and things in genral are easier to read.

曾几何时,我们有匈牙利符号,因为 IDE 不提供智能感知,而且程序员太笨了,无法意识到拥有 30,000 行长的代码块是不可读的*。现在 IDE 很友好,程序员开始使用小而整洁的类,我们有 JavaDoc 并且一般的东西更容易阅读。

So, just name your variable for its usage. i.e. names. I'm no fan of pre/post-fixing variables as it often makes them harder to understand.

因此,只需为其使用命名您的变量。即名称。我不喜欢固定前/固定后的变量,因为它通常会使它们更难理解。

(*) i.e. Me, there's probably some deeply shameful code out there with my name on it.

(*) 即我,可能有一些非常可耻的代码,上面写着我的名字。

回答by PeterMmm

Depends on the use case.

取决于用例。

names 

If this is the only "names" variable

如果这是唯一的“名称”变量

namesList

If therr are other names collestions (e.g. namesSet) in your code.

如果您的代码中有其他名称集合(例如名称集)。

private List<String> listOfNames

Is wrong; if you will be so specific you should write listOfStrings or

是错的; 如果您如此具体,您应该编写 listOfStrings 或

private List<Name> listOfNames

redefine your type (whatever Name is).

重新定义您的类型(无论名称是什么)。

回答by Anuj Patel

The conventional name will be namesList.

常规名称将是namesList.

PS : If you use auto complete in Eclipse you'll see that.!

PS:如果您在 Eclipse 中使用自动完成功能,您会看到。!

回答by Fahim Parkar

Regarding variable name, you can use anything.

关于变量名,你可以使用任何东西。

My team saysafter reading variable name, one should understand what that variable will hold data BUT variable name should be as per Java naming convention.

我的团队说在阅读变量名后,人们应该了解该变量将保存什么数据,但变量名应该按照 Java 命名约定

In your case I would go with listOfNames, because it will say the variable is of type list and it has names.

在你的情况下,我会选择listOfNames,因为它会说变量是列表类型并且它有名称。

Also read Java naming convention.

另请阅读Java 命名约定

回答by Eight

whatever is suitable for you and your team go with that.

任何适合您和您的团队的都可以。

IDEs are very smart they will take for everything else like what a given name stands for, type, permissions etc.

IDE 非常聪明,它们可以处理其他所有内容,例如给定的名称代表的含义、类型、权限等。