Search code examples
javanaming-conventionscamelcasing

Camel case name for class with "IPv4"


I have class named Ipv4Address. What would be idiomatic camel case name for it? By idiomatic I mean meeting Google Java Style and meeting Checkstyle AbbreviationAsWordInName check.

This question does not answer my question - I'm asking here specifically about what to do with letter "v" that is already lowercase in acronym.

Ipv may suggest that there's word "ipv" or acronym "IPV". But actual acronym is "IPv", wich is made of two words: "IP" and "version"


Solution

  • Well, according to the first site:

    1. Convert the phrase to plain ASCII and remove any apostrophes. For example, "Müller's algorithm" might become "Muellers algorithm"

    2. Divide this result into words, splitting on spaces and any remaining punctuation (typically hyphens).

      Recommended: if any word already has a conventional camel-case appearance in common usage, split this into its constituent parts (e.g., "AdWords" becomes "ad words"). Note that a word such as "iOS" is not really in camel case per se; it defies any convention, so this recommendation does not apply.

    3. Now lowercase everything (including acronyms), then uppercase only the first character of:

      ... each word, to yield upper camel case, or

      ... each word except the first, to yield lower camel case

    4. Finally, join all the words into a single identifier.

    So:

    1. IPv4 Address

    2. IPv 4 Address

    3. ipv 4 address

      Ipv 4 Address

    4. Ipv4Address

    An example they give that includes IPv:

    "supports IPv6 on iOS?" -> supportsIpv6OnIos

    So, it appears that Google does not care that the "v" stands for "version", and as such they treat it as part of a single word, "IPv".

    If you are dead-set on making it clear that "v" is "version," you could probably get away with IpVersion4Address, though I like the look of Ipv4Address better.