How do you PEP 8-name a class whose name is an acronym?

后端 未结 8 772
抹茶落季
抹茶落季 2020-12-05 04:08

I try to adhere to the style guide for Python code (also known as PEP 8). Accordingly, the preferred way to name a class is using CamelCase:

Almost wi

相关标签:
8条回答
  • 2020-12-05 04:39

    I also work in an acronym-heavy environment. I tend to prefer form #3 because even though it lower-cases parts of an acronym, it clearly delineates parts of the name. It also avoids confusion when part of the name is an acronym and part is a word.

    0 讨论(0)
  • 2020-12-05 04:39

    I tend to use #3. It looks weird at first but you (sort of) get used to it. I went this way after suffering for too long under strings of acronyms jammed together, e.g. NPCAIXMLParser was one. I decided that NpcAiXmlParser was much easier to read and have been doing that ever since, even though seeing these things lowercased still looks weird sometimes.

    In terms of "the standards," I tend to think of these entities as "words" and as such capitalize them as I would capitalize any other word. E.g. if I had a local variable representing some NPC (non-player character), I would name it 'npc' and not 'nPC'.

    In regards to PEP-8, I disagree with this statement; I find the last spelling of the word to be preferable.

    Note: When using abbreviations in CapWords, capitalize all the letters of the abbreviation. Thus HTTPServerError is better than HttpServerError.

    0 讨论(0)
提交回复
热议问题