Punctuation after block of code [closed]

What is an unambiguous usage of punctuation after a block of code?

For example, suppose I have the following:

something = "The quick brown fox jumps over the lazy dog :)"
that = find(isequal('b'), something)
looks = find("brown", something)
like = replace(something, "brown" => "red")
code = ":"")"^2

Now this is a new sentence, but there could not have been a full stop inside the code, as it would modify it. One could argue that if the succeeding line begins with a capital letter, one should imagine a full stop after the code, while if it doesn't there shouldn't be one.

The situation is trickier with commas though. Observe the following example:

something = "The quick brown fox jumps over the lazy dog :)"
that = find(isequal('b'), something)
looks = find("brown", something)
like = replace(something, "brown" => "red")
code = ":"")"^2

where something is something. Here there should have been a comma before "where", but where should one place it?

It gets even worse. The capitalisation argument breaks down with proper nouns. For example we might have:

something = "The quick brown Fox jumps over the lazy dog :)"
that = find(isequal('b'), something)
looks = find("brown", something)
like = replace(something, "brown" => "red")
code = ":"")"^2

Fox is a really good guy. "Fox" is now a name, and thus should be capitalised. In this situation all three cases (full stop, comma, no punctuation) are plausible. Note that the first sentence after the block/the continuation of the block's sentence (since it's ambiguous) does not convey any logical meaning in this example, but it just goes to show how an ambiguous sentence/series of sentences could be formed.

Is there an unambiguous resolution to this?


Solution 1:

If your sensibilities really will not permit you to end a sentence with a block of code without putting a period after it, or to drop a comma that belongs after a block of code, you should treat blocks of codes as figures, caption them, and set them apart from the text with references. (I.e., “see Fig. 13” or “see Code Block 13.”) This system also has the advantage that you will not need to break a block of code over more than one page (unless the code is longer than one page).

Otherwise, just omit the punctuation after a block of code. This is what is often done for pictures in children's books. For example, here is part of the first page of The Little Prince, by St. Exupéry:

picture of boa constrictor digesting an elephant, or maybe a hat, without punctuation after it. From The Little Prince