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.
In JavaScript, accessor properties are methods that get or set the value of an object. For that, we use these two keywords: get - to define a getter method to get the property value. set - to define a setter method to set the property value.
Some data members may be entirely internal to the object, and should have neither getters nor setters. Some data members should be read-only, so they may need getters but not setters. Some data members may need to be kept consistent with each other.
get() method in JavaScript is used for returning a specific element among all the elements which are present in a map. The Map. get() method takes the key of the element to be returned as an argument and returns the element which is associated with the specified key passed as an argument.
The getter method returns the value of the attribute. The setter method takes a parameter and assigns it to the attribute. Once the getter and setter have been defined, we use it in our main: public static void main(String[] args) { Vehicle v1 = new Vehicle(); v1. setColor("Red"); System.
Because, in languages without Properties, name()
is a function. Without some more information though, it's not necessarily specific about what it's doing (or what it's going to return).
Functions/Methods are also supposed to be Verbs because they are performing some action. name()
obviously doesn't fit the bill because it tells you nothing about what action it is performing.
getName()
lets you know without a doubt that the method is going to return a name.
In languages with Properties, the fact that something is a Property expresses the same meaning as having get or set attached to it. It merely makes things look a little neater.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With