`name ()` vs. `getName ()` naming convention?

I saw some projects (like jsoup) use this new getter / setter naming convention:

String name() void name(String value) 

instead of the old getter / setter build:

 String getName() void setName(String value) 

What are the positive and negative aspects of each naming convention? When and why do you think you need to give preference to another?

+8
java oop naming-conventions
source share
5 answers

The first example does not meet the specification

+9
source share

Nothing but the readability and style of the API.

Some APIs accept this style, and some do not, for example Spring injections and JSF cannot recognize this syntax (they explicitly need get / set for the properties).

+3
source share

I like to just use name() when the object I'm dealing with is immutable, i.e. I would never change the value of the name field. When I deal with a volatile object, I would use the second convention that you talked about, simply because I think it is superior in readability.

+3
source share

I always prefer to use verbs for the name of the methods, so this is true for getters and setters.

I use nouns only for variables.

Follow the classic JavaBean standard to make me feel more comfortable. :)

+2
source share

I prefer to use a shorter style if the library is at a low level and I want it to clear this component rather than the JavaBean.

If in doubt, I would use the JavaBean style.

+1
source share

All Articles