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…
Each language has their own conventions in the style guides for how they prefer variables and functions to be named.
For example,
snake_case
camelCase
(like your examples)UpperCamelCase
that’s like camel case, but the first letter is also capitalizedAnd then some organizations like to override those and institute their own conventions. I generally think the latter is a bad idea, since it breaks with accepted industry standards for a given language. Even for a personal project you know that no one else will touch, I think it’s good to follow the langues guides.
I generally wouldn’t make a compound word all lowercase.
strikethroughoffset
is much more difficult to read, IMO. If you’re going that route, then you should at least snake case it:strike_through_offset
. But again, a lot of this is going to depend on your situation.It’s not really a “get good” issue so much as it’s just an annoying part of the industry one has to navigate.