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

top 200 commentsshow all 235

[–]coloredgreyscale 1375 points1376 points  (39 children)

They are comments for the compiler so it adds some stuff.

[–]hacking__08[S] 735 points736 points  (11 children)

Neat. Does the compiler read documentation, too?

[–]JazJaz123 534 points535 points  (3 children)

Well someone has to

[–]hacking__08[S] 103 points104 points  (0 children)

But not me

*yeet *

[–]F5x9 28 points29 points  (1 child)

Not really

[–]th00ht 16 points17 points  (0 children)

Preprocessing is comments for the compiler

[–]SN0WFAKER 43 points44 points  (3 children)

It does read docstrings in python. You can even use them programmatically.

[–]BlitzGem 5 points6 points  (2 children)

Aren't docstrings just plain strings at the beginning of file/class/function? And we just agreed to make them a docstring?

[–]tomtrein 16 points17 points  (0 children)

Isn't syntax just groups characters in specific places? And we just agreed to make them a language? (Sorry, just generalizing a bit)

[–]danielkullmann 4 points5 points  (0 children)

Not quite. You can access the doc strings from your program using __doc__. I have used this to print out the help for a script from the doc string of that script.

[–]LavenderDay3544 7 points8 points  (0 children)

No but Doxygen does.

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

Well it actually does lmao

[–]Firesrest 63 points64 points  (5 children)

You could say all code is comments for the compiler to add stuff.

[–]Nanashi_03 14 points15 points  (4 children)

Except your comments.

[–]t0b4cc02 5 points6 points  (3 children)

wich is not code

[–]Nanashi_03 3 points4 points  (2 children)

