this post was submitted on 02 Feb 2024
1021 points (98.3% liked)

Programmer Humor

32179 readers
345 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] SpaceNoodle@lemmy.world 20 points 8 months ago (2 children)

If you're using C++, why not use streams?

[–] solrize@lemmy.world 16 points 8 months ago (2 children)
[–] SpaceNoodle@lemmy.world 5 points 8 months ago* (last edited 8 months ago) (1 children)

Well, that means that it's also a C++ thing, but streams are an even slicker concept that aren't a C thing, making higher-level code look nice and shiny - and abstracting away loads of I/O pain points while encapsulating useful features.

[–] solrize@lemmy.world 7 points 8 months ago (2 children)

C++ streams are ugly in their own right, but C++ preferred practice these days is to treat it as its own language rather than as a C superset. That is, lots of crufty old C stuff still works in C++ for legacy reasons, but using it when you don't have to is considered inappropriate.

The real fun about treating C++ as a superset of C begins when you run into cases where the languages differ.

I'm not talking about classes and templates and stuff like that either, I'm talking about relatively simple syntax that people expect to be present in both languages.

if (1) int a = 42;

is valid C++, but will not valid C. That's because the definition of a what a statement is differs between the two and has since the 80s!

[–] SpaceNoodle@lemmy.world 1 points 8 months ago

Yeah, streams are old and crusty and horrific on the inside (don't ask about the time I implemented a socket layer with streams), but still less clunky than the C standard library (unless you're really into being a memory Nazi).

[–] SpaceNoodle@lemmy.world 1 points 8 months ago
[–] stsquad@lemmy.ml 1 points 8 months ago (1 children)

I wasn't personally using C++, I was using relatively modern C which has had an homegrown object system added to it.

[–] SpaceNoodle@lemmy.world 1 points 8 months ago* (last edited 8 months ago)

Then it's not C++. And probably an even bigger mess.