Skip to content

SL.io.50 (Avoid endl): Mention string streams #1920

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 13, 2022

Conversation

N-Dekker
Copy link
Contributor

@N-Dekker N-Dekker commented Jun 2, 2022

Explicitly mentioned string streams as endl insertions into string streams do actually occur in the wild.

People have been wondering whether endl is specifically useful for a stringstream to get a platform-specific end-of-line character sequence (apparently not):
"Inserting endline into a stringstream"
https://stackoverflow.com/questions/6865398/inserting-endline-into-a-stringstream

But there have also been concerns about the performance effect of endl on an ostringstream:
"Why does using std::endl with ostringstream affect output speed?"
https://stackoverflow.com/questions/12675273/why-does-using-stdendl-with-ostringstream-affect-output-speed

@cubbimew
Copy link
Member

cubbimew commented Jun 6, 2022

CI wants ostringstream to be added to scripts/hunspell/isocpp.dic

And yes, I've also seen the "platform-specific end-of-line" urban legend, I wonder if it should be called out explicitly.

@N-Dekker N-Dekker force-pushed the SL.io.50-Mention-string-streams branch from bbdf585 to 8b750f4 Compare June 6, 2022 09:49
Explicitly mentioned string streams as `endl` insertions into string streams do actually occur in the wild.

With help from Sergey Zubkov.
@N-Dekker N-Dekker force-pushed the SL.io.50-Mention-string-streams branch from 8b750f4 to 3503b5a Compare June 6, 2022 09:54
@N-Dekker
Copy link
Contributor Author

N-Dekker commented Jun 6, 2022

@cubbimew Thanks for your comments. Can you please check if I addressed them correctly and sufficiently?

to the insertion of a `'\n'` character, but also in this case, `endl` might be significantly slower.

`endl` does *not* take care of producing a platform specific end-of-line sequence (like "\r\n" on
Windows). So for a string stream, `s << endl` just inserts a *single* character, `'\n'`.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or \n\r for Mac ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or \n\r for Mac ;)

@BenjamenMeyer You mean '\r', right? But hasn't Mac moved towards using just a single \n, nowadays? Otherwise, are there still actively used C++11 Standard Library implementations for Mac whose file output streams produce a '\r' on each end-of-line?

I did notice the smiley in your comment, but I just want to be entirely sure that it's OK not to mention the old Mac '\r' in the proposed text.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@N-Dekker AFAIK mac is still doing the \n\r - now, perhaps it changes from application to application, but I've still seen it in recent years. The new text called out the Windows behavior as an example; it could be worth noting (legacy or otherwise) the Mac behavior too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just want to be entirely sure that it's OK not to mention the old Mac '\r' in the proposed text.

Please don't mention Macs. Your proposed change is fine. What matters is that it doesn't output a platform-specific line ending, you don't need to give multiple examples of things it doesn't do.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with this PR documenting it ;) (e.g not a change - just the commentary here)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jwakely @BenjamenMeyer Thanks, I won't mention old Macs line endings, if it isn't really necessary. So I also think the PR is OK now.

@BenjamenMeyer
Copy link

cool - glad to have this documented. too bad we can't link back to the definition of std::endl for more authority; but this should do just fine and help curb those urban legends.

@jleffler
Copy link

jleffler commented Jun 7, 2022 via email

@hsutter hsutter merged commit 9ead2c4 into isocpp:master Jun 13, 2022
@hsutter
Copy link
Contributor

hsutter commented Jun 13, 2022

Editors call: Great, thanks!

