12

How should I format class names when I speak of objects in plural? See this excellent answer as an example. The relevant parts are sentences like these two:

Just like Activitys, Fragments may be destroyed by the system when memory resources are low. [...] all of the Activitys attached Fragments will also be destroyed.

Apart from the missing apostrophe behind the second Activity, it looked confusing to my eye. I read "Just like Activity s ..." and wondered where in the code there would be an Activity named s.

Even moreso outside of the blockquote, since the code gray is much closer to the regular background white than the

blockquote code gray is to the blockquote's background gray.

What do you think is the best way to format class names when they are required to be different from the actual classes' name?

  1. Exclude changes from the code tag, accepting the gap and improper spelling:
    Android uses Activitys and Fragments.
  2. Include the changes in the code tag:
    Android uses Activities and Fragments.
  3. Paraphraze:
    Android uses Activity and Fragment objects.
  4. Do away with the code tag if you cannot use the actual class name:
    Android uses activities and fragments.
7
  • 2
    Worth noting, the blockquote background color on regular SO is yellow not grey.
    – ryanyuyu
    Commented Sep 21, 2018 at 13:00
  • @ryanyuyu Now that you said it... indeed it is. But that makes the difference even more obvious there.
    – LWChris
    Commented Sep 21, 2018 at 13:04
  • 4
    "school of fish", "pride of lions", "murder of crows"... we urgently need a cool collective noun for instances.
    – yivi
    Commented Sep 21, 2018 at 13:15
  • 4
    @yivi I was about to add a flock of activities when a herd of fragments crossed my path.
    – LWChris
    Commented Sep 21, 2018 at 13:40
  • 9
    @yivi A heap of objects or a stack of instances. Obviously.
    – deceze Mod
    Commented Sep 21, 2018 at 14:49
  • 2
    I abide to @deceze ’s superior wisdom. There, problem solved.
    – yivi
    Commented Sep 21, 2018 at 14:52
  • 2
    easy: a descent of classes, a dangle of pointers, an overflow of stacks, a race of threads, a throw of exceptions, a scurry of lambdas, a walk of heaps, a mutation of constants, a run of tasks. Commented Sep 23, 2018 at 16:40

2 Answers 2

16

This may be a bad example, since it should probably be phrased as a pure English sentence without reference to any specific code. Here's maybe a better example, in which I'm trying to refer to specific classes in an explanatory sentence:

Android has a notion of activities and fragments. Activities are implemented by the Activity class. You can create a list of such Activity objects*. Each Activity** will be processed in turn.

* The choice here is between "such Activity objects" and "such Activitys". The latter one is rather awkward, so err on the side of saying "Activity objects".

** This is used as shorthand for "Activity object". Since that phrasing was already used in the previous sentence, it's fine to shorten it here.

So, whenever you refer to a specific class, use code markup, and use the literal name of the class without grammatical alternations. If possible, for purely stylistic reasons, I'll go with a grammatical alteration after the code; for example when talking about Tasks. It uses the literal class name, but also uses proper grammar within the sentence. If that is awkward, use phrasing like "Xyz object" instead. If you're not talking about a specific class, don't use code markup.

1
  • I like this answer even more than the answer given on the question mine has been made a duplicate of by now.
    – LWChris
    Commented Oct 7, 2018 at 2:04
9

They're talking about the concepts "activities" and "fragments". I wouldn't use code formatting for that.

The same goes for example for a "stream", which is a concept in many frameworks such as Java and .NET. You don't highlight each instance of the word Stream with inline code when explaining something about that topic.

Yes, these concepts have classes named after them, but not each time it occurs it is about the class name. So simply remove the code formatting when it's not about code.

And yes, I'm allergic to overuse of inline code.

See also: When should code formatting be used for non-code text?

4
  • 1
    This answer doesn't address what to do if you are referring to actual class names.
    – John Y
    Commented Sep 21, 2018 at 21:27
  • My point is that you should write your post in such a way that you won't need inline code highlighting.
    – CodeCaster
    Commented Sep 23, 2018 at 17:30
  • 3
    Personally, I like inline code for class names. It makes it easier for me to follow the posting, because the eye gets hooked on the class names and finds references to it in the text, like "Using a PrinterWriter makes using a BufferedWriter superfluous." But that's just my personal favor.
    – LWChris
    Commented Sep 23, 2018 at 19:58
  • @LWChris I'm not entirely against using inline code highlighting, but it's easily overused.
    – CodeCaster
    Commented Sep 24, 2018 at 4:56

Not the answer you're looking for? Browse other questions tagged .