140
top 50 comments
sorted by: hot top controversial new old
[-] diemartin@sh.itjust.works 6 points 1 day ago
fprintf(stdout, "%c", '\012');
[-] Archr@lemmy.world 6 points 1 day ago* (last edited 1 day ago)
[-] Croquette@sh.itjust.works 4 points 1 day ago

I just learned that in Python, it's fucking terrible. Python is a fucking mess and my next script will be in a different language.

[-] qaz@lemmy.world 4 points 1 day ago

Perhaps TS is not a terrible language for shell scripts after all

[-] Croquette@sh.itjust.works 2 points 10 hours ago* (last edited 10 hours ago)

Never tried it, but I will probably be more at home than python.

[-] jdeath@lemm.ee 4 points 1 day ago

python is a bad joke that never ends

[-] andMoonsValue@lemmy.world 3 points 1 day ago

As a python lover, I have to ask, what don't you like about it and what languages do you generally prefer?

[-] Croquette@sh.itjust.works 1 points 10 hours ago

I prefer strongly typed languages. Using bytes isn't intuitive.

Transforming certain data types into other data types is often not straightforward.

The identation is the worst though. Let me format the code however I want.

[-] Gustephan@lemmy.world 10 points 1 day ago

Fuck endl, all my homies hate endl

[-] jdeath@lemm.ee 1 points 1 day ago

bloods 4 lyfe

Cout << "\n"; is dumb and you should feel bad

[-] Gustephan@lemmy.world 0 points 1 day ago

You're right, that is incredibly dumb. Just not for the reasons you think it is. Imagine using iostream rather than stdio and unironically trying to clown on \n

[-] DragonTypeWyvern@midwest.social 1 points 1 day ago* (last edited 1 day ago)

Is this not a debate for freshman students and other assorted opinionated know-nothings? Or just people shitposting.

My mistake. You think it's srs.

(And your opinion is still bad)

[-] Gustephan@lemmy.world 0 points 1 day ago

Oh no! Did I hurt your feelings by clapping back when you insulted me on a shitpost comment chain? Your lack of self awareness is astounding

[-] Oinks@lemmy.blahaj.zone 23 points 2 days ago* (last edited 2 days ago)

I am very sorry to remind everyone about the existence of Visual Basic, but it has:

  • VbCrLf
  • VbNewLine
  • ControlChars.CrLf
  • ControlChars.NewLine
  • Environment.NewLine
  • Chr(13) & Chr(10)

And I know what you're asking: Yes, of course all of them have subtly different behavior, and some of them only work in VB.NET and not in classic VB or VBA.

The only thing you can rely on is that "\r\n" doesn't work.

[-] MTK@lemmy.world 4 points 1 day ago

Apology not accepted, fuck you for reminding me!

[-] jdeath@lemm.ee 3 points 1 day ago

great reminder to avoid microsoft products as much as i can

[-] ulterno@programming.dev 19 points 2 days ago* (last edited 1 day ago)

Simple. \n when you just want a newline.
endl when you need to flush at the moment.

Useful in case you are printing a debug output right before some function that might do bed stuff to buffers.


Edit: I wrote println instead of endl somehow. Guess I need more downtime

[-] embed_me@programming.dev 5 points 1 day ago

I only program in C. I was under the assumption that \n also flushes

[-] pelya@lemmy.world 3 points 1 day ago* (last edited 1 day ago)

It depends on whether you are printing to a terminal or to a file (and yes the terminal is also a file), and even then you can control the flushing behaviour using something like unbuffer

[-] ulterno@programming.dev 2 points 1 day ago

I remember having to fflush a couple of times.

[-] heavydust@sh.itjust.works 48 points 2 days ago

No debate, std::endl can be a disaster on some platforms due to flushing crap all the time.

[-] Rednax@lemmy.world 1 points 1 day ago

Considering std::cout should only directly be used when you are too lazy to place breakpoints, I totally get the decision to auto-flush.

