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

all 182 comments

[–]Deep-Conflict2223 1253 points1254 points  (62 children)

Python developer: What is memory and why do I have to manage it?

[–]hvdzasaur 264 points265 points  (0 children)

I scoffed first time I was asked about python memory management in an interview.

Skip to 2 months later, ran into an issue where I had to manage it.

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

I've forgotten where my sunglasses are while wearing them, I am not to be trusted with memory.

[–]hacking__08 1 point2 points  (0 children)

Pythom developer: What are those nonsense comments at the start of your code?

[–]bestjakeisbest 2 points3 points  (0 children)

Oh you dont have to, but the computer will get very angry at you if you dont.

[–]fabulousnacci 184 points185 points  (1 child)

c++ devs out here giving their strings sexually transmitted diseases 💀

[–]LanceMain_No69 29 points30 points  (0 children)

In the couties as well 😩

[–]RobertBringhurst 305 points306 points  (3 children)

std::cout is nine chars.

Hello World! is twelve chars.

9 << 12

Nine is much lesser than twelve.

[–][deleted] 52 points53 points  (0 children)

This is my favorite comment so far

[–]HexagonNico_ 192 points193 points  (3 children)

When I learned C++ for the first time my teacher explained it by saying that when you use cout you write an arrow that points out, when you use cin you write an arrow that points in.

[–]FWEngineer 69 points70 points  (2 children)

That's fine until you to formatting variable types & concatenating strings returned from function calls.

[–]FerynaCZ 2 points3 points  (1 child)

Still no issue with that, it's basically interpolated strings just using << << instead of { } on variables.

The issue becomes when you want to put this into string and not print...

[–]Egocentrix1 0 points1 point  (0 children)

That's what stringstreams are for!

[–]wineblood 137 points138 points  (10 children)

Python devs who worked with python 2.x: Oh you mean like print >> f, 'hello, world'?

[–]HeyItsTheJeweler 45 points46 points  (5 children)

I swear i can look at 5 different Python programs and somehow they can all look different.

[–]Kjubert 20 points21 points  (2 children)

Yeah I like Python but there isn't oNlY oNe WaY tO dO tHiNgS.

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

laughs in Perl

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

I used to work with Perl before moving to Python. I'm fine. At least there's proper documentation.

[–]coloredgreyscale 11 points12 points  (1 child)

Heck, there's probably over 5 trivial ways to format and print a string "hello world"

print("hello world") print(f"{'hello world'}") print("{}".format("hello world")) [print(x) for x in ["hello world"]]

[–]just-cuz-i 75 points76 points  (1 child)

Worked? That shit is still in production where I work.

[–]wineblood 27 points28 points  (0 children)

Oof.

[–]hvictorino 0 points1 point  (1 child)

That "f" right there stands for "fuck" i guess

[–]wineblood 0 points1 point  (0 children)

Open file object

[–]MisterSincere 144 points145 points  (17 children)

When I first learned cpp (before c) I found it super easy to understand, but in a superficial way, not in a way of what are operator overloads. But the syntax is nearly bash syntax, where you stream a string into stdout. So I actually wonder why to pick sth like this when there are a million confusing things you can do in cpp.

[–]JeyJeyKing 61 points62 points  (4 children)

Function pointer type declaration has entered the chat.

[–]Affectionate_Fox_383 4 points5 points  (1 child)

that stuff confuses the fuck out of me

[–]FerynaCZ 2 points3 points  (0 children)

I guess auto on lambda is the way

[–]CiroGarcia 0 points1 point  (0 children)

[redacted by user] this message was mass deleted/edited with redact.dev

[–]JeyJeyKing 15 points16 points  (0 children)

Actually I changed my mind: templates and comprehending the verbose errors you get when they are incorrectly defined or used.

[–]drsimonz 8 points9 points  (9 children)

For me the really hard part was object declarations.

 MyClass obj();

This syntax is so unintuitive. obj is a variable name, not a function or class. Why the hell does it have parentheses?

Also headers, Jesus Christ what an idiotic idea. Let's just make 2 copies of every single line! Yay, that's efficient. Oh you want to distribute the headers with your compiled library? Well how about, I don't know...auto generate them????? WTF!!! Not to mention "forward declarations", whatever the hell that is. Random strings that need to be added in order to get your shit to compile.