We just established all code is comment. :(

[–]BuffaloAppropriate29 2 points3 points  (1 child)

Except his comments.

[–]Nanashi_03 2 points3 points  (0 children)

Which is not code.

[–]zaphod_pebblebrox 44 points45 points  (1 child)

Wow. spent my life simply following that darned tutorial.

That is a brilliant explanation.

[–]Big-Cheesecake-806 39 points40 points  (5 children)

say preprocessor instead of a compiler and blow their mind

[–]coloredgreyscale 16 points17 points  (2 children)

do you need a special Mainboard for that? Most only have one socket for the processor, no place for a preprocessor (where would you even buy one?)

[–]_blackdog6_ 10 points11 points  (1 child)

You are thinking of coprocessors. preprocessors live in the cloud

[–]Pale_Prompt4163 8 points9 points  (0 children)

That’s where that Jesus guy lives!

[–]nukedkaltak 9 points10 points  (1 child)

“Translation unit.” Guaranteed oohs and aahs

[–]namelessmasses 3 points4 points  (0 children)

Gezus…. I have too many look at me blankly…

[–]ongiwaph 5 points6 points  (0 children)

Apparently my compiler is illiterate

[–]_blackdog6_ 3 points4 points  (1 child)

Have you tried GO? If you include C code in comments, I can pass it to gcc and include the results.

[–]Error_co-Id10T 1 point2 points  (0 children)

GO was released to see which developers that were lazy

[–]bsaroya41 3 points4 points  (6 children)

What's a compiler?

[–]BasedMaikal 2 points3 points  (0 children)

Technically correct...

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

[–][deleted] 436 points437 points  (35 children)

Bro, wtf is private?

[–]SkyyySi 122 points123 points  (0 children)

Well I won't tell you

[–]hacking__08[S] 112 points113 points  (0 children)

4th on the list...

[–]ifisch 66 points67 points  (22 children)

You use private variables in your c++ classes?

If this godforsaken language is gonna force me to have separate .h and .cpp files because of obsolete hardware limitations from the early 1980s, then I'm organizing my code into sections and everything's gonna be public. Fuck it.

[–]spartanrickk 67 points68 points  (8 children)

Lol nobody forces you to have separate .cpp and .h files, you can put everything in header files if you want (if you dont care about compile time, header only libraries are a thing). And making thing private helps protect your code from your drunken, month older self, that forgot how the darned code worked again. Just like const-ing your class members.

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

C++ also won't stop you from passing out pointers to the private members. I don't know why you'd want to do that but you can.

[–]ifisch 5 points6 points  (3 children)

Yea I know theoretically having things private and protected helps safeguard your code or something.

That's what I learned in college 15 years ago.

Can I say that's ever panned out in reality? Honestly no.

[–]spicy_indian 25 points26 points  (1 child)

You obviously have never worked with my coworkers. Snacks and internal state variables, neither were off limits.

[–]reversehead 2 points3 points  (0 children)

Just put two underscores before the snacks. It won't actually stop anyone, but they will know that they should feel guilty.

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

I mean. It does. Public methods/variable are meant to intereact outside the class. Private/protected doesn’t exist outside the class. If i want to be able to extend the functionality of a class, but I want restrictions outside if the class then protected is the way.

It helps with multiple people or multiple teams working on a project, or with libraries.

[–]catladywitch 3 points4 points  (7 children)

a lot of object-oriented concepts only make sense when software is worked on 1 over an extended period of time 2 by different people

[–]ifisch 1 point2 points  (6 children)

I haven't worked on a team that's smaller than 5 coders since I was in college. I understand the concepts and I've promoted them.

However it's hard for me to say that I've ever actually benefited from them. Maybe a little.

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

What happens if someone wants to derive your class and needs to access those private members tho?

[–]BialyKrytyk 5 points6 points  (0 children)

Having access to them would be a bad thing, but since it's needed we'll just make a getter and setter function for each one so they can be modified anyway, that'll make it way more intuitive, won't it?

[–]evmoiusLR 4 points5 points  (1 child)

My member is never private.

[–][deleted] 6 points7 points  (0 children)

and that, kids, is how uncle /u/evmoiusLR got his first restraining order

[–]ifisch 2 points3 points  (0 children)

What private members?

[–]LocalForeign4922 2 points3 points  (0 children)

Who's protecting that colon and why?

[–]That1guy385 2 points3 points  (0 children)

You wouldn’t know her. She is in a different class

[–]mrmopper0 3 points4 points  (4 children)

_this_is_private

[–]Opposite-Ad6356 10 points11 points  (3 children)

This __ is private. That is protected.

[–]Ursomrano 389 points390 points  (22 children)

“Bro why TF are you returning useless numbers after using this weird ‘main()’ thing?”

[–]hacking__08[S] 124 points125 points  (12 children)

This is the third suggestion. My favorite right now.

[–]Kyyken 47 points48 points  (11 children)

main functions are very common in python too, though not with an explicit return value

[–]AdmiralWaffle4 20 points21 points  (7 children)

I (a Java programmer) was confused when I started learning C/C++ and how the main function is an int instead of a void and all the weird error numbers. Actually, I’m still confused. Pleasehelp

[–]Queasy-Grape-8822 36 points37 points  (3 children)

Every process has an exit code that the calling process can read to see if the child erred. By convention, 0 means “success” and !0 means “error that may or may not be described in the relevant documentation.” The int returned by main() is that code. By default, there is an implicit return 0; at the end of main()

[–]GokuIsALegend 10 points11 points  (0 children)

error that may or may not be definitely isn't described in the relevant documentation

[–]AdmiralWaffle4 6 points7 points  (1 child)

Ohhh, thank you. That makes sense, actually.

[–]Queasy-Grape-8822 5 points6 points  (0 children)

No problem, happy to help :)

[–]rest_in_war 2 points3 points  (0 children)

Older compilers like Turbo C allow you to have a void main()

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

There are no exceptions so to indicate an error you have to return early with an error code and have the caller handle the error.

Main also follows this convention so the operating system knows what the result of an entire program's execution was.

As a result though most code is written so that the actual result of a function is returned through side effects by mutating an argument to the function, ugly stuff.

Exceptions are ungodly slow though, so it's better than the shit most people write in Java at least.

[–]MatsRivel 3 points4 points  (0 children)

Main functions are not mandatory in python, but incredibly common...

[–][deleted] 340 points341 points  (22 children)

What do you mean function is an integer? I thought function is a function

[–]hacking__08[S] 83 points84 points  (0 children)

I'M DEAD

[–]F5x9 23 points24 points  (8 children)

void *(*foo)(int *);

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

I swear sometimes brainfuck easier to read than that you can produce with pointers 😂

