6 ms·
It would make me sad to type getSqrt(), getMin(), getMax(), getStrLen(), getSizeOf(), get… Putting a verb in the function name is not a bad idea, but if you fi
by function_seven 10y ago
It would make me sad to type getSqrt(), getMin(), getMax(), getStrLen(), getSizeOf(), get…
Putting a verb in the function name is not a bad idea, but if you find yourself identifying the verb as “get”, then it’s a useless three extra letters.
- TillE 10y agoI think for most people, "getFoo" generally implies direct access to a data member, not a calculation. This is a useful hint, and an argument for not using it in other contexts.
- function_seven 10y agoGood point. For me personally, I find myself using “get” whenever a function or method will query a database or some other external source to deliver the result. For example, getNormalizedDeliveryAddress(), or getRelatedComments().
- catlover99 10y agoPersonally, for whatever reason in my mind, I think "get" as referring to something local which is why I choose between three different verbs, "grab", "fetch", or "query" (typically grab), as a descriptive prefix for functions that retrieve data from external sources.
- pvg 10y agoI doubt that's most people unless most people are confused. The whole point of having getters and setters is to abstract away the implementation details of where the value comes from. Direct access to a data member is easily achieved via direct access to the data member, it doesn't require a method.
- Stratoscope 10y agoBack in the early days of Pascal programming for both DOS and Mac, it was common to put a 'the' prefix on just about every variable. I guess it was supposed to be more "English-like". You'd have variables like this: theWindow theUser theFile theLineCount I hated it! I never did find out why people wanted to put in such a useless noise word in every single variable name, but I decided to never do it again. Make every word count.
- jejones3141 10y agoThat would almost tempt me in Algol 68, where, like FORTRAN, space isn't significant, and where members of structures are referred to as foo OF bar rather than bar.foo but as you say, in code "the" is a noise word, so I'd resist. :)
- ams6110 10y ago"my" was another often-seen useless prefix of that era
- flukus 10y agoIt still has it's uses as a class name prefix. MyFoo extends GenericFoo.
- louthy 10y agoIndeed, it is horrific. As is Hungarian notation. Anything where the type or locality ('m_foo', 'g_var') has infiltrated the name of the variable says to me that the variable is named badly.