shinve — 2014-07-01T23:21:15-04:00 — #1
I use camelCase for method names. But occasionally I have method names with acronyms or things that are otherwise fully capitalized in common usage. Examples: ID, IP.
I know it is subjective and subject to conventions, but some conventions have more justification than others... especially when you consider naming across various scopes and platforms, like class names, variable names, and database column names.
So any thoughts on whether a class method's name should be getProductID or getProductId?
mittineague — 2014-07-01T23:41:45-04:00 — #2
:lol: I just had this dilemma the other day.
I too use camelCase and was torn between
getJSON or getJson
I guess the main thing is to be consistent with your own code, solo or collaborative.
I've seen it both ways in other's code, so either there's no standard or some have it wrong.
The real problem happens when the acronym isn't last. eg.
getJSONResults looks worse to me than getJsonResults
jeff_mott — 2014-07-02T13:10:59-04:00 — #3
It doesn't appear that there is any common convention for camel casing acronyms. I glanced over at the Java API's, and it isn't consistent even there. Sometimes the acronyms are uppercase, sometimes camel case.
Very few style guides seem to cover this sort of thing. The .NET Framework style guide is one of the few that mentions it. Their guideline for most cases is to strictly follow camelCase (e.g., HtmlTag), but they make an exception for two letter acronyms (e.g., IOStream).
Wikipedia seems to have another suggestion, that you could "follow any instance of acronymic capitalization with a re-initialization of lower case camel" (e.g., TCPIPsocketID).
shinve — 2014-07-03T15:15:10-04:00 — #4
Glad to know that I am not the only one who ran into this style issue. Thanks for the replies.
I am leaning toward capitalizing acronyms and then returning to camelCase, so getProductID or getProductIDFromProductList. An emphasis will be to never have an acronym start a method name, such as IDDelete (bad example, I know, but just an example). Although it occurred to me that this leads to yet another style problem of whether the pluralization of an acronym should also be capitalized. (example: getProductIDS vs getProductIDs.) :lol:
And to push even more considerations onto the pile, there are some acronyms that you often see without capitalization that I have come to expect to see in lower case, things like like html, php, js. I don't know if I like the look of HTML being capitalized, but at least it would be consistent, so I am leaning in that direction.
system — 2014-10-08T02:16:28-04:00 — #5
This topic is now closed. New replies are no longer allowed.