bgloyer added a commit to bgloyer/CppCoreGuidelines that referenced this pull request Jun 16, 2022
* F.16 ("in" parameters): Move Matrix example to F.20 (return values) (isocpp#1922)

The `Matrix` example and the notes about assignment appear off-topic in rule F.16, as F.16 is specifically about "in" parameters.

With help from Sergey Zubkov.

* SL.io.50 (Avoid `endl`): Mention string streams (isocpp#1920)

Explicitly mentioned string streams as `endl` insertions into string streams do actually occur in the wild.

With help from Sergey Zubkov.

* Extended E.16 to include copy ctor for exception type, closes isocpp#1921

* Fix GitHub Actions build warnings, Marker style should be `*` (isocpp#1925)

* restored reference

* Added references to note

Co-authored-by: Niels Dekker <[email protected]>
Co-authored-by: Herb Sutter <[email protected]>
bgloyer added a commit to bgloyer/CppCoreGuidelines that referenced this pull request Jul 9, 2022
* F.16 ("in" parameters): Move Matrix example to F.20 (return values) (isocpp#1922)

The `Matrix` example and the notes about assignment appear off-topic in rule F.16, as F.16 is specifically about "in" parameters.

With help from Sergey Zubkov.

* SL.io.50 (Avoid `endl`): Mention string streams (isocpp#1920)

Explicitly mentioned string streams as `endl` insertions into string streams do actually occur in the wild.

With help from Sergey Zubkov.

* Extended E.16 to include copy ctor for exception type, closes isocpp#1921

* Fix GitHub Actions build warnings, Marker style should be `*` (isocpp#1925)

* C.166: Use markdown format and document title for link (isocpp#1929)

* C.9: Improve an inline link (isocpp#1933)

Avoid ending the sentence with a dangling "see".

Co-authored-by: Niels Dekker <[email protected]>
Co-authored-by: Herb Sutter <[email protected]>
Co-authored-by: Francisco Moretti <[email protected]>
Co-authored-by: Sven van Haastregt <[email protected]>
bgloyer added a commit to bgloyer/CppCoreGuidelines that referenced this pull request Jul 9, 2022
* Update CppCoreGuidelines.md

* Update CppCoreGuidelines.md

* Update isocpp.dic

* use snake casing

* sake case naming

* C 32 comments (#3)

* F.16 ("in" parameters): Move Matrix example to F.20 (return values) (isocpp#1922)

The `Matrix` example and the notes about assignment appear off-topic in rule F.16, as F.16 is specifically about "in" parameters.

With help from Sergey Zubkov.

* SL.io.50 (Avoid `endl`): Mention string streams (isocpp#1920)

Explicitly mentioned string streams as `endl` insertions into string streams do actually occur in the wild.

With help from Sergey Zubkov.

* Extended E.16 to include copy ctor for exception type, closes isocpp#1921

* Fix GitHub Actions build warnings, Marker style should be `*` (isocpp#1925)

* restored reference

* Added references to note

Co-authored-by: Niels Dekker <[email protected]>
Co-authored-by: Herb Sutter <[email protected]>

Co-authored-by: Niels Dekker <[email protected]>
Co-authored-by: Herb Sutter <[email protected]>
bgloyer added a commit to bgloyer/CppCoreGuidelines that referenced this pull request Jul 9, 2022
* F.16 ("in" parameters): Move Matrix example to F.20 (return values) (isocpp#1922)

The `Matrix` example and the notes about assignment appear off-topic in rule F.16, as F.16 is specifically about "in" parameters.

With help from Sergey Zubkov.

* SL.io.50 (Avoid `endl`): Mention string streams (isocpp#1920)

Explicitly mentioned string streams as `endl` insertions into string streams do actually occur in the wild.

With help from Sergey Zubkov.

* Extended E.16 to include copy ctor for exception type, closes isocpp#1921

* Fix GitHub Actions build warnings, Marker style should be `*` (isocpp#1925)

* C.166: Use markdown format and document title for link (isocpp#1929)

* C.9: Improve an inline link (isocpp#1933)

Avoid ending the sentence with a dangling "see".

* C 32 (#5)

* Update CppCoreGuidelines.md

* Update CppCoreGuidelines.md

* Update isocpp.dic

* use snake casing

* sake case naming

* C 32 comments (#3)

* F.16 ("in" parameters): Move Matrix example to F.20 (return values) (isocpp#1922)

The `Matrix` example and the notes about assignment appear off-topic in rule F.16, as F.16 is specifically about "in" parameters.

With help from Sergey Zubkov.

* SL.io.50 (Avoid `endl`): Mention string streams (isocpp#1920)

Explicitly mentioned string streams as `endl` insertions into string streams do actually occur in the wild.

With help from Sergey Zubkov.

* Extended E.16 to include copy ctor for exception type, closes isocpp#1921

* Fix GitHub Actions build warnings, Marker style should be `*` (isocpp#1925)

* restored reference

* Added references to note

Co-authored-by: Niels Dekker <[email protected]>
Co-authored-by: Herb Sutter <[email protected]>

Co-authored-by: Niels Dekker <[email protected]>
Co-authored-by: Herb Sutter <[email protected]>

Co-authored-by: Niels Dekker <[email protected]>
Co-authored-by: Herb Sutter <[email protected]>
Co-authored-by: Francisco Moretti <[email protected]>
Co-authored-by: Sven van Haastregt <[email protected]>
hsutter added a commit that referenced this pull request Jul 13, 2022
* Update CppCoreGuidelines.md

* Update CppCoreGuidelines.md

* Update isocpp.dic

* use snake casing

* sake case naming

* C 32 comments (#3)

* F.16 ("in" parameters): Move Matrix example to F.20 (return values) (#1922)

The `Matrix` example and the notes about assignment appear off-topic in rule F.16, as F.16 is specifically about "in" parameters.

With help from Sergey Zubkov.

* SL.io.50 (Avoid `endl`): Mention string streams (#1920)

Explicitly mentioned string streams as `endl` insertions into string streams do actually occur in the wild.

With help from Sergey Zubkov.

* Extended E.16 to include copy ctor for exception type, closes #1921

* Fix GitHub Actions build warnings, Marker style should be `*` (#1925)

* restored reference

* Added references to note

Co-authored-by: Niels Dekker <[email protected]>
Co-authored-by: Herb Sutter <[email protected]>

Co-authored-by: Niels Dekker <[email protected]>
Co-authored-by: Herb Sutter <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants