Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java: Naming convention for plural acronyms

I know there had already been similar discussions on such naming conventions. However, I'm having problem with plural acronyms.

public List<Disc> findAllDvds(DiscHolder holder) {}
public List<Disc> findAllDvd(DiscHolder holder) {}

Assuming that I have decided to use CamelCase for acronyms, which of the two is generally more acceptable?

Edit

I am aware this will invite opinion-based answers, but sometimes when you are in doubt, you just need people to give advises and feedbacks.

To add on, the confusing part here is that findAllDvds can imply a new acronym DVDS, and it can be considered confusing.

like image 748
Jai Avatar asked Mar 16 '18 07:03

Jai


People also ask

Should acronyms be camelCase?

Some guidelines Microsoft has written about camelCase are: 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 .

Which naming convention is used in Java?

Java uses CamelCase as a practice for writing names of methods, variables, classes, packages, and constants.

What are the rules for naming classes in Java?

Class names should be nouns, in mixed case with the first letter of each internal word capitalized. Try to keep your class names simple and descriptive. Use whole words-avoid acronyms and abbreviations (unless the abbreviation is much more widely used than the long form, such as URL or HTML).

How do you use abbreviations in Java?

The . NET Framework guidelines recommend that acronyms three letters or longer use mixed case for PascalCase and camelCase identifiers, except for the first word of a camelCase identifier. Thus for a class name you might have XmlDocument , while a local variable might be named httpRequest .


2 Answers

The first (findAllDvds). The second (findAllDvd) is simply incorrect, "all" implies more than one, but "Dvd" is singular in English.

Re your edit:

the confusing part here is that findAllDvds can imply a new acronym DVDS, and it can be considered confusing

Since the "all" implies multiple, the "s" on "Dvds" reads as a plural, not part of the acronym. If it really were DVDS, the name would be findAllDvdss or similar.

It's said that in computer science, there are three hard problems: Cache invalidation, and naming things. (Off-by-one errors are just common, not hard.)

like image 170
T.J. Crowder Avatar answered Oct 22 '22 07:10

T.J. Crowder


This is a really opinion based question and could be closed.

However, this should be the correct version:

public List<Disc> findAllDvds(DiscHolder holder) {}
like image 42
sarkasronie Avatar answered Oct 22 '22 07:10

sarkasronie