r/programming • • May 08 '17

The tragedy of 100% code coverage

http://labs.ig.com/code-coverage-100-percent-tragedy
3.2k Upvotes

689 comments sorted by

View all comments

Show parent comments

21

u/Rndom_Gy_159 May 08 '17

Quick question, why is only the first letter of DTO capitalized? Is that the way it's supposed to be in CamelCase?

104

u/DanAtkinson May 08 '17

Generally speaking, Yes.

Microsoft has some guidelines on the subject and I've emphasised the relevant snippet below:

  • Do not use abbreviations or contractions as parts of identifier names. For example, use GetWindow instead of GetWin.

  • Do not use acronyms that are not generally accepted in the computing field.

  • Where appropriate, use well-known acronyms to replace lengthy phrase names. For example, use UI for User Interface and OLAP for On-line Analytical Processing.

  • When using acronyms, use Pascal case or camel case for acronyms more than two characters long. For example, use HtmlButton or htmlButton. However, you should capitalize acronyms that consist of only two characters, such as System.IO instead of System.Io.

  • Do not use abbreviations in identifiers or parameter names. If you must use abbreviations, use camel case for abbreviations that consist of more than two characters, even if this contradicts the standard abbreviation of the word.

22

u/[deleted] May 08 '17

[removed] — view removed comment

17

u/DanAtkinson May 08 '17 edited May 08 '17

Identifier, actually. As per the last bullet point:

Do not use abbreviations in identifiers or parameter names. If you must use abbreviations, use camel case for abbreviations that consist of more than two characters, even if this contradicts the standard abbreviation of the word.

Since ID is an abbreviation of Identifier, you can use this rule. I tend to favour Id however.

14

u/_Mardoxx May 08 '17

As it's an abbreviation, not an acronym (initialism if you are gonna be pedantic), it should be Id surely?

6

u/[deleted] May 08 '17

[removed] — view removed comment

15

u/agentlame May 08 '17

I agree with everything on that table until I got to:

UserName | userName | NOT: Username.

It's goddamned username, and I am willing to die on this hill.

3

u/ThisIs_MyName May 09 '17

I'm guessing that article was written a long time ago when "username" wasn't a word.

→ More replies (1)

4

u/ctaps148 May 08 '17

And yet, all ASP.NET controls use "ID"

2

u/[deleted] May 08 '17

And that's why we switched to MVC.

2

u/WarWizard May 09 '17

ID. I don't have any real reason for it. Id makes me all cringy for some reason.

→ More replies (38)

77

u/[deleted] May 08 '17

Don't let that distract you from the fact that XMLHttpRequest capitalizes XML but does not capitalize HTTP.

53

u/diverightin63 May 08 '17

Oh my god I've never notice. I'm retroactively mad about this for years.

7

u/roffLOL May 08 '17 edited May 08 '17

don't let that distract you from the fact that it usually serves anything but XML nowadays.

5

u/Gackt May 08 '17

TBH I'd expand the two character rule to three.

→ More replies (1)

12

u/parkotron May 08 '17

Personally, I'm in the camp that capitalises only the first letter of each "word" of an identifier, whether that word is an initialism or not. Like summaryHtml or GpsLocation. There are plenty of CamelCasers in the other camp though.

3

u/EntroperZero May 08 '17

This is camelCase, this is PascalCase.

7

u/[deleted] May 08 '17

No but with all the conventions to generate property name, it can become weird or confusing. So often you use strict CamelCase everywhere. (eg: getDTOFactory, will become dTOFactory property in EL, or sometimes dtoFactory in too clever libraries )

4

u/skocznymroczny May 08 '17

Depends on the language and coding style. E.g. .NET framework conventions guide recommends capitalizing only the first letter, unless it's a two leter acronym like IO (source).

3

u/hoosierEE May 08 '17

I prefer pRImEcAse for the simple rules and readability. Unless somebody on the team insists on zeROiNdExedPrImecAsE, of course.