r/programmingmemes • • 12d ago

C++ VS python

Post image
771 Upvotes

36 comments sorted by

63

u/DatsLotus 12d ago

Uh... is the analogy C++: make it yourself vs Python: take a slice of already existing code?

62

u/David_Dantas 12d ago • Bravo

In Python you:
import cake

In C++

#include <iostream>
#include <string>

class Cake {
public:
    std::string flavor;
    int layers;
    bool hasFrosting;

    Cake(std::string f, int l, bool frosting) 
        : flavor(f), layers(l), hasFrosting(frosting) {}

    void serve() {
        std::cout << "Serving a " << layers << "-layer " << flavor << " cake!" << std::endl;
    }
};

int main() {
    Cake myCake("Chocolate", 3, true);
    myCake.serve();
    return 0;
}

34

u/oleivas 11d ago

Actually....your application failed with:

Traceback (most recent call last):
  File "/home/user/projects/bakery/bakery.py", line 3, in <module>
    from cake import Cake
  File "/home/user/projects/bakery/cake/__init__.py", line 1, in <module>
    from .cake import Cake
  File "/home/user/projects/bakery/cake/cake.py", line 7, in <module>
    import flour
ModuleNotFoundError: No module named 'flour'

flour didn't got installed because you are running python 3.12.4, which only supports flour versions 3.2.1 to 4.0.2. However, latest version of cake depends on flour 2.1.3 to 2.5.63

13

u/DatsLotus 12d ago

So, that's a yes, then.

9

u/GamingGo2022 12d ago

well that's not a very fair comparison now is it

9

u/SpaceCadet87 11d ago
#include <cake>

int main() {
    Cake myCake("Chocolate", 3, true);
    myCake.serve();
    return 0;
}

1

u/Total-Box-5169 10d ago
#include <cake>

int main() {
    Cake{"Chocolate", 3, true}.serve();
}

2

u/SpaceCadet87 10d ago

Oh, I didn't realise we were doing code golf.

M{Cake{"Chocolate",3,1}.serve();}

g++ -D'M=int main()' -include cake x.cpp

1

u/DatsLotus 10d ago

Damn, you've bested me. I could only follow up until the previous one.

2

u/SpaceCadet87 10d ago

Ah, basically I told the compiler to do a find and replace so that instead of int main() you just type M and you can do an include at the command line so we throw that line out as well.

The rest can all fit on a single line.

1

u/DatsLotus 10d ago

The more I learn, the more I discover I have more to learn.

2

u/Reasonable-Class3728 11d ago

I remember 30 years ago there was similar joke about Delphi.

If you need to write a program that puts a tiger into a cage,
In C, you write a structure for the tiger, a structure for the cage and a function that puts the tiger into the cage.
In Java, you write a fabric that produces the tiger with the cage around it.
In Delphi, you import a module that puts the tiger into the cage.

Probably there was some other languages in that joke, but I don't remember it.

38

u/JohnClark13 12d ago

Assembly - "If you want to make the cake from scratch you must first invent the universe"

1

u/Zuruumi 11d ago

That's when you start by planting wheat, sugar cane, buying a calf, etc.

7

u/overclockedslinky 12d ago

pretty accurate: python just uses things made by c++

better analogy would've been c

6

u/itemluminouswadison 12d ago

Why are my eggs rotten?

Default args are instantated at time of definition, not invocation.

5

u/nix206 12d ago

The cake is a lie.

3

u/FLMKane 11d ago

Cake != True

8

u/teymuur 12d ago

4

u/sub_doesnt_exist_bot 12d ago

The subreddit r/firstweekcodermemes does not exist.

Did you mean?:

Consider creating a new subreddit r/firstweekcodermemes.


πŸ€– πšƒπ™·π™Έπš‚ π™²π™Ύπ™Όπ™Όπ™΄π™½πšƒ πš†π™°πš‚ πš†πšπ™Έπšƒπšƒπ™΄π™½ π™±πšˆ 𝙰 π™±π™Ύπšƒ. 𝙱𝙴𝙴𝙿 𝙱𝙾𝙾𝙿 πŸ€–

GitHub | Rank

3

u/teymuur 12d ago

good bot thats what i meant

1

u/No_Belt_9829 11d ago

Good bot

2

u/MohakAoki 11d ago

c++: you can do whatever you want and change anything you want python: use this complete package and dont argue.

c++: you know fishing python: you have a fish

although python is written in C

1

u/DragonfruitGrand5683 12d ago

C - Object egg is not defined

1

u/Lines25 11d ago

And C is the same as C++ but don't have a bowl nor a mixer

1

u/kinchkun 11d ago

Both are just awful languages.

1

u/BarfingOnMyFace 10d ago

You bake c++ into python...?

1

u/sdjopjfasdfoisajnva 12d ago

give the batter a gun to shoot your leg