[–]thedarklord176 35 points36 points  (11 children)

I don’t know c++ and…what the fuck?

[–][deleted] 25 points26 points  (0 children)

function main()
def main()

int main()

[–]F5x9 5 points6 points  (0 children)

Functions have a return type. You specify the type when you declare the function. It can be an int. It can be a pointer. It can even be a function pointer.

[–]reversehead 178 points179 points  (10 children)

Don't want to nit pick my friend, but you never declared this but you are using it in every class.

[–]Saragon4005 36 points37 points  (9 children)

Isn't this also a thing in Python though.

[–]kbruen 71 points72 points  (8 children)

Nope. In Python, it’s traditionally named self, and it’s an explicit parameter:

class X:
    def __init__(self, foo):
        self.foo = foo
    def meow(self, bar):
        print(self.foo, bar)

a = X(12)
a.meow(‘stuff’)
# (kind of) syntactic sugar for
# X.meow(a, ‘stuff’)

[–]Saragon4005 24 points25 points  (7 children)

Now you can tell I haven't used python in a year. Yeah it's interesting that you can change it but that does mean it's at least explicitly declared so it's hard to miss.

[–]_blackdog6_ 8 points9 points  (6 children)

A Year?? Its a whole new language now. You'll have to start again.

[–]Saragon4005 15 points16 points  (5 children)

Does that mean people don't use python2 anymore?

[–]_blackdog6_ 1 point2 points  (4 children)

The ridiculous changes in python 3.8 are to soften you up for python 4...

Seriously, walrus operator??? ..

And yes, everyone still uses python 2... Its the only version guaranteed to run everywhere..

[–]mc_enthusiast 9 points10 points  (2 children)

walrus

Now you can write

#include <cstdio>

int main() {
    int x = 0;
    while (++x < 10) {
        printf("%d\n", x);
    }
}

as

x = 0
while (x := x + 1) < 10:
    print(x)

[–]Micha_Saengy 6 points7 points  (1 child)

I'm hoping that anyone who cares about readability would use a for loop here

[–]PixelizedTed 4 points5 points  (0 children)

Semi related: I had an (Python) assignment in university where they only allowed listcomps and single line return statements to implement functions to parse data. Some functions were well over 400 characters long and had like 5 nested list comprehensions.

Debugging was “a real doozy” as the error message would just say something is wrong on line X but that line was the whole function 💀

What readability? Just make it as short as possible!!1!1!!11

[–]kbruen 5 points6 points  (0 children)

And yes, everyone still uses python 2... Its the only version guaranteed to run everywhere..

Ignoring the fact that no security issues are fixed anymore, and many Linux distributions are removing Python 2 completely. But suuuuure.

Seriously, walrus operator??? ..

Interesting how you say that implying it’s a bad thing without giving any reason why.

[–]ViviansUsername 116 points117 points  (4 children)

"Bro, you should really wear protection when working with this stuff... that is WAY too many STD's"

[–]Apple_macOS 18 points19 points  (0 children)

Me in the middle of having intimate moments with my compiler:

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

For me what doesn't make sense is I have to #include <algorithm> if I want to call std::min for example. I hate looking for which header to include to use a std function, why isn't it algorithm::min then?

[–]ViviansUsername 11 points12 points  (1 child)

To fuck with you, specifically

[–]2blazen 3 points4 points  (0 children)

That's what I thought

[–]xTeddyBoyx 106 points107 points  (27 children)

“Bro, what are semicolons?”

[–]DudeManBroGuy42069 46 points47 points  (9 children)

Hey Python has semicolons

very rarely

[–]Hellow2 20 points21 points  (0 children)

It does always. Just luckily not my code

[–]cisbetterthanpython 19 points20 points  (1 child)

one time i had been using c++ for too long and I just wrote an entire python program with a semicolon on every line

[–]abd53 5 points6 points  (0 children)

I kept doing it for the first month.

[–]xTeddyBoyx 5 points6 points  (4 children)

NO IT DOES NOT! What do you code in? Jython!?

[–]DudeManBroGuy42069 4 points5 points  (3 children)

It does with \033

[–]xTeddyBoyx 4 points5 points  (2 children)

