Getter naming conventions

Bertil Muth - Dec 15 '18 - - Dev Community

In Java and similar languages that don't have a built-in property concept, it is common to make fields private and accessible to the object's outside only through getter methods.
The Java Beans naming convention suggests to use the name getX() for the getter method of a field x (most of the time) , like so:

public class User{
    private Name name;

    public Name getName(){
        return name;
    }
    ...
}
Enter fullscreen mode Exit fullscreen mode

I didn't question it when I started programming. Then I heard of several people, like Martin Fowler, who didn't care about that convention. They write name() for the example getter instead.

Looks a lot better, so I started adopting it. Then I ran into problems with libraries that expect the Beans convention.
Another benefit of classes adhering to the Beans convention: in an IDE, you can easily find out all the properties of a library's class if you just type in the first three letters: get.

So, if you use getter methods, which naming convention do you use?

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .