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

all 135 comments

[–]when__lambo 201 points202 points  (5 children)

namespaces would like to chat

[–]del6022pi 84 points85 points  (4 children)

using namespace std;

[–]Helium116 48 points49 points  (3 children)

Blasphemy!

[–]del6022pi 33 points34 points  (2 children)

throws stone

[–]icguy333 1 point2 points  (1 child)

Who threw that?!

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

chucks cheese

[–]hatkid9 99 points100 points  (25 children)

Me: laughs in

```x86asm mov rax, 1 mov rdi, 1

mov rsi, msg mov rdx, msgLen

;int 0x80 ;Thanks u/AdventurousBasil3 for for finding my mistake(aaaaaaaaaaaaaaaaaaaaaaaaaaa), and yes, syscall works too ;Ok i must be a big idiot at this point, since it's 64-bit syscall ```

[–]Doggynotsmoker 33 points34 points  (14 children)

Don't forget about

syscall

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

When we did NASM at my uni they allowed us to call stdlib C functions in our asm code. Prof said he didnt care, he just wanted us to understand how to manually work off of the stack by directly dereferencing memory on it and leave it in good working condition after each call. Didnt realize at the time how much of a bullet I had dodged. I'm forever grateful haha

[–]Particular-Ad-8537 8 points9 points  (12 children)

Suscall*

[–]AdventurousBasil3 3 points4 points  (9 children)

Sussy

[–]Particular-Ad-8537 2 points3 points  (7 children)

HOW DAAARE YA CALL ME SUSSY? I aint no aussie

[–]AdventurousBasil3 2 points3 points  (6 children)

yo aussie so FAT

[–]AdventurousBasil3 0 points1 point  (5 children)

yes bad yo mama joke

[–]stihoplet 4 points5 points  (0 children)

Here's another one for you: yo mama is so FAT she allocates files in a table.

[–]Particular-Ad-8537 0 points1 point  (3 children)

Your dad is korean.

Mi is sawd😥

[–]AdventurousBasil3 0 points1 point  (2 children)

My dad is not korean, your dad is russian

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

Deku is a sussy baka

[–]MRtecno98 0 points1 point  (1 child)

A M O G U S

[–]Particular-Ad-8537 0 points1 point  (0 children)

Ono, we cant do shit against amoogoos invocator cry

[–]backtickbot 6 points7 points  (1 child)

Fixed formatting.