[-] mmddmm@lemm.ee 36 points 2 days ago

It's a very C++ thing that the language developers saw the clusterfuck that is stream flushing on the kernel and decided that the right course of action was to create another fucking layer of hidden inconsistent flushing.

[-] jdeath@lemm.ee 2 points 1 day ago

programmers manage to do stupid shit in every language. i was wondering if there was a way to stop them, and golang comes close but maybe proves it can't be done. idk!

I hear C++ was greatly inspired by the fifth circle of hell.

[-] joyjoy@lemm.ee 20 points 2 days ago

Just because the box says something is flushable doesn't mean you should flush it.

[-] pelya@lemmy.world 29 points 2 days ago* (last edited 2 days ago)

printf is superior and more concise, and snprintf is practically the only C string manipulation function that is not painful to use.

Try to print a 32-bit unsigned int as hexadecimal number of exactly 8 digits, using cout. You can do std::hex and std::setw(8) and std::setfill('0') and don't forget to use std::dec afterwards, or you can just, you know, printf("%08x") like a sane person.

Just don't forget to use -Werror=format but that is the default option on many compilers today.

C++23 now includes std::print which is exactly like printf but better, so the whole argument is over.

I went digging in cppref at the format library bc I thought c++20 or c++23 added something cool.

Found std::print and was about to reply to this comment to share it bc I thought it was interesting. Then I read the last sentence.

Darn you and your predicting my every move /j

[-] LambdaRX@sh.itjust.works 17 points 2 days ago* (last edited 2 days ago)

I prefer \n for 0.001% better performance

[-] Lembot_0001@lemm.ee 25 points 2 days ago

I prefer \n for less typing.

I prefer endl for more typing because it lets me pretend to work more than I am

[-] jdeath@lemm.ee 2 points 1 day ago

^ least deranged coder

[-] BananaOnionJuice@lemmy.dbzer0.com 16 points 2 days ago
std::cout << "\nwhy not both" << std::endl;
[-] rikudou@lemmings.world 5 points 2 days ago

In PHP it exists as well. I try to use PHP_EOL but when I'm lazy I simply do "\n".

[-] lord_ryvan@ttrpg.network 1 points 1 day ago

For me the answer is “Building backend applications with it instead of CLI applications, like Lerdorf intended.”

But also "\n" because it's easier and PHP_EOL is just an alias for "\n"; it's not even platform-dependent.

[-] rikudou@lemmings.world 2 points 1 day ago

PHP_EOL depends on your host system, it's \r\n on Windows.

I don't really want to use what Lerdorf intended, PHP <= 4 was horrible, 5.x was mainly getting slowly rid of nonsense and with 7.x PHP started its slow path of redemption and entered its modern era.

While Lerdorf's vision was great at that time for its intended use case, I wouldn't want to build anything serious in it.

[-] lord_ryvan@ttrpg.network 1 points 1 day ago

It actually outputs "\n" on a Windows system, but modern Windows to recognise that as enough of a newline, nowadays.

I don't really want to use what Lerdorf intended, PHP <= 4 was horrible

Actually a great point!

[-] r00ty@kbin.life 3 points 2 days ago

Maybe c# has similar. There's \r\n or \n like c++ and Environment.NewLine.

Probably it's similar in that Environment.NewLine takes into account the operating system in use and I wonder if endl in c++ does the same thing?

[-] vithigar@lemmy.ca 4 points 2 days ago

C# also has verbatim strings, in which you can just put a literal newline.

string foo = @"This string 
has a line break!";
[-] astrsk@fedia.io 3 points 2 days ago

Just puts(“I’m a teapot”); :)

[-] ArbitraryValue@sh.itjust.works 3 points 2 days ago

C++ style text streams are bad and a dead-end design and '\n'.

load more comments
view more: next ›
this post was submitted on 05 Apr 2025
140 points (88.0% liked)

Programmer Humor

22250 readers
191 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