Was looking through some code today, and found something that highlights my biggest struggles in programming, it’s compound words and casing. Had identifiers such as…

strikeThroughOffset
whitespaceWidth
lineSpacing
underlineOffset
outlineThickness

I can keep in mind “strike through off set”, but then I struggle to remember, is it strikethrough or strikeThrough? What about Offset or OffSet? Why are offset, underline, and outline, all one word, but strikeThrough isn’t? I think of it as one compound word, many people apparently do, but I guess someone who wrote this code doesn’t.

Or… is this just a me problem? Does anyone else struggle with this sort of thing? Am I missing something or should I “just get good”? My best solution so far is just keep everything always lowercase, personally I find that more readable and memorable, but that’s a lot to ask of literally every other programmer in the world…

19 points
*

I’d take the approach of “flattening” compound words and joining them with the preferred style for the given language. Take your first one, for example:

strike-through off-set -> strikethrough offset

Python (snake_case): strikethrough_offset

Go (camelCase): strikethroughOffset

Rust type (UpperCamelCase): StrikethroughOffset … etc

permalink
report
reply
14 points

I totally agree with what you’re saying. Also, I think UpperCamelCase is called Pascal case.

permalink
report
parent
reply
2 points

It is, the one that starts with lower case is called camel case. As in camelCase has a “hump”

permalink
report
parent
reply
9 points

I have issues with acronyms. For example, SMS: Is it activateSms or activateSMS? What about smsPermission vs sMSPermission?

permalink
report
reply
7 points

My rule of thumbs is if its more than three characters capitalize only the first letter. So, given your example I would write activateSms and smsPermission.

The key is consistency.

permalink
report
parent
reply
9 points

It doesn’t really matter all that much. camelCase is to break up the long variable names and help people find the word breaks. Like imagine linespacing. That could be line spacing or lines pacing, and a little context would help you understand which (yeah this is a bit of a stretch)

As long as it helps clarify, it doesn’t matter. That doesn’t mean it won’t bug me if I think someone has done it wrong, but it doesn’t really matter.

permalink
report
reply
7 points

Yeah, this is one of those constant annoyances that you kinda just live with. It doesn’t matter that much, because compound words were at some point not one word, and there may be separate words that you use today that will join together during your career. Electronic mail became e-mail became email. As long as the casing doesn’t hide the meaning, you’re doing it right. Also be consistent. Don’t recreate such monstrosities as XMLHttpRequest.

permalink
report
reply
4 points

I see this a lot with a significant portion of my colleagues, maybe around 30%.

Personally I don’t feel like it’s a big issue for me, but on the other hand I’ve been working mostly in Python (snake_casing) for the last six years.

That said I do see people having issues with it even in Python, so it’s not like snake casing cures the issue.

Always lowercase gets a downvote from me though.

permalink
report
reply

Programming

!programming@beehaw.org

Create post

All things programming and coding related. Subcommunity of Technology.


This community’s icon was made by Aaron Schneider, under the CC-BY-NC-SA 4.0 license.

Community stats

  • 154

    Monthly active users

  • 228

    Posts

  • 1.4K

    Comments