像“iCode”这样的类的 Java 类命名或“ICode”或“Icode”?

发布于 2024-10-27 12:45:33 字数 344 浏览 6 评论 0原文

所以,这些单字母应用程序名称似乎变得太流行了,但如果我们必须处理它们,命名 Java 类的传统方法是什么?

注意:我们不是在谈论接口/实现约定名称,而是在代码中使用应用程序名称,例如 iCode、jQuery、eSomething 等。

例如,哪种变体是正确的,或者至少更常见在现实世界中发现的。

public class ICode..

……

public class iCode..

public class Icode..

So, it seems like those one letter application names are becoming way too popular, but if we must deal with them, what would be the conventional way to name a Java class?

Note : we are not talking about interfaces/implementations convention names but uses of application names in code, like iCode, jQuery, eSomething, etc.

For example, which variation would be correct, or atleast is more often found in the real world.

public class ICode..

..

public class iCode..

..

public class Icode..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

明明#如月 2024-11-03 12:45:34

Java 约定规定类名中的每个单词都以大写字母开头,因此

public class ICode

看起来最合适。

话虽如此,这并没有说明它应该做什么......所以也许它们都不是最好的名字

这个类应该做什么? 你应该能够通过阅读类名来判断一个类的作用。

此外,一些约定规定 INTERFACES 以大写 I 开头。因此,命名 CLASS ICode 是不明智的,相反,它似乎类似的东西

public class MyCode implements ICode

不过,如果您的用户都是 mac 粉丝,也许这会是最好的:

public class iCode /* on my iPad */ {

Java convention dictates that each word in a class name starts with a capital, so

public class ICode

seems most appropriate.

That being said, this doesn't say much for what it's supposed to do... so perhaps neither of them is the best name

What is the class supposed to do? You should be able to tell what a class does by reading the class name.

Furthermore, some conventions dictate that INTERFACES start with a capital I. So naming a CLASS ICode would be ill-advised, instead it seems something like

public class MyCode implements ICode

Although, if your users are all mac-fanboys, maybe this would be best:

public class iCode /* on my iPad */ {
ぽ尐不点ル 2024-11-03 12:45:34

按照约定:

public interface Code

对于接口和

public class CodeImpl implements Code
public abstract class AbstractCode implements Code

实现该接口的类。

By convention:

public interface Code

for an interface and

public class CodeImpl implements Code
public abstract class AbstractCode implements Code

for classes that implement that interface.

回忆追雨的时光 2024-11-03 12:45:34

从我的角度来看,第一个 ICode 是最具可读性的选项。它以大写字母 I 开头,因为类应该开始,其余部分采用驼峰式大小写表示法。

From my point of view, the first one, the ICode, is the most readable option. It starts with capital I as classes should start and the rest is in camel case notation.

暗恋未遂 2024-11-03 12:45:34

约定是 ICode,但请注意,这主要用于 C、C++、C# 世界中的接口,而不是 Java 世界中的接口。或者说你的观察从何而来?

The convention would be ICode, but note that this is mostly used for interfaces in the C, C++, C#-world rather than in the Java world. Or where did your observation come from?

我的奇迹 2024-11-03 12:45:34

我总是使用严格的约定,即第一个字母大写,即使真实姓名会使用小写字母。我认为我选择的原因是开头的小字母看起来像接口前缀。

我没有任何参考资料来支持我的选择,这纯粹是个人品味。

所以,我会去

public class ICode..

I always use a strict convention where the first letter is capitalized even though the real name would be with a small letter. The reason for my choice I think is that a small letter at start looks like an interface-prefix.

I have no references to back up my choice, it's pure personal taste.

So, I would go for

public class ICode..
负佳期 2024-11-03 12:45:34

有许多约定来命名类,并且从一种语言到另一种语言的变化。
在java中,只有在使用接口时才添加前缀I,并且以大写字母开头命名类是一个好习惯

there are many conventions to name a class and this change from one language to another.
In java its commond to add the prefix I only when you are using interfaces and its a good practice to name a class begining with an upper case letter

待天淡蓝洁白时 2024-11-03 12:45:34

据我所知,public class ICode 是正确的使用方法。经验法则 - 第一个字母大写,每个单词的第一个字母大写。

Well public class ICode is the correct way to use as far as IKnow. The rule of thumb - first letter upper-case and first letter in every word upper-case.

甜`诱少女 2024-11-03 12:45:34

您可以在此文档中找到有关 Java 命名约定的所有信息,它始终是一个很好的参考。关于类名的内容是:

“类名应该是名词,大小写混合,每个内部单词的第一个字母大写。尽量使类名保持简单和描述性。使用整个单词 - 避免首字母缩略词和缩写词(除非缩写比长形式使用更广泛,例如 URL 或 HTML)。”

和接口名称:

“接口名称应该像类名称一样大写。”

因此在这种情况下,我认为正确的方法是 ICode,但是如果“I”表示我认为更好的使用整个名称,例如让我们说“I”代表“Instant”,那么如果类被命名为 InstantCode,如果“I”没有多大意义,也许最好直接调用类 Code。

You can find all about Java naming conventions in this document, it is always a great reference. What it says about class names is:

"Class names should be nouns, in mixed case with the first letter of each internal word capitalized. Try to keep your class names simple and descriptive. Use whole words-avoid acronyms and abbreviations (unless the abbreviation is much more widely used than the long form, such as URL or HTML)."

and interfaces names:

"Interface names should be capitalized like class names."

So in this case I think the correct way would be ICode, however if the "I" means something I I think is better to use the whole name, like for example let's say "I" is for "Instant", so it is clearer if the class is named InstantCode instead and if the "I" doesn't mean much maybe is better to just call the class Code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文