0

What is the best practice of naming convention of enum

public enum SystemTypeEnum {

    RRD, FFR, DDE
}

Currently the name is SystemTypeEnum. Is this ok or we should have name as SystemType

Would like to know best practice.

VJS
  • 2,549
  • 6
  • 31
  • 58
  • 2
    do you write Class after every class ? What additional info will Enum give users of this code ? – Erran Morad May 01 '20 at 05:45
  • 1
    There are different standards and opinions, but to my knowledge the most commonly used style is to not have `Enum`, `Interface`, `Abstract` or `E`, `I`, `A` as part of the name. – Zabuzard May 01 '20 at 05:45
  • This may help https://stackoverflow.com/questions/3069743/coding-conventions-naming-enums – Nagaraj Kandoor May 01 '20 at 05:46
  • Good question but opinion-based, so voting to close. – Zabuzard May 01 '20 at 05:46
  • 1
    @NagarajKandoor It is actually even a duplicate, it explicitly explains whether to suffix with `Enum` or not. – Zabuzard May 01 '20 at 05:47
  • 1
    Possibly because it lacks research effort. There are some SO threads talking about this naming convention and also outside of SO there are lots of discussions about naming practices, whether to pre- or suffix abstract, interfaces and enums. Especially `EFoo`, `AFoo`, `IFoo` is still quite commonly used. – Zabuzard May 01 '20 at 05:49
  • @Zabuzard : Agree. Question comes as there are various opinions in so many thread over internet. I researched but some people say that it is ok to have enum in name to get the glance and code friendly for people to understand after seeing in bunch of classes that this contains constant. This is the reason question came in my thought. – VJS May 01 '20 at 05:55
  • 1
    After Googling `"java best practice to name enums"` I came across this: https://stackoverflow.com/questions/3069743/coding-conventions-naming-enums – nabster May 01 '20 at 05:58
  • Irrespective of the enum name, I would suggest your values should have better names. Perhaps they are well-known abbreviations in the problem domain; otherwise call them something more descriptive: `REALLY_REALLY_DESCRIPTIVE`, `FRANKLY_FAMOUS_RATATOUILLE` etc. – Andy Turner May 01 '20 at 07:10

2 Answers2

1

Disclaimer: I realize that my Answer can be considered opinionated, so my answer reflects my own experience.

I think it's better to rename to SystemType It's clear that its enum, all modern IDE show that. Following this logic, if you have, for example, interface

interface Calculator {
   int plus(int a, int b);
   int minus(int a, int b);
}

It should be renamed to CalculatorInterface - sounds weird, right?

Another example:

class Person {
   String name;
   int age;
}

Do you think its a good idea to rename it to PersonClass only because of its a class?

Bottom line, as I said, you can rely on IDE here - it will provide a visual hint for you for what it is.

Mark Bramnik
  • 31,144
  • 4
  • 41
  • 69
0

Outcome

This is a highly opinion based topic, so I will try to keep this unbiased.

There are different standards and opinions and there is no very clear outcome to the discussion.

To my knowledge the most commonly used style is to not have a suffix or prefix.


Arguments

The discussion typically also includes pre- or suffixes for abstract classes and interfaces, not only enums. Also frequently seen are prefixes like E, A, I instead of suffix.

Some argue it does not add any useful additional information to the name and only clutters it. Some say it should not matter whether it is, lets say, and interface or a class. Some say it is the job of the IDE and not the name to indicate the type, for example with colors and icons. But there are also opinions in favor of that naming standard.


Style guidelines

A widely adopted style guideline is Googles style, quoting:

In Google Style, special prefixes or suffixes are not used. For example, these names are not Google Style: name_, mName, s_name and kName.

Another style that is commonly referred to is the style used in the JDK by the Java developers themselves, they also do not use a prefix or suffix.

But again, those are just some styles, there are also others.

Zabuzard
  • 20,717
  • 7
  • 45
  • 67