Yes, this usage is acceptable. Identifiers that are found in source code are code, and therefore it's acceptable to format them as if they are code.
The rule is, inline code formatting is only for code—never for emphasis, or proper nouns, or anything else that isn't actually code.
The only one of your examples I'm not wild about is formatting string literals as code. I think the fact that they're surrounded by quotation marks is sufficient demarcation. At least don't use inline code formatting for long strings.
Also note that there is a concern beyond strict semantics: readability. if you have a paragraph where you make reference to a lot of identifiers (function names, keywords, constants, etc.), formatting each of those identifiers using inline code formatting can actively interfere with readability. Thus, you need to use it sparingly.
Consider:
In order to foo
the bar
, you first need to call PrepareBar()
, passing in a const
reference to the bar
. Make sure that bar
is of type IFooableBar
and that you've created it using the MAKE_FOOABLE
constant.
versus:
In order to foo the bar, you first need to call PrepareBar(), passing in a const-reference to the bar. Make sure that bar is of type IFooableBar and that you've created it using the MAKE_FOOABLE constant.
The meaning of these is equally clear, but I'd argue that the latter is significantly easier on the eyes. You don't have the big, ugly, gray blocks breaking up the flow of the text.
If I were writing this as an answer, I'd probably use an intermediate formatting style, where I set only bar
in inline code formatting:
In order to foo the bar
, you first need to call PrepareBar(), passing in a const-reference to the bar
. Make sure that bar
is of type IFooableBar and that you've created it using the MAKE_FOOABLE constant.
The SCREAMING_CASE and function-call parentheses make it sufficiently obvious that these are identifiers found in code; special formatting is not required, and can be omitted in the interest of readability. However, bar
is special, yet it looks too much like normal text, so I'd format it in such a way to make it obvious that it is a specific identifier in the source code.
As I stated at the beginning, this is not a semantic argument, but a practical one. If inline code formatting wasn't so ugly, the readability problem would be diminished. But it is what it is, so this is a choice that authors should be allowed to make. Please don't go through other people's posts and apply inline code formatting to every symbol. It was very likely a deliberate choice to eschew it.
string
instead it will always show up asstring
.