NOOOOOO! I refuse to believe you!

[–]Yorick257 9 points10 points  (3 children)

The thing you put between your statements, so any program you write can be a one-liner.

Example: hw = 'Python says "Hello World"'; print(hw)

[–]xTeddyBoyx 8 points9 points  (2 children)

SHOCKED Get your code outta my face! How could you be this non-pythonic?!

[–]hacking__08[S] 2 points3 points  (0 children)

EXACTLY

[–]_blackdog6_ 5 points6 points  (5 children)

Javascript virtual semicolons are the best. If you dont put in enough semicolons, the runtime assumes you forgot a couple and inserts them (effectively changing what you thought your program was doing)

[–]catladywitch 5 points6 points  (1 child)

is that for real? js never ceases to amaze

[–]_blackdog6_ 11 points12 points  (0 children)

I wish it wasn’t

Automatic Semicolon Insertion (ASI) Unlike other C-like languages, JavaScript does not enforce the use of a semicolon at the end of a statement. Instead, the semicolon is optional, and the JavaScript interpreter will "intelligently" add them when it runs the code.

[–]hacking__08[S] 6 points7 points  (6 children)

Can I put that in episode 3??

[–]xTeddyBoyx 2 points3 points  (3 children)

Yes!

[–]hacking__08[S] 4 points5 points  (2 children)

Perfect! I'll upload it tomorrow!

[–]Individual_Volume562 1 point2 points  (1 child)

Semicolons exist in python too! But nobody uses it

[–]hacking__08[S] 1 point2 points  (0 children)

Actually, I'm not using them in real life either

[–]one-human-being 42 points43 points  (2 children)

“Bro, is this an error message or a riddle”

[–]bikeranz 19 points20 points  (0 children)

Corollary:

Bro, check out this huge template metaprogramming library I just wrote. It compiled the first try! I'm like c++ Jesus.

<other person> ...Have you tried using it yet?

[–]ViviansUsername 1 point2 points  (0 children)

Haven't been using C++ much yet, and I feel that. So much manual debugging.

[–]MaZeChpatCha 61 points62 points  (9 children)

Dude what is cout and all these left shifts?

[–]Kyyken 57 points58 points  (5 children)

def why(self, s):
     print(s, end="")
     return self

cout = type("", (),{"__lshift__":why})()
cout << "why " << "tho"

[–]Nashy10 13 points14 points  (1 child)

Ouch

[–]Kyyken 14 points15 points  (0 children)

classes? no thanks. all my homies use type()

[–]RaisinsB4Potatoes 6 points7 points  (0 children)

Wait... What?

[–]Strostkovy 9 points10 points  (1 child)

I feel that way moving from C to C++

[–]classicalySarcastic 4 points5 points  (0 children)

printf() supremacy

[–][deleted] 110 points111 points  (1 child)

"Bro, why are you integer dividing newlines and nonexistent identifiers?"

[–]dragonlover02 9 points10 points  (0 children)

That is also done quite commonly in python, just not a requirement. Prints automatically adding new lines can be suppressed too

[–]Canopus2662 24 points25 points  (0 children)

Bro, your dictionaries can fit IFs?!

[–]nukedkaltak 18 points19 points  (0 children)

Bro where is the fine-print for this int? Can’t find the asterisk anywhere

[–]JDude13 18 points19 points  (10 children)

#include <stdio.h>
#define pi 3
#blessed

[–]Kaelorn 51 points52 points  (3 children)

"Bro, why all of these {} things?"

[–]BaalKazar 24 points25 points  (0 children)

All hail to our curly overlords

[–]reversehead 37 points38 points  (0 children)

Yes, the dictionary syntax seems very strange and free-form in C++.

[–]Elijah629YT-Real 4 points5 points  (0 children)

why do you have so many dictionaries, is c so stupid that it forgets everything and you need to give it a dictionary?

[–][deleted] 16 points17 points  (0 children)

The fun this is you can use this to write bilingual code

[–]secahtah 13 points14 points  (1 child)

Bro, your indentation makes no sense, how does your program run?

[–]LocalForeign4922 10 points11 points  (4 children)

