在Java变量和方法名称中使用下划线 [英] Using underscores in Java variables and method names

查看:683
本文介绍了在Java变量和方法名称中使用下划线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即使现在我经常在Java变量和方法中看到下划线,例如成员变量(如m_count或_count)。据我所知,在这些情况下使用下划线被Sun称为坏样式。

Even nowadays I often see underscores in Java variables and methods, an example are member variables (like "m_count" or "_count"). As far as I remember, to use underscores in these cases is called bad style by Sun.

他们应该使用的唯一地方是常量(如公共最终版) static int IS_OKAY = 1;),因为常量应该都是大写而不是驼峰的情况。这里,下划线应该使代码更具可读性。

The only place they should be used is in constants (like in "public final static int IS_OKAY = 1;"), because constants should be all upper case and not camel case. Here, the underscore should make the code more readable.

你认为在Java中使用下划线是不好的风格吗?如果是(或没有),为什么?

Do you think using underscores in Java is bad style? If so (or not), why?

推荐答案

如果您现在没有使用它的代码,我建议继续这样做。如果你的代码库使用它,那就继续吧。

If you have no code using it now, I'd suggest continuing that. If your codebase uses it, continue that.

关于编码风格最重要的是一致性。如果您没有任何要求,那么语言供应商的推荐可能是一个很好的起点。

The biggest thing about coding style is consistency. If you have nothing to be consistent with, then the language vendor's recommendations are likely a good place to start.

这篇关于在Java变量和方法名称中使用下划线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