-1

I wonder which one is more suitable for a function name:

  1. isUHD
  2. isUhd
  3. (is4k)
Marcus Müller
  • 34,677
  • 4
  • 53
  • 94
John
  • 1,139
  • 3
  • 16
  • 33
  • Primarily opinion. I would use option 1. "Ultra High Definition" is an acronym. – Elliott Frisch Jun 13 '19 at 03:24
  • 2
    It seems to be getting more common to treat acronyms as plain words, leading to option 2. In this case 1 & 2 would both be legible (and commonly used), but in e.g. local variable names that start with the acronym, only making the first character lower-case looks weird (.e.g `uHD` vs `uhd`). – vlumi Jun 13 '19 at 03:28
  • 1
    [Google style guide](https://google.github.io/styleguide/javaguide.html#s5.3-camel-case) says you should use `isUhd`, but in the standard library, the use sometimes `isUHD` (like for example `URL` class). – Krzysztof Atłasik Jun 13 '19 at 04:52

1 Answers1

5

While UHD is written in all uppercase in English, Java naming conventions “win” in Java: They say we should use camel case, isUhd.

It’s not that clear-cut, though. Even old JDK classes tend to keep all uppercase for abbreviations that are part of class or method names, for example Character.isISOControl. Newer additions to JDK rather apply the naming conventions more strictly and use camel case, for example IsoChronology (class in java.time.chrono, since Java 8) or ZoneId.getAvailableZoneIds​() (where ID is written in all uppercase in English). Modern usage is camel case.

The comment by Krzysztof Atłasik supports the same. Google Java Style Guide is gaining recognition as the official Java conventions are not being maintained as the language evolves. Google is clear about camel case and gives this example among others: "supports IPv6 on iOS?" becomes supportsIpv6OnIos.

Link: Google Java Style Guide

Ole V.V.
  • 81,772
  • 15
  • 137
  • 161