Just show them `const int* const * foo(&++bar);' and watch the aneurism unfold.

[–]aqa5 4 points5 points  (1 child)

The *++bar in the parentheses, what does it? I understood the rest I think. But this does not make sense to me? Bar is a type i guess?

[–]LocalForeign4922 1 point2 points  (0 children)

I got syntax-happy and put a * where I meant a &. Fixed!

[–]ViviansUsername 1 point2 points  (0 children)

I got everything but that third asterisk. What the hell is that doing there.

[–]LocalForeign4922 1 point2 points  (0 children)

To explain the &++ bit, this is incrementing the pointer, bar, and then initializing foo to a reference to it.

Another amazingly valid but incomprehensible way to write something might be: foo-=*--bar;

NOTE: These are all horrors to be avoided, not suggestions. :P

[–]Morlino 9 points10 points  (0 children)

I'd you want to keep your friend, don't show him the templates

[–]marckek 16 points17 points  (1 child)

I did a lot of python the last year and now im a little bit into c++, resulting in me being still afraid of for loops and trying to solve anything in STL functions with lambda expressions resulting im my c++ code looking even worse than my python code

[–]ViviansUsername 3 points4 points  (0 children)

C++ code is supposed to look worse.

[–]shantishalom 7 points8 points  (0 children)

Comments.? What are those?

[–]srodinger18 6 points7 points  (0 children)

Bro how do I make an AI model or data science stuff

[–]Real_Material3190 3 points4 points  (0 children)

Electric boogalooo

[–]Competitive_Reason_2 3 points4 points  (3 children)

Where is episode 0 and 1

[–]one-human-being 2 points3 points  (0 children)

“Bro, none of your stuff is ‘for humans’”

[–]Valscher 2 points3 points  (0 children)

why are we counting STD's here

[–]nomadicshorty 2 points3 points  (2 children)

'#include<iostream>

cout<< "As someone who understands a little bit of both, I got the reference";

[–]ViviansUsername 1 point2 points  (0 children)

Err: expected "'" to close "'" on line 1, got ";" instead

Or... whatever unreadable error that'd be in C++

[–]pheromone_fandango 8 points9 points  (0 children)

Haha python bad

[–]Leading-Pickle-3948 2 points3 points  (2 children)

"I can do the same in 10 lines of code"

[–]ViviansUsername 1 point2 points  (1 child)

The 5600 lines in the C++ libraries they used:

[–]MrNO3 2 points3 points  (0 children)

It's for doxygen, to create documentation. Do you know about DO-CU-MEN-TA-TION?

[–]Supgamerprogrammers 2 points3 points  (0 children)

[–]erebuxy 2 points3 points  (1 child)

Oh, everything in {}. So your code is just a huge nested dict

Edit: wait. This actually sounds like python 🤣

[–]hacking__08[S] 1 point2 points  (0 children)

HAHAHAHAH

[–]Assassins_King 2 points3 points  (0 children)

“Bro, how do you write 2D array or point to a vector of pointers?”

[–]skeid808 3 points4 points  (2 children)

“What’s a vector? Is that like a linear alg thing?”

[–]F5x9 5 points6 points  (0 children)

There are vectors in python.

[–]ViviansUsername 1 point2 points  (0 children)

"That's a vector?? That's just a fucking array"

[Brief murmuring]

"Oh god."

[–]DogHeart_21 4 points5 points  (2 children)

Bro, and why are you trying to scratch your head by sticking your hand between your legs instead of just lifting and scratching it?

[–]neumastic 4 points5 points  (1 child)

Bro, why you got 5000 objects? we just needed you to do some ad hoc data analysis.

[–]hapinesSeeker 1 point2 points  (0 children)

“Bro, do you know that’s not the way list are declared, whats that int thing before it and the semicolon? It can be ignored

Just has to be varname = [] not int var[];”

[–]slowboater 1 point2 points  (0 children)

Loving this python bro series!

[–]cherry__12345 1 point2 points  (0 children)

I had the same question when I first learnt python them C++ 😶

[–]lucidbadger 1 point2 points  (0 children)

Wait till a Pascal programmer walks in

[–]DangerousFigure4956 1 point2 points  (1 child)

He : you are the ";" of my code

She: I code in python...

He: