Why are getters prefixed with the word "get"?

Posted by Joey on Stack Overflow See other posts from Stack Overflow or by Joey
Published on 2010-04-15T19:50:39Z Indexed on 2010/04/15 19:53 UTC
Read the original article Hit count: 470

Filed under:

Generally speaking, creating a fluid API is something that makes all programmers happy; Both for the creators who write the interface, and the consumers who program against it. Looking beyond conventions, why is it that we prefix all our getters with the word "get". Omitting it usually results in a more fluid, easy to read set of instructions, which ultimately leads to happiness (however small or passive). Consider this very simple example. (pseudo code)

Conventional:

person = new Person("Joey")
person.getName().toLower().print()

Alternative:

person = new Person("Joey")
person.name().toLower().print()

Of course this only applies to languages where getters/setters are the norm, but is not directed at any specific language. Were these conventions developed around technical limitations (disambiguation), or simply through the pursuit of a more explicit, intentional feeling type of interface, or perhaps this is just a case of trickle a down norm. What are your thoughts? And how would simple changes to these conventions impact your happiness / daily attitudes towards your craft (however minimal).

Thanks.

© Stack Overflow or respective owner

Related posts about conventions