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…
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
I totally agree with what you’re saying. Also, I think UpperCamelCase is called Pascal case.
I have issues with acronyms. For example, SMS: Is it activateSms
or activateSMS
? What about smsPermission
vs sMSPermission
?
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.
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.
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.