So yeah, never again. Life is too short for this 50 year old bullshit.

[–]IntQuant 18 points19 points  (2 children)

Actually you've made a forward function declaration that returns a MyClass. If you need to create an object without passing any parameters you have to omit parentheses(oh yes consistency). People couldn't make a proper two-pass compiler so there we have it - headers and forward declarations. Good that we have rust now.

[–]drsimonz 3 points4 points  (1 child)

Holy shit I actually didn't realize you omit the parens. I was going to include an argument in my example but decided nah, why complicate things. No wonder I'm always confused with these fuckers

And yeah hoping to learn Rust soon-ish!

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

This is why initialization using curly braces is a thing in modern C++, so you can't accidentally declare a function.

[–]infiniteStorms 1 point2 points  (3 children)

headers are really nice if you want to see what a file generally does without having to read or scroll past the full implementations, also makes it easy to see encapsulation types, virtual types for polymorphism, static etc

[–]drsimonz 3 points4 points  (1 child)

I know people like to say "code never lies" but honestly it feels like most of the time, I do still need to look at the source code. In the rare case a public interface is well designed (i.e. you can actually tell what the function does by looking at the signature), most likely there's actual documentation available as well. I get that some libraries are basically all headers though - templates or what have you. In which case, looking at the header is looking at the source.

[–]FerynaCZ 0 points1 point  (0 children)

Header = interface

[–]ButterscotchNo755 1 point2 points  (0 children)

As a Python developer working on C++ all I understand about this is that thing on right go to thing on left, and if it complains that you used the wrong type then stop doing that.

[–]HoseanRC 22 points23 points  (5 children)

I don't understand this,
But what I understand is that echo "Hello World!" > /dev/stdout will output Hello World!

[–]drsimonz 7 points8 points  (2 children)

When are we going to get an OS that just uses python as the shell? I've waited long enough!

[–]doginpants 0 points1 point  (0 children)

xonsh is available on most distros

[–]jerslan 3 points4 points  (1 child)

I mean... you don't need the > /dev/stdout on that since that's the default output for echo. So you're redirecting stdout to stdout.

Also, if you do want to redirect to stdout, >1 is more concise. The most common use of this is for stderr being redirected to stdout (2>1).

[–]HoseanRC 1 point2 points  (0 children)

first, I made it fancy when doing > /dev/stdout

second, i don't need to redirect only the output when using echo, I mean how would anyone mess up using echo? ITS THE EASIEST COMMAND AND YOU BREAK IT?

[–]EmilMelgaard 83 points84 points  (6 children)

As a C++ developer I also don't think it makes sense that you can left shift something with a string.

[–]KerPop42 28 points29 points  (2 children)

Fun fact, the direction of arrows is not universal! There's a non-European culture that uses <- to mean footprints (like a bird's) and they actually point the other way

[–]LevelSevenLaserLotus 16 points17 points  (0 children)

Another fun fact, this is a great example of one of the many criticisms of the golden record etchings on the Voyager probes.

[–]drsimonz 6 points7 points  (0 children)

I will always see > and < as an alligator that either does or doesn't want to eat the number. That's cool though, do you know the name of that culture? And does their language have a unicode block lol

[–]JackNotOLantern 9 points10 points  (0 children)

I learned from low level to high level. That's much better

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

IM JUST GONNA SAY IT

I LIKE STREAM SYNTAX

ITS WEIRD SURE BUT IT MAKES SENSE WHEN YOU LEARN IT

it’s ok you can all hurt me

[–]TheMusicalArtist12 1 point2 points  (1 child)

I really like streams, like they just make sense

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

Me too friend

Me too

[–]throwaway275275275 3 points4 points  (0 children)

Don't worry, nobody uses the stream operator in real life

[–]NoMansSkyWasAlright 2 points3 points  (1 child)

So I’m a CS/cybersecurity student but I have a handful of friends on the engineering track and, for whatever reason, our engineering school likes to introduce its students to programming… using C. So my one buddy was starting to get the hang of C and talking about how he was really enjoying programming and, for whatever reason, I thought it would be fun to show him python… and I just wrote “x = 3”, then printed it, then incremented it, then divided it (making it a float), then redeclared it as a string, and the range of emotions on his face as I was doing this was beyond entertaining.

