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…

  • davehtaylor
    link
    fedilink
    English
    111 months ago

    Each language has their own conventions in the style guides for how they prefer variables and functions to be named.

    For example,

    • Python uses snake_case
    • C and C++ also generally use snake case, but have specific conventions for particular types of variables
    • Java, JavaScript, and C# use camelCase (like your examples)
    • Pascal, Dart, and a few others use UpperCamelCase that’s like camel case, but the first letter is also capitalized

    And 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.