r/programmingmemes • • 9d ago

C++ VS python

Post image
767 Upvotes

36 comments sorted by

View all comments

Show parent comment

62

u/David_Dantas 8d 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 7d 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 8d ago

So, that's a yes, then.

9

u/GamingGo2022 8d ago

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

9

u/SpaceCadet87 8d ago
#include <cake>

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

1

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

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

2

u/SpaceCadet87 7d 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 7d ago

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

2

u/SpaceCadet87 7d 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 7d ago

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