简体   繁体   中英

Should acronym be capitalized in camelcase if first word of camelCase?

Say I have an acronym/abbreviation like AB.

Is there a convention for how the variable should be named if it is the first word of a camelCase?

In other words should it be * abTest * ABTest * AbTest

What if the acronym is more than 2 letters? Then should it be * httpTest * HttpTest

I know consistency is key, but if starting out, I feel perhaps the first option would be best?

I wish there were a good answer. It seems that acronyms that are more commonly used (and longer) are only capitalized on the first letter but shorter, less common ones are capitalized entirely. For instance, in JavaScript, one common object for HTTP requests is XMLHttpRequest . While XML is a shorter term (and needs to be capitalized to recognize easier, HTTP is a longer and more recognizable term. Also, consider that it would be really irritating to write/read XMLHTTPRequest as it would be pretty unreadable. Just make sure you're consistent and your variable names are readable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM