Class capitalisation when using an Acronym

Hello.

In https://kotlinlang.org/docs/reference/coding-conventions.html#choosing-good-names we have this:

When using an acronym as part of a declaration name, capitalize it if it consists of two letters (IOStream); capitalize only the first letter if it is longer (XmlFormatter, HttpInputStream).

Does this apply only to prefixes or also to suffixes?

I’m asking this because the issue came up in the team that I work if we should use ItemDTO or ItemDto

I would probably apply this rule to suffixes as well. That said DTO is a 3 letter acronym and should therefor be spelled ItemDto in any case.
That said there are some acronyms that look strange if spelled with only 1 letter in upper case eg. country codes Ger, Usa, Aus which I would probably capitalize completely.
Also this is a minor guideline. It is there to make code more consistent and make it easier to switch between projects, companies etc, but I’d argue that the capitalization of 2-3 letter acronyms is far less important than let’s say the guideline that only class names should start with capital letters while function and property names start with lower case.
As long as you keep it consistent I don’t think there is much to worry. This guideline is a good start but if you and/or your team decides that you prefer ItemDTO this is a totally valid decision, just don’t call you next class Item2Dto :wink:

1 Like