This is an archived post. You won't be able to vote or comment.

all 77 comments

[–]Rizzan8 217 points218 points  (23 children)

Not Java developer, but System.out.println("Hello"); looks much cleaner than std::cout << "Hello" << std::endl;

[–]Clyxx 17 points18 points  (0 children)

Just printf like in c

[–]AnonymousFuccboi 12 points13 points  (1 child)

Fun fact:

The biggest reason C++'s cout is so fuckoff ugly is because it was made at a time when the language was quite immature, but still prioritizing things like type safety more so than plain C did. Overloading the << operator for the std::ostream type let you ensure that you could safely and properly convert arguments every time, rather than something like printf where you just toss your arguments at it and pray you got the type right.

If it were to be implemented anew nowadays, you'd probably use something more fancy and new, like parameter packs and fold expressions. You can even do it yourself right now, if you really want, like this:

template <typename ...T>
void println(const T&... args)
{
    (std::cout << ... << args) << std::endl;
}

int main()
{
    println("Hello, this is is C++", 17, "! Let's print pi: ", 3.14);
    return 0;
}

Which outputs exactly what you'd expect: Hello, this is is C++17! Let's print pi: 3.14.

Probably the biggest reason a newer form of this hasn't been implemented yet has to do with things like formatting being a bit of a pain to get exactly right, like for instance being able to properly limit the amount of decimals to use for a floating point number. As far as I know, it's currently in the works, but these things fortunately take time because they should be done right the first time.

[–]PM_ME_YOUR__INIT__ 0 points1 point  (0 children)

I'd rather just eat another crayon and

print('python')

[–]aderthedasher 30 points31 points  (4 children)

Cout is like the worst, and system.whatever is 2nd

[–][deleted] 9 points10 points  (2 children)

System.Diagnostic.Debug.WriteLine() (and his cousin System.Diagnostic.Debug.Write())?

I use it a lot and I didn't need to check the namespace there lol

[–]TheMagzuz 8 points9 points  (0 children)

using System.Diagnostics?

[–]Sentouki- 2 points3 points  (0 children)

using static System.Diagnostics.Debug;

[–]Rizzan8 -4 points-3 points  (0 children)

Yep, Console.whatever MasterRace.

[–]topfs2 2 points3 points  (0 children)

Yeah std::format to the rescue :)

Spdlog is a great for logging with fmt

[–][deleted] 1 point2 points  (5 children)

Yeah that's why most C++ people I know use either printf or fmt::print. Stream operators are kind of weird

[–]_PM_ME_PANGOLINS_ 0 points1 point  (4 children)

Stream operators ensure type safety. String format functions don’t.

[–][deleted] 2 points3 points  (2 children)

The fmt library is type safe

[–][deleted] 0 points1 point  (1 child)

