I don't see how that's relevant, Java doesn't use the << operator for its print, it uses arguments, and also, it should be print, println implies a \n at the end, although you pretty much nailed the unnecessarily long path for the print statement (although you can statically import it if you're so inclined to use System.out.println a lot
Dunder methods are so damned fun. The fact that you can make a very loose DSL at times. While it does make some more complex code reading, there are just some times where using >>, &, |, etc. as methods between two things can sometimes just be very clear.
It’s just a string here—the code is assigning the value of the new line character to endl, then that gets passed in to the print function the same way “Hello” and “World” do, except that this is hidden in a variable
So it’s not a default handling but it’s a user assigned variable that works
78
u/sam-lb Aug 14 '21
Lol. You think that's bad?
https://gist.github.com/sam-lb/38824677afaa16334b590b1c2b0e5a24
3
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Aug 14 '21
Image Transcription: Code
[The screenshot shows code and output in a console, as follows:]
I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!
366
u/WaterFoxforlife Aug 14 '21
When you want to try python after doing C++
429
u/grknado Aug 14 '21
This is genius, but I've made an improvement:
39
u/taptrappapalapa Aug 14 '21
This is technically what C++ does with
std::out. The left bit shift operators are overloaded28
u/ekolis Aug 14 '21
Why not call your variable
cout?46
u/chimericCreation Aug 14 '21
This is exactly how it works in cpp too so don’t be too surprised
61
u/KBAC99 Aug 14 '21
You forgot to make endl flush :)
13
u/ywBBxNqW Aug 14 '21
Why were you surprised?
11
u/sixtyfifth_snow Aug 14 '21
The variable p should be named as cout.
9
u/[deleted] Aug 14 '21
This has been mildly interesting.
25
u/Igotbored112 Aug 14 '21
I don't even use this syntax in C++ because I hate it so much. This is the absolute worst, thank you. You should totally rename "p" to "stdout" tho.
7
u/angel14995 Aug 14 '21
Dunder methods are so damned fun. The fact that you can make a very loose DSL at times. While it does make some more complex code reading, there are just some times where using
>>,&,|, etc. as methods between two things can sometimes just be very clear.9
u/sohang-3112 Aug 14 '21
Why is this bad code? Obviously, don't do this in real code (just use
print) - but this just seems like a humorous attempt to imitate C++ in Python.4
u/anilctrn Aug 14 '21
Would that semicolon compile?
3
u/KyleDrogo Aug 14 '21
delet this 😡
3
u/KYIUM Aug 14 '21
Thanks, I hate it.
3
u/[deleted] Aug 25 '21
I did this as a joke to annoy some python programmers lmao
2
u/Outrageous-Wave-2946 Aug 14 '21
Thanks I learned about more python tricks today
2
u/suomensalmiakki Aug 14 '21
Why “p”? Why variable name is not “cout”?
2
u/AlwaysNinjaBusiness Aug 14 '21
This is what I'll start doing from now on.
2
u/pekkalacd Oct 04 '21
That’s actually pretty cool. I might try this.
4
u/moonlandings Aug 14 '21 edited Aug 14 '21
Does python have some default handling of endl that I’m not familiar with? Because otherwise this doesn’t work…
Edit: I realized after posting this that endl is defined in the terminal. My bad.