Hacker News new | ask | show | jobs
by jstimpfle 3155 days ago
Yeah Metaclasses in Python are obviously so powerful and make programs so easy to read, so let's just go ahead and add those as well.

Now we only write

    struct Point {
        int x;
        int y;
    };
to get the oh-so-needed

    class Point {
    private:
        int x;
        int y;
    public:
        Point() =default;
        ~Point() noexcept =default;
        Point(const Point&) =default;
        Point& operator=(const Point&) =default;
        Point(Point&&) =default;
        Point& operator=(const Point&&) =default;
    };
Genius! Almost like 1972 where we wrote the former and that was just fine!
1 comments

You can still write the former and it's just fine.
Except, I need to think the latter?
Not for a Plain Old Data (POD) type. You need to think about the latter if you're manually managing memory or OS resources in your class (which should be rare) or you're trying to optimize performance when you have members that can be moved more cheaply than copied (usually because they manage memory) which should also usually be rare and the result of identifying a performance issue through profiling.