V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
curiousjude
V2EX  ›  问与答

[命名]大家是如何处理首字母缩写词的? renderHtml() 还是 renderHTML()?

  •  
  •   curiousjude · 2015-03-10 14:51:37 +08:00 · 2624 次点击
    这是一个创建于 3306 天前的主题,其中的信息可能已经有所发展或是发生改变。
    我个人比较倾向于首字母缩写词全部用大写,大家是如何处理的呢?
    7 条回复    2015-03-10 16:45:43 +08:00
    sinsin
        1
    sinsin  
       2015-03-10 14:57:48 +08:00
    很多缩写已经被当成普通词使用了,使用CamelCase风格命名时,包括spring framework的作者们也愿意使用前者。这样大小写分明,分词可编程性也强得多(ry
    顺便还有像首词只有一个字母时,Upper camelcase是写IFace还是iFace的这类蛋裂问题233
    mgcnrx11
        2
    mgcnrx11  
       2015-03-10 15:31:52 +08:00
    选renderHTML,理由是HTML在书写时都是大写的
    Sharuru
        3
    Sharuru  
       2015-03-10 15:44:57 +08:00
    IDE 说啥我信啥 233
    incompatible
        4
    incompatible  
       2015-03-10 15:46:51 +08:00
    @sinsin 说到首词只有一个字母时,我不得不提一下java bean spec里的一个烂坑
    ···
    when we extract a property or event name from the middle of an existing Java name, we
    normally convert the first character to lower case. However to support the occasional use of all
    upper-case names, we check if the first two characters of the name are both upper case and if
    so leave it alone. So for example,
    - “FooBah” becomes “fooBah”
    - “Z” becomes “z”
    - “URL” becomes “URL”
    ···

    如果你不巧有一个bean,它有一个field名字叫做uRL, 然后它的getter叫getURL
    那么在introspect这个bean时,jdk会认为你有一个property叫做URL,而不是uRL
    mimzy
        5
    mimzy  
       2015-03-10 16:08:23 +08:00
    感觉这东西还是看语言和团队规范的。

    在写 C# 的时候,我一般遵循 ReShaper 的建议,缩略词只首字母大写。除非是只有两个字母的缩略词,比如 IO 这种,就全部大写。

    这一点在 Framework Design Guidelines 中有很清晰的描述 https://msdn.microsoft.com/en-us/library/ms229042.aspx
    mimzy
        6
    mimzy  
       2015-03-10 16:09:20 +08:00
    补充:具体位置在 Capitalization Conventions 这一节 https://msdn.microsoft.com/en-us/library/ms229043.aspx
    cst4you
        7
    cst4you  
       2015-03-10 16:45:43 +08:00
    render_html() //逼死你们这些强迫症
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3230 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 11:57 · PVG 19:57 · LAX 04:57 · JFK 07:57
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.