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…

0 points
*

Whitespace width? You mean kerning?

You could make those styles into objects. So you have something like:

TextFormat.strikethrough.withWidth(1.dp)

ParagraphFormat.lineheight.double()

Or

TextDecoration.underline.solid.withWidth(1.dp).and.padding(top: 0.5dp)

permalink
report
reply
0 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
0 points

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

permalink
report
parent
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

  • 71

    Monthly active users

  • 122

    Posts

  • 230

    Comments