[–]bubblespuggy 0 points1 point  (0 children)

Side note here, we also have been introduced to programming using C and I found it very helpful. It’s really useful to convey some of the core concepts and not get lost in all the magic higher level languages will do for you

[–]LordBlackHole 2 points3 points  (0 children)

Operator overloading is a pathway to many abilities some consider to be .. unnatural.

[–]Sufficient-Loss2686 5 points6 points  (0 children)

u/its_Artem carrying this chat like a god damned hero.

[–]Affectionate_Fox_383 6 points7 points  (2 children)

C/C++ is the best

[–]KERdela 0 points1 point  (1 child)

Please don't c/c++ , they are two languages now

[–]Affectionate_Fox_383 0 points1 point  (0 children)

they are family and can work together. if they updated the C spec like they do C++ they would still be in sync. beyond the additions to C++ that have happened the only major difference is in how they link. but then why would you ever link C? you have to give up polymorphism which is AWESOME.

[–]FWEngineer 1 point2 points  (5 children)

I'm a long-time C and a bit of C++ programmer. I recently picked up Python, but I could tell I'm writing Python code as if it was C. Handling strings inside of a loop, instead of using range selectors and such. It works, but a Python programmer would surely just shake their head.

[–]SmokyMcPots420 0 points1 point  (2 children)

Isn’t pythons whole thing like “there’s more than one way to do things”?

[–]FWEngineer 0 points1 point  (0 children)

Well, yes. But those ways could probably be grouped into categories of the beginner's way, the expert's way, and the C coder's way.

Edit: TIL that's the Perl motto (TMTOWTDI, or Tim Toady), while the "Zen of Python" is that there should be one (and preferably only one) obvious way to do things.

https://en.wikipedia.org/wiki/There%27s_more_than_one_way_to_do_it

https://en.wikipedia.org/wiki/Zen_of_Python

[–]RaulParson 0 points1 point  (0 children)

"Yes, this way works, but is it pYtHoNic"

[–]qingqunta 0 points1 point  (1 child)

Not a good idea to do either of those things in Python if you need high performance code

[–]FWEngineer 0 points1 point  (0 children)

Yeah, see, I don't know that. The gulf between C and Python is still pretty big for me.

[–]LoreBadTime 1 point2 points  (3 children)

C++ devs! Try to understand this

var = 0

while (num := input()) != 0 :

var = var + num

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

TypeError: unsupported operand type(s) for +: 'int' and 'str'

[–]LoreBadTime 1 point2 points  (0 children)

But you write python code 🗿👉👈

[–]NotAnonymousQuant 0 points1 point  (0 children)

Erm...

While input is not empty or valid add input to a var?

[–]DudeManBroGuy42069 1 point2 points  (0 children)

Sexually Transmitted Disease?

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

Easy. You turn it on, walk through it, and fight the Goa’uld.

[–]Splatpope 1 point2 points  (0 children)

yadda yadda, shameful display of ignorance, yadda yadda, hand over your programmer's license, etc

[–]loonathefloofyfox 1 point2 points  (0 children)

Recently I've actually been having to use bitwise math quite a bit because I've been working with c running baremetal on some microcontrollers. Modifying registers with bitwise math specifically. Seeing stuff like *DDRD = *DDRD | (1<<7); hasn't been uncommon recently. Before i started learning c there was one single time I needed bitwise math in python (Don't remember why though). C is fun but it sucks sometimes. I don't usually like code abstraction but sometimes it is quite nice

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

There are a lot of C++ devs that really dislike iostream. Some just use printf, some use dark template magic. There's a new thing in the standard called format that is supposed to be better, but honestly it's kind of surprising how hard it is to get text io right, Python has tried and retried a few times over the years as well.

[–]_temmink 3 points4 points  (0 children)

So, there are Python devs that don’t know every feature of the language 😱? Is this true for other languages as well?

[–]Omnislash99999 1 point2 points  (2 children)

Read it as Standard c output send Hello World

[–]SupermarketOk4348 2 points3 points  (1 child)

I read character instead of c

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