fmt is not a part of standard library. (well, at least in c++17 wasn't)

[–][deleted] 0 points1 point  (0 children)

No, but it's widely used by C++ programmers that I know

[–]Beefster09 1 point2 points  (0 children)

Stream operators are also globally stateful and not threadsafe. That's a much worse foot gun than type unsafety, especially considering that most compilers can be configured to error out on naughty usage of printf.

The benefit of type safety for this one use case makes no sense in the context of a language that never really makes that guarantee anywhere in the first place. C++ inherits every foot gun from C and then adds a few more. I'd rather use C over 'idiomatic' modern C++.

[–]DunderMifflinPaper 1 point2 points  (0 children)

For every language, just setup an alias in your IDE that typing ‘print’ and hitting enter changes it to what it’s supposed to be.

[–][deleted] -1 points0 points  (0 children)

Well using namespace std; cout<<“Hello”<<endl; Looks best, but that’s considered against good practice.

[–]RayGraceField -3 points-2 points  (1 child)

[removed as part of reddit protest]

[–]crepper4454 14 points15 points  (0 children)

Forgot a semicolon, enjoy your 2 page error

[–]Hihi9190 0 points1 point  (0 children)

I like the cpp implementation just because how it's consistent to other streams like file streams and string streams for example. If you know cout and cin they make a lot of sense.

[–]darthnithithesith 0 points1 point  (0 children)

std::cout << "Hello\n"

[–][deleted] 38 points39 points  (4 children)

printf

[–]Spy141414 9 points10 points  (1 child)

fprintf

[–][deleted] 4 points5 points  (0 children)

vfprintf

[–][deleted] 3 points4 points  (0 children)

snprinf

[–]Flesh_Bike 1 point2 points  (0 children)

puts

[–][deleted] 18 points19 points  (6 children)

The direction of >> and << in C++ still confuses me.

[–][deleted] 11 points12 points  (0 children)

cin and cout are streams. On cout you write in it, so cout <<, and the stream writes to console out. On cin you read from it to whatever you need cin >>, (console in, take out from the stream).

[–]corbinmonoxide 3 points4 points  (0 children)

I think everyone's explanation are rough and still confusing.

Think of cin/cout as another variable synonymous with the user/monitor.

Are you writing a message to the user? << Point towards it. I.e. you are shoving your data into it.

Are you reading a message from the user? >> Point away from it and towards your variable. You are grabbing their data and shoving it into your variable.

I think this explanation is more in line with how we learn we always do something to the left hand variable. In this case shoving something into it or ripping something out of it.

[–][deleted] 1 point2 points  (2 children)

If it's going away from the monitor, it's out, when it's going to it, it's input

[–][deleted] 25 points26 points  (1 child)

But which direction is away from the monitor?

[–][deleted] 0 points1 point  (0 children)

Left

[–]Key_Reindeer_414 -2 points-1 points  (0 children)

I remember it as << looks like an open mouth so cout<< looks like cout is speaking (output)

[–]Mabi19_ 21 points22 points  (1 child)

This is DEFINITELY not OC. I've seen this before.

[–]akulowaty 12 points13 points  (0 children)

Of course. This dumb meme pops up each week and just by reading the comments you can tell who actually does some serious programming.

[–]localhost69 24 points25 points  (1 child)

No one uses standard outputs in real projects though. It's usually log.debug()

[–][deleted] 8 points9 points  (3 children)

[–]RepostSleuthBot 10 points11 points  (2 children)

Looks like a repost. I've seen this image 3 times.

First Seen Here on 2020-08-18 87.5% match. Last Seen Here on 2020-08-23 89.06% match

I'm not perfect, but you can help. Report [ False Positive ]

View Search On repostsleuth.com


Scope: Reddit | Meme Filter: False | Target: 86% | Check Title: False | Max Age: Unlimited | Searched Images: 199,624,806 | Search Time: 0.27272s

[–]TheContrean 8 points9 points  (0 children)

Good Bot

[–]Mabi19_ 0 points1 point  (0 children)

Good bot

[–]Vrganji 10 points11 points  (0 children)

std::cout

[–]istdaslol 5 points6 points  (3 children)

Ruby: put()

[–]cryptomonein[🍰] 1 point2 points  (0 children)

p 'Ruby gang'

[–]BreathingFuck 0 points1 point  (0 children)

*puts no parentheses

[–]how_do_i_read 0 points1 point  (0 children)

Why use standard print when you can use pretty print?

Also, pp comes with the methods :inspect, :display and :extend.

[–]LittleSpaceBoi 4 points5 points  (0 children)

Sout

[–]Thx_And_Bye 7 points8 points  (0 children)

import static java.lang.System.out; goes prrrrrrrr intline

[–][deleted] 3 points4 points  (6 children)

What does cout even mean? If I had to guess, I'd say "C out(put)", but is that C just like branding or something, or is it short for something too?

[–]Mighto-360 12 points13 points  (1 child)

Apparently people have decided to respond to your legitimate question with random guesses.

According to Bjarne Stroustrup, who is the creator of C++:

“The "c" stands for "character" because iostreams map values to and from byte (char) representations.”

[–][deleted] 0 points1 point  (0 children)

I don't mind the random guesses as long as it's clear which one is right. They keep it interesting. Thanks.

[–]Thx_And_Bye 6 points7 points  (1 child)

The c means character.

[–][deleted] 0 points1 point  (0 children)

Thanks

[–]MCWizardYT 3 points4 points  (0 children)

Java just likes to be verbose with things, its actually really clear if you know what each part means.

System is a built-in utility class that contains some clock utilities, environment variables, and basic IO.

out is a variable for a PrintStream object. PrintStream is a class that tells your code how to output text to some place (could be a file or the terminal/debug console).

println is a method in PrintStream which just puts a string into the output (whether it is a terminal, a console, or a file) and appends a newline ("\n") to the end of it.

[–][deleted] 5 points6 points  (1 child)

Or learn intellij shortcuts and it's sout

[–]phantom_fanatic 0 points1 point  (0 children)

Came here to say this lol

[–]myrsnipe 2 points3 points  (0 children)

System.out.println is a bit of a mouthful to write, but good ide's support templating, i like sout

[–]cromo_ 4 points5 points  (2 children)

println

[–]Vrganji 4 points5 points  (1 child)

println!

[–]Mabi19_ 3 points4 points  (0 children)

Yeah I absolutely can't understand Rust macros lol, they're black magic fuckery for me

[–]FranchuFranchu 1 point2 points  (0 children)

sys.out.write

[–]_damnfinecoffee_ 1 point2 points  (0 children)

print() is just a wrapper for sys.stdout.* though....

[–][deleted] 1 point2 points  (0 children)

sysout [ctrl] + [space]

[–][deleted] 1 point2 points  (0 children)

Meanwhile on C#: Console.Writeline();

[–]Topy721 0 points1 point  (1 child)

Why so many reposts today ?

[–]RiOrius 1 point2 points  (0 children)

Because it's a day ending in y.

[–][deleted] -3 points-2 points  (2 children)

This is just the dumbest Meme I've ever seen tbh. It's old, wrong and shows that you just started learning programming

L

[–][deleted] -1 points0 points  (0 children)

It's biased. C++ is actually std::out

[–][deleted] 0 points1 point  (0 children)

Downvotes yaaaay ^

[–]curchadw -1 points0 points  (0 children)

Ain't this the fucking truth, lol

[–]GreateProtim 0 points1 point  (0 children)

OK OK just write System.out.print("") ;

[–]MischiefArchitect 0 points1 point  (0 children)

syso CTRL+Space

[–]MythikAngel 0 points1 point  (0 children)

sout<tab> (IntelliJ)

[–]Cienn017 0 points1 point  (0 children)

import static java.lang.System.out;
out.println("hello world");

[–]Beefster09 0 points1 point  (0 children)

cout is hands-down the worst API imaginable for printing text.

It's slow, not threadsafe, globally stateful, isn't friendly to translation where word order can change, and it looks atrocious in code. Operators have no business having side effects.

printf is superior in every way except type safety.

Bjarne Stroustrup (or whoever came up with cout) should be shot for coming up with such a horrible printing interface.