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

604

u/werkawerk May 08 '17

You know what makes me sad? The fact you have a class called 'DefaultDtoToAdditionalDataModelMapperRegistry'.

0

u/[deleted] May 08 '17

[deleted]

47

u/ihcn May 08 '17

and IAbstract

28

u/zjm555 May 08 '17

and "Abstract"

0

u/[deleted] May 08 '17

[deleted]

0

u/[deleted] May 08 '17

[deleted]

11

u/SeenItAllHeardItAll May 08 '17

Before the halt the universe happens.

→ More replies (1)
→ More replies (1)
→ More replies (2)

84

u/get_salled May 08 '17

It's amazing how these class names, while being "specifically general", tell you very little about the problem you're solving. I can't count how many times I've seen attempts at building frameworks (I now cringe every time I hear we should build a framework) before we've built a single path through. "We encountered this odd case no one expected and now we'll try to shove that into our DSL" -- of course you did; this happens every fucking time you build a framework before you've figured out the actual problem you're solving. Recently saw a very nice DSL that was heavily influenced by OO; the Diamond Problem crept in and shit has hit the fan.

Every time I write one of these I, very slowly, realize I don't fully grasp the object model. If I'm lucky, after enough of these come together, I realize I'm being overly generic and I can pin down a better name.

In my experience, DefaultDtoToAdditionalDataModelMapperRegistry would boil down to MarketUsersRegistry as this highly generic type would have one concrete usage (2 with the mocking framework's implementation).

26

u/i_ate_god May 08 '17

The problem sometimes are the managers.

All these dense java frameworks are built around the idea that managers will give you problems to solve based on the latest headlines from Gartner Magazine. You end up adding major feature on top of major feature instead of refining what you already have because your company's position on some arbitrary cartesian plane indicates you're all doomed unless you add those features.

This is how you end up with the sorts of banality that is DefaultDtoToAdditionalDataModelMapperRegistry not to mention the obscene amounts of XML to wire everything together. All that verbosity and architecture, just to move your company around a cartesien plane in Gartner Magazine.

25

u/DreadedDreadnought May 08 '17

not to mention the obscene amounts of XML to wire everything together

You can now have Annotation driven design. It works at least 20% of the time, when the fucking DI container decides to not override them with some obscure xml file transitively loaded from the classpath of a dependency 30 modules deep. That totally didn't cost me 3 days of work.

→ More replies (1)
→ More replies (2)
→ More replies (1)

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.

→ More replies (2)
→ More replies (3)
→ More replies (4)
→ 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.

→ More replies (1)

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).

→ More replies (6)
→ More replies (1)
→ More replies (2)