this post was submitted on 07 Aug 2023
29 points (100.0% liked)

Programming

13373 readers
2 users here now

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.

founded 1 year ago
MODERATORS
 

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

you are viewing a single comment's thread
view the rest of the comments
[–] EdriMareyemi@beehaw.org 2 points 1 year ago* (last edited 1 year ago)

Hmm per-syllable camel case, is that a thing? Sounds interesting! I might like that one lol

But yeah, am I able to use another casing style... the thing is, kinda yes? But kinda no. I think I basically can manage any style (Though not a fan of the underscore_style but hey, can do), it's really just compound words that trip me up. Like, consider white space width and strike through off set. I can keep every word in mind, but apparently whitespace is one word, and strike through might be two words, depending on who you ask. So to me, I think this is correct: whitespace_width, strikethrough_offset

But someone else might think it should be: white_space_width, strike_through_off_set

And yet a third person might do: whitespace_width, strike_through_offset

I just can't memorize which words are compound words, and which ones aren't, and I don't know how to tell without just knowing. I know what words go into identifier names, but when some of those words might be compound words, I get all messed up, which is a bit of an issue when working with other people's code.

Maybe in a way, my problem is that I memorize the names of things in a sort of "spoken" state; I "say" strike through off set in my mind, but capitalization doesn't affect speech, so if its 'strikethroughoffset' or 'StrikeThroughOffSet", my brain is gonna memorize it as just the 4 words, "strike through off set".

So in the end, the easiest thing I've found when working on my own projects is just keep everything lowercase, no underscores. The tiniest exception I might make is a singleton, but generally I think "If I have a collection of data and functions, and there will only be 1 instance of it, there's a name for that: A namespace" so I don't often employ those. (Maybe you can tell I have C/C++ in mind especially lol)