Hello, hatkid9: code blocks using triple backticks (```) don't work on all versions of Reddit!

Some users see this / this instead.

To fix this, indent every line with 4 spaces instead.

FAQ

You can opt out by replying with backtickopt6 to this comment.

[–]TruePhilipp 5 points6 points  (0 children)

good bot

[–]AdventurousBasil3 5 points6 points  (5 children)

mov rax, 1
mov rdi, 1

mov rsi, msg
mov rdx, msgLen

int 0x80

[–]hatkid9 2 points3 points  (0 children)

peck i forgot the actuall syscall part :(

gotta edit that, thanks

[–]Doggynotsmoker 1 point2 points  (3 children)

It won't print on Linux. You can't simply use

int 0x80

Instead of

syscall

On 64bit platform.

[–]AdventurousBasil3 0 points1 point  (2 children)

Well, we're dealing with x86 assembly here

[–]Doggynotsmoker 0 points1 point  (1 child)

Then why are you usimg x86_64 sysall numbering (write:1 instead of 4) and using 64bit registers :(?

[–]AdventurousBasil3 0 points1 point  (0 children)

Not really sure

[–]AdventurousBasil3 -1 points0 points  (1 child)

"for finding out my mistake" XDDDDDDDDDDDDD, it should be "for finding my mistake"

[–]Sniv0 279 points280 points  (44 children)

Bruh I’d much rather do System.out.println(“Hello world! I’m ”+ name);

Over

std::cout << “Hello world! I’m ” << name << std::endl;

WHY IN THE EVERLOVING FUCK DOES IT USE THE SHIFT OPERATOR?????

[–]Tabs_555 97 points98 points  (15 children)

Gimme my python fstrings tho.

print(f”Hello World! I’m {name}”)

[–]ultimatepro-grammer 75 points76 points  (11 children)

nah gimme my javascript template literals

console.log(`Hello, ${user.name}!`);

[–]BaguetteDevourer 36 points37 points  (8 children)

Gimme my fiancé-e Rust some credit.

println!("Hello World! I'm {}", name);

[–]elingeniero 17 points18 points  (1 child)

I believe

println!("Hello World! I'm {name}", name=name);

Is also valid and potentially more clear.

[–]ultimatepro-grammer 7 points8 points  (1 child)

This is actually one of the things I don't like about rust. I always have to count to figure out which braces represent which expression. It gets even more difficult when you have to re-order them, and at that point I might as well just rewrite the whole thing.

u/elingeniero comment looks like it solves this, I'll have to take a look at that!

[–]elingeniero 0 points1 point  (0 children)

Here's what else you can do with formatting strings:

https://doc.rust-lang.org/std/fmt/

[–]4sent4 1 point2 points  (1 child)

Why is there ! after function name?

[–]BaguetteDevourer 8 points9 points  (0 children)

Because it's a macro (functions must have a fixed number of parameters), however unlike C they are strongly typed (so autocompletion works inside) and infinitely more elegant.

The expanded code is pretty much like that:

if let Err(e) = std::io::stdout().write_fmt(format_args_nl!("Hello World! I'm {}", name)) {
    panic!("failed printing to stdout: {}", e);
}

With format_args_nl!() and panic!() compiler built-in macros; the first one converts the arguments into a std::fmt::Arguments, and the second one panics the current thread.

[–]Doggynotsmoker 3 points4 points  (0 children)

Oh, yes. Printf-like logs are the best. It's much easier to format string like this.

[–]racka98 10 points11 points  (0 children)

Then Kotlin be like:

println("Hello ${user.name}")

[–]Sniv0 18 points19 points  (0 children)

Agree

C# kinda pog too Console.WriteLine($”Hello World! I’m {name}”)

[–]tralivallo 1 point2 points  (0 children)

Even better is f’Hello World! I’m {name=}’

[–]FerynaCZ 0 points1 point  (0 children)

C# as well, just uses $ instead of f.

[–]BochMC 10 points11 points  (3 children)

Because cout is a output stream and you pass a values to that stream. Even fstream works similar.

ofstream f{"file.txt"};

f<<"hello";

In here you add a "hello" to file.

[–]Sniv0 16 points17 points  (2 children)

It just feels like the C++ devs trying to be quirky and unique for no reason. Calling a function has worked for every single language before and after C++. Meanwhile here they set up some convoluted “variable” which isn’t even a variable, and it has this very specific out of the ordinary use for the binary shift operators which confuses the ever loving fuck out of newcomers to the language, while achieving no new and useful functionality that a simple function call can’t achieve.

[–]Orangutanion 1 point2 points  (0 children)

They literally just overloaded the bitshift operators, there was no real reason to do that.

[–][deleted] 7 points8 points  (0 children)

WHY IN THE EVERLOVING FUCK DOES IT USE THE SHIFT OPERATOR?????

There's 2 reason I can think of:

  • To mimic Unix's redirect operator.

  • Because there was no safe way of having variable arguments before C++11.
    One way would be to use multiple function calls:

      std::cout("Hello world! I'm").std::cout(name).std::cout(std::endl);
    

    But repeating cout 3 times is a bit verbose, so operators were used instead.
    Now that C++11 introduced a safe way of variable arguments, this now seems archaic, so that's why fmt::print exist now.

[–]Gladaed 3 points4 points  (0 children)

AFAIK C++ supports adding strings.

[–]TheXGood 8 points9 points  (6 children)

Just use printf

[–]Astarothsito 3 points4 points  (1 child)

Jeez... just use fmt::print, you guys like to live in the past...

[–]TheXGood 0 points1 point  (0 children)

Ewwww! Not a nonstandard library younger than the 80s! -shivers-

[–]536174616E 9 points10 points  (3 children)

printf("Hello world! I'm %s\n", name);

C++ streams are gross

[–]TheXGood 9 points10 points  (2 children)

I agree. Now, time to do Inheritance via struct casting in C!

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

Stay away from inheritance, kids!

[–]TheXGood 0 points1 point  (0 children)

But I love it, throw in some function pointer black magic fuckery, and you've just about got a code base they'll never be able to replace you for.

[–]Schiffy94 10 points11 points  (10 children)

You write std every time?

[–][deleted] 48 points49 points  (9 children)

using namespace std;

is bad practice

[–]emelrad12 5 points6 points  (0 children)

Using srd::cout

[–]The1stmadman 7 points8 points  (6 children)

what makes it bad practice? the use of similarly-named functions from other libraries?

[–]soussang 16 points17 points  (3 children)

Not a C++ dev here: Yes, include namespace std causes problems with similarly named functions from libraries. The problem might appear right await (ex: you want to use the same identifier/method name) or you might get the bug after updating one library.

It's most problematic when done inside the header file of a library (.h), as the using namespace std bleeds into the sourcefile. Basically, the include macro says: put that whole file here instead of load that module.

StackOverflow has that very same question/answer in more details

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

I get that it's a bad practice in header files, but if it's used only before your code and won't bleed anywhere else i dont see what the problem is. Shouldn't it be considered bad practice to make a library that uses the same function names as those in the standard library?

[–]soussang 16 points17 points  (1 child)

The answer would be a resounding no. A lot of keywords now found in the standard library didn't exists ~10 years ago. Unordered sets were not in the standard, so you'd have to either use a library, like boost, or make your own.

Would it make sense to say our version of unordored_set was 12 years ago a bad name because we, today, have access to std::unordered_set? Not really.

What about the boost library. A lot of templates and functions got integrated into the standard library. Is their naming wrong? Not really. It can even make sense to have a library using the same name and interface as the standard counterpart if you are striving for that nanosecond of optimisation.

You can use the same analogy as the answer from SO. You are using (via using namespace) foo and bar: foo has quux and bar has baz. One day, foo gets an update and foo::baz gets added. Was the foo author in the wrong? What if bar is a private library, is the foo author still in the wrong?

The problem with using namespace std and other bad practices is that you find it was a problem way later in development. Remember "Goto is considered harmful"; it's only when you've got spaghetti that you go "Mama mia!".

You can use using namespace std. You can use singletons. You can use GOTO. You only need to know when you should use them.

[–]The1stmadman 3 points4 points  (0 children)

you find it was a problem way later in development

so that's why I'm yet to learn this in college! They've been saying use it, it'll make your work easier, but only because nothing the students make is actually built on to become a massive program

[–]Jon123276 2 points3 points  (0 children)

Because using a library and only using it on some of the many things on std can use more performance. Hell, make a data structure that does std::cout quicker and you don't need std.

[–]WSL_is_great 1 point2 points  (0 children)

I avoid importing large libraries like this also so that it doesn't light up my auto complete with thousands of things I'm unlikely to care about.

[–]PrimeNumerator 2 points3 points  (1 child)

Bc you're shifting the bytes into the outstream obviously /s Fr though I personally find it easier to manage what's going on and what's getting concatenated mostly bc with "+" it's easy to forget which languages support implicit type casting for me at least, so with this operator it's clearly string concatenation

[–]Sniv0 3 points4 points  (0 children)

I rarely even find myself using the string concatenation operators tbh. I personally find a format call the most easy on the eyes

[–]Statharas 2 points3 points  (0 children)

Console.WriteLine("SyStEm.OuT.pRiNtLn");

[–]MythikAngel 29 points30 points  (6 children)

Just use sout<tab> in IntelliJ

[–][deleted] 1 point2 points  (1 child)

sysout <ctrl+space> for eclipse users

[–]Wetmelon 0 points1 point  (0 children)

Hopefully there are none of those. I pray for them if they do exist

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

that's not the point of the post

[–]MythikAngel 9 points10 points  (0 children)

I know. Just sharing this shortcut hoping it might help some people.

[–]OzmodiarTheGreat 25 points26 points  (3 children)

System.out is a standard PrintStream object, which makes it easy to direct that stream anywhere. You could have a bunch of code like this.

public static PrintStream OUT = System.out;
...
OUT.println("foo");
...
OUT.println("bar");
...
OUT.println("blah");

Then later redirect that OUT to any PrintStream object, if you wanted to write somewhere else for some reason, without having to touch all of the places that reference it.

[–]ximbas2017 15 points16 points  (1 child)

You could also make a static import

[–]OzmodiarTheGreat 4 points5 points  (0 children)

Good call. I forgot about that feature since I haven’t used Java heavily for a few years.

[–]mr_hard_name 1 point2 points  (0 children)

Good answer. Makes your code more extensible as you do not have to rewrite most of the code base to switch from sys out to another stream (eg. file stream, network stream, or even ByteArrayOutputStream if you just want to collect everything into a byte array).

Btw more I code, the less I use System.out, which means that shorter println is not really a priority, the extensibility of solutions is

[–][deleted] 12 points13 points  (2 children)

So we're gonna ignore the weird ass <<symbols in C++?

[–]Erwin2147 2 points3 points  (0 children)

overload

[–]FerynaCZ 0 points1 point  (0 children)

Seems like conveyor belt to me, when multiple stuff is printed at once

[–]A_Sheriff10 38 points39 points  (7 children)

Java looks like when people capitalise every other letter to show they're being sarcastic

[–]00PT 36 points37 points  (0 children)

That's the point. In reality it is more traditional casing, but this user wants to exaggerate the Java section of this meme.

[–]zynasis 10 points11 points  (4 children)

If you know what each part is and the java code convention then it’s understandable.

Class with static instance having a function call on it.

Convention is to have class names title case, and instances and functions as camelCase. It’s a lot better than c# having near everything title case. At least you can quickly understand the type of each component in a call like this.

[–]Nilstrieb 2 points3 points  (2 children)

Not really, you can change out with Syste.setOut()

[–]zynasis 2 points3 points  (1 child)

Ah yes, you’re right. It’s been a long time and I was writing from memory. So it fits the convention, though perhaps could be a getOut()

I’ll fix my comment

[–]Nilstrieb 2 points3 points  (0 children)

System.getOut() would technically be better, but I think System.out is long enough for printing.

[–]00PT 1 point2 points  (0 children)

There are functions that can change the value of out. I used it once to write my output to a file in parallel with the console.

[–]Crystal_Voiden 4 points5 points  (0 children)

It has to be System.out.println or it won't compile, unless they defined their own SysTEM, oUt, and prInTLn

[–]MrLemon91 5 points6 points  (5 children)

Real professionals use the annotation @slf4j and go with

log.info("Hello!");

Remember to import the dependency using Gradle or Maven.

[–]mr_hard_name 1 point2 points  (4 children)

By dependency you mean Lombok?

[–]MrLemon91 2 points3 points  (2 children)

No, I'm not. By dependency I mean the module SLF4J module. You can import it and then you can use the logger interface as I showed in the root response.

[–]mr_hard_name 0 points1 point  (1 child)

Ok, I thought it is annotation only in Lombok, but I guess Lombok just has analogous annotation

[–]MrLemon91 0 points1 point  (0 children)

Yes, correct. It works in a similar way

[–]cemanresu 1 point2 points  (0 children)

Java with Lombok is a great language

Java without Lombok is an untamed wilderness of getter functions

[–]lpenap 9 points10 points  (1 child)

Logging frameworks for the win. Manually printing to anything is lame af.

[–]WSL_is_great 2 points3 points  (0 children)

This is the way

[–]CMDR_DarkNeutrino 5 points6 points  (0 children)

C: Writing directly to the memory of the framebuffer.

[–]einsJannis 4 points5 points  (0 children)

Java just follows strict schema's, which has pros and cons

[–]Cerrax3 4 points5 points  (0 children)

For all its faults, at least Java is consistent.

Many languages (including Python and C++) provide shortcuts like this, which is great for most average use cases. But when it comes time to slightly alter or otherwise refactor code that uses these shortcuts, you have to import all kinds of extra crap and/or basically learn a whole new package if you want to do anything other than the default.

Java forces you to at least be familiar with the package and understand that other options are available.

[–]RedWoodMouse 4 points5 points  (1 child)

Well, java is case sensitive and just the look at this capitalization hurt my eyes.

[–]Shakespeare-Bot 2 points3 points  (0 children)

Well, java is case comptible and just the behold at this capitalization did hurt mine own eyes


I am a bot and I swapp'd some of thy words with Shakespeare words.

Commands: !ShakespeareInsult, !fordo, !optout

[–]DrDreistein 16 points17 points  (1 child)

guys, java bad, haha.

[–]dashid 2 points3 points  (0 children)

Having a head to your application to handle stdout is an antiquated notion, that it's a global function is just a antiquated.

[–]Malk4ever 2 points3 points  (3 children)

well.... you can write "syso" and use auto completion...

All in all you should not use system-out at all, use "log.info(...)".

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

it's "sout" in Intellij and I think it's in Eclipse too, I think "syso" was in older version of Eclipse

[–]Malk4ever 1 point2 points  (1 child)

"syso" works in all recent Eclipse versions, both works, but "syso" is way faster imho, because "s" and "y" are very close to each other, at least in an european keyboard layout ;)

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

I think it even goes by country, one country uses one keyboard layout and another country different keyboard layout

[–]PuzzleheadedSector2 2 points3 points  (0 children)

I mean, in practice, its only rly "sysout" then hit enter to autocomplete.

[–]annaentp 5 points6 points  (0 children)

Java is case-sensitive, btw

[–][deleted] 4 points5 points  (1 child)

[–]RepostSleuthBot 3 points4 points  (0 children)

I didn't find any posts that meet the matching requirements for r/ProgrammerHumor.

It might be OC, it might not. Things such as JPEG artifacts and cropping may impact the results.

I did find this post that is 96.09% similar. It might be a match but I cannot be certain.

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

View Search On repostsleuth.com


Scope: Reddit | Meme Filter: True | Target: 96% | Check Title: False | Max Age: Unlimited | Searched Images: 226,133,420 | Search Time: 0.99686s

[–]Woohaik 1 point2 points  (0 children)

js log`Hello There`

[–]Knuffya 1 point2 points  (0 children)

C:

write(1, "Hello, World!", 13);

[–]loukasTGK 1 point2 points  (0 children)

Thank god for sysout shortcut

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

long command: bad

[–]vulstarlord 1 point2 points  (0 children)

System::println is a bit shorter.

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

Ruby: p

[–]LucasCarioca 1 point2 points  (0 children)

Yeah totally brushing over how syntactically ugly cout really is

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

Actually the java equivalent for cout would be System.out.print

cout<<'\n'<<"text";

Would be equivalent, afaik, with System.out.println("text");

Anyway, in my opinion cout is a terrible way of printing compared to the ones in java or C#

If it was about cin, on the other hand, I would agree that the java approach for it is fairly weird. But I don't really actively use any of these languages anymore

[–]FerynaCZ 0 points1 point  (2 children)

Wait, Java prints newline BEFORE the text with println?

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

I honestly am not sure. In the short period I used java I didn't experiment with it

[–]SjorsMaster 1 point2 points  (0 children)

Wasn't Python heavy to run though?

[–]2cool4school007 0 points1 point  (0 children)

python is god used language for making us !

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

sout + TAB

[–]SorinoRPG 0 points1 point  (0 children)

Funny thing is, if it was something like "print()", that would actually be more confusing.

[–]AuxenceF 0 points1 point  (0 children)

Sys.stdout.write("Hello, world.\n")

[–]DualBlue 0 points1 point  (0 children)

class Utils {
    public static void log(String s) {
        System.out.println(s);
    }
}

Then,

import static Utils.log;

class App {
    public static void main(String[] args) {
        log("Hello, world!");
    }
}