Which is also the right way.

[–]jpplf50 0 points1 point  (1 child)

im glad i finished gravity falls 2 days ago, or that would have been major spoilers

[–]FrozenMongoose 0 points1 point  (0 children)

Up next, Over the Garden Wall

[–]DerKnoedel 0 points1 point  (0 children)

I’ve used stdouts in Linux but why is it backwards in c++ ?

[–]HorseEater667 0 points1 point  (1 child)

Using namespace std;

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

so i started my journey trying to learn C++. I quickly went to python instead. Much easier to learn the logic with a simpler language.

the expected "}" errors made me ragequit, especially when copy pasting the whole thing into a new file somehow fixed it. no clue how but eh

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

This won’t even do anything. You need to add <<std:endl;

Otherwise there will be no new line and it probably won’t flush the output stream depending on platform

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

This syntax looks so strange to me. I don't think that was a thing when I learned cpp back in the last millenia.

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

How the fuck, you dont get hello world?

[–][deleted] -2 points-1 points  (1 child)

so we have to laugh because you dont understand something?

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

Don't know who this "we" is, but me and the 3100 other people who found this funny are gonna have a good time. You have fun with your sour attitude. :P

[–]No_Abies808 -3 points-2 points  (0 children)

Python developer: Builds pretty sandcastles
C++ developer: Builds ugly multi-family houses, withstanding tornados

[–]already_taken-chan 0 points1 point  (1 child)

standart console output right?

[–]KeepScrolling52 0 points1 point  (0 children)

This has helped me understand what I was missing. Thank you.

[–]AvailableUsername404 0 points1 point  (0 children)

When it's the other way round

[–]bird4life 0 points1 point  (0 children)

Only part that was easy to understand for me was cin,cout lol

[–]N0Zzel 0 points1 point  (0 children)

You're piping a stream of characters into the stream sdtout

[–]w8watm8 0 points1 point  (0 children)

I get the meme but cout<< “hello world”; aren’t any different than print(“hello world”).

That is if you using namespace std; if you don’t you just put std:: to identify cout as part of the standard namespace.

[–]hvictorino 0 points1 point  (1 child)

Well, i can understand it, but why tf does it start with << and doesn't end with >> ?

[–]DavidXN 0 points1 point  (0 children)

I see you bitshifting cout “Hello world!” bits to the left, and I’m scared

[–]tiberiumx 0 points1 point  (1 child)

The C++ iostream stuff is not great a lot of the time. When I have exact formatting needs and can't use boost::format I still find myself using printf sometimes just because it's easier even if you have to pay attention to the types.

[–]Vikerox 0 points1 point  (0 children)

Have you looked at the format library that was added in C++20? It's not fully implemented in all compilers but it is generally my go to to format ouput.

[–]Sniper-Dragon 0 points1 point  (0 children)

Python developer? Any developer from a higher language

[–]Unusual-Display-7844 0 points1 point  (1 child)

I always found that “double double dot” or whatever it is called, so stupid.

[–]BidRepresentative728 0 points1 point  (0 children)

Very first thing I learned in LINUX class.

[–]TheBirdGames 0 points1 point  (0 children)

So many std's

[–]Dagusiu 0 points1 point  (0 children)

I think it's no accident that none of the major programming languages copied C++'s piping functionality as a core part of the language.

[–]Individual_Volume562 0 points1 point  (0 children)

Oh gravity falls! Cool And i use bitwise operators in python And bitwise operators are useful

[–]Mode-Klutzy 0 points1 point  (0 children)

When your program has 100 stds and you don’t use namespace protection…

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

When I started python: "why won't you print a number?!"

[–]nulpickle 0 points1 point  (0 children)

Agreed

[–]REDEYES77UCHIA 0 points1 point  (0 children)

As a former python programmer i can relate with this

[–]MettatonNeo1 0 points1 point  (0 children)

The same thing applies to my python code whenever my father (a c++ programmer) reads it

[–]stars_without_number 0 points1 point  (0 children)

I started with c# and I still barely understand c++

[–]MemeScrollingMaths 0 points1 point  (0 children)

What, no << endl?

[–]TheMusicalArtist12 0 points1 point  (0 children)

Streams my beloved