Hacker News new | ask | show | jobs
by Night_Thastus 499 days ago
Something about the formatting of the code blocks used is all messed up for me. Seems to be independent on browser, happens in both Firefox and Chrome.
8 comments

This is a Bjarne issue. For personal reasons he uses proportional fonts in his code blocks (in his texts) instead of monospaced and the code snippets always look bad. I guess he is stuck in his ways, just have to work around this ugly look.
Looking at how aesthetically charming the C++ syntax is, I wouldn't expect anything less than Comic Sans code blocks
> This is a Bjarne issue.

I have come to find this category of error to be distressingly large.

Bjarne has nothing to do with the HTML/CSS pages of the ACM site, which select for displaying the code the default monospace font that is configured in the browser of the user.

If a proportional font is used for rendering, the most likely cause is that the user has not configured the default monospace font in the settings of the browser.

This is not a Bjarne issue.

The font is selected by the HTML/CSS of the ACM site, not by Bjarne.

There may be a bug in the CSS of the ACM site, but I think that it is more likely that anyone who does not see correctly formatted code on that page has forgotten to open the settings of their browsers and select appropriate default fonts for "serif", "sans serif" and "monospace".

As installed, most browsers very seldom have appropriate default fonts, you normally must choose them yourself.

In this case, whoever does not see a monospace font, which is mandatory for rendering the code on that page, because the indentation is done with spaces, which become too narrow if rendered with a proportional font, must have that proportional font set in their browser as a default monospace font, so they should correct this.

No, the formatting was definitely botched. It should look much better than it does even in a proportional font.
Agreed. I wouldn't mind if, say, end of line comments weren't perfectly aligned. There's zero indentation so things like

     for (string line; getline(is,line); )
  s.insert(line);
are hard to visually parse.
This must depend on some settings of the browser and perhaps also on the locally installed typefaces.

On my Firefox on Linux, this HTML page is not rendered with any custom typefaces, but it uses those specified by me as defaults for serif/sans serif/monospace.

The C++ code is rendered in my browser with my default, i.e. with JetBrains Mono and there is nothing weird.

The code quoted by you is indented as expected, not as in your posting.

On my computer, I have mostly typefaces that I have bought myself and which are seldom encountered in most computers. I do not have any of the typefaces that are typically specified in CSS rules, i.e. none of the typefaces that can be found in default installations of Windows, Linux or MacOS.

So perhaps there is a bug in their CSS at the definition of "wp-block-code", which on other computers selects a bad typeface that is proportional, so that the narrow spaces make the indentation disappear. (Their wp-block-code says "font-family:inherit" and I have not searched further to see from where the wrong font-family may be inherited.)

Here, perhaps because that bad typeface cannot be found, the browser uses my default monospace font and the code is displayed fine.

Or else, perhaps you have not set in your browser a proper default for monospace fonts and it just takes Arial or other such inappropriate system font even for monospace.

The formatting has been (partially) fixed since it was posted.
this is definitely an issue for the editors of the ACM journal
It's typical Stroustrup style to write code in a variable width font. I'd wager they didn't have an option to use a variable-width font in their code blocks in their CMS and normal paragraphs are trimmed automatically.

I didn't see the author at first. However, immediately after seeing the code I checked for the author, because I was sure it was Stroustrup.

The other give away is that he wants to use his awful "I/O streams" feature even though he also wants very modern features like modules.

Normal people who have a modern environment would std::println but Bjarne insists on using the I/O streams from last century instead

While you are right about the books of Stroustrup, here your inference is wrong, because Stroustrup cannot have anything to do with the CSS style sheets of the ACM Web site, which, in conjunction with the browser settings, determine the font used for rendering the text.

On my browser, all the code is properly indented, most likely because my browsers are configured correctly, i.e. with a monospace font set as the default for "monospace".

Whoever does not see indentation, most likely has not set the right default font in their browser.

They just fixed it by now. It was different when the story was new.
There’s a better formatted PDF on Stroustrup’s website: https://stroustrup.com/21st-Century-C++.pdf .
That is massively better, thank you!
The code blocks aren't in a preformatted tag like <pre> so the whitespace gets collapsed. It seems the intention was to turn spaces into &nbsp; but however it was done was messed up because lots of spaces didn't get converted.
The code blocks are formatted as "wp-block-code", which seems to select the default monospace font of the browser.

My browser has an appropriate default monospace font (JetBrains Mono), so the code is formatted and indented correctly, as expected.

Where this does not happen, the setting for the default monospace font must be wrong, so it should be corrected.

It has been changed since it was posted. You can check the Wayback Machine for the original.
Have you verified that your browsers have correct settings for their default fonts, i.e. a real monospace font as the default for "monospace"?

Here the code is displayed with my default monospace font, as configured in browsers, so the formatting is fine.

There are only 2 possible reasons for the bad formatting: a bug in the CSS of the ACM site, which selects a bad font on certain computers or a bad configuration of your own browsers, where you have not selected appropriate default fonts.

Firefox reader view seems to be a slight improvement since it removes the random right alignments in the article.
This doesn't seem to be a code blog, but a general science communication blog. The editors may not be familiar with code syntax, and may simply be using a content management system and copy-pasting from source material.
> ACM, the Association for Computing Machinery, is the world's largest educational and scientific society, uniting computing educators, researchers and professionals to inspire dialogue, share resources and address the field's challenges.

Most of programming language conferences are organized by ACM.

I know, but the blog itself doesn't seem oriented to post code snippets. I clicked a few articles which were much more general.
Yeah. Looks nasty. Don't the editors of the ACM have a say on how the article is presented?