curiousjude
V2EX  ›  问与答

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

  •  
  •   curiousjude · Mar 10, 2015 · 3314 views
    This topic created in 4130 days ago, the information mentioned may be changed or developed.
    我个人比较倾向于首字母缩写词全部用大写,大家是如何处理的呢?
    7 replies    2015-03-10 16:45:43 +08:00
    sinsin
        1
    sinsin  
       Mar 10, 2015
    很多缩写已经被当成普通词使用了,使用CamelCase风格命名时,包括spring framework的作者们也愿意使用前者。这样大小写分明,分词可编程性也强得多(ry
    顺便还有像首词只有一个字母时,Upper camelcase是写IFace还是iFace的这类蛋裂问题233
    mgcnrx11
        2
    mgcnrx11  
       Mar 10, 2015
    选renderHTML,理由是HTML在书写时都是大写的
    Sharuru
        3
    Sharuru  
       Mar 10, 2015
    IDE 说啥我信啥 233
    incompatible
        4
    incompatible  
       Mar 10, 2015
    @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  
       Mar 10, 2015
    感觉这东西还是看语言和团队规范的。

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

    这一点在 Framework Design Guidelines 中有很清晰的描述 https://msdn.microsoft.com/en-us/library/ms229042.aspx
    mimzy
        6
    mimzy  
       Mar 10, 2015
    补充:具体位置在 Capitalization Conventions 这一节 https://msdn.microsoft.com/en-us/library/ms229043.aspx
    cst4you
        7
    cst4you  
       Mar 10, 2015
    render_html() //逼死你们这些强迫症
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3424 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 51ms · UTC 11:54 · PVG 19:54 · LAX 04:54 · JFK 07:54
    ♥ Do have faith in what you're doing.