this post was submitted on 05 Apr 2025
140 points (88.0% liked)

Programmer Humor

22250 readers
802 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS
(page 2) 8 comments
sorted by: hot top controversial new old
[–] Sibbo@sopuli.xyz 3 points 2 days ago

Wasn't this {fmt} library merged into STL now? Does this solve this issue?

Anyways, there was also a constant that is the OS line ending without a flush, right?

[–] palordrolap@fedia.io 2 points 2 days ago (2 children)

If endl is a function call and/or macro that magically knows the right line ending for whatever ultimately stores or reads the output stream, then, ugly though it is, endl is the right thing to use.

If a language or compiler automatically "do(es) the right thing" with \n as well, then check your local style guide. Is this your code? Do what you will. Is this for your company? Better to check what's acceptable.

If you want to guarantee a Unix line ending use \012 instead. Or \cJ if your language is sufficiently warped.

load more comments (2 replies)
[–] schnurrito@discuss.tchncs.de 2 points 2 days ago (1 children)

Kinda in Java, you can call System.out.println or you can call System.out.print and explicitly write the newline.

[–] uranibaba@lemmy.world 2 points 2 days ago (1 children)

I haven't looked at the code but I always assumed that println was a call to print with a new line added to the original input.
Something like this:

void print(String text) { ... }
void println(String text) { this.print(text + '\n'); }
load more comments (1 replies)
[–] slazer2au@lemmy.world 1 points 2 days ago

As long as it doesn't end in ;

[–] istdaslol@feddit.org 1 points 2 days ago (2 children)

\n is fun until you’re an a system that needs an additional \r

[–] Arghblarg@lemmy.ca 1 points 2 days ago

Bedeviled NXP/ARM SDK stdlib. Hate it, we need \n\r there. Why????!?!?! What a PITA.

load more comments (1 replies)
[–] deegeese@sopuli.xyz 1 points 2 days ago (1 children)

Doesn’t endl predate C++?

load more comments (1 replies)
load more comments
view more: ‹ prev next ›