Tagged Python

Just to evangelize D a little and increase my code/crap ratio, let's pretend we develop a library in C++ that contains this class:

class SomeMetaVariables {
    public:
    std::string foo;
    bool bar;
};

// ... Somewhere in the client code:
SomeMetaVariables baz;
baz.foo = "foo";
baz.bar = true;

Our library is quite successful and many people are using SomeMetaVariables despite its obvious flaws. Now, say we get many requests for additional functionality, for example: "Make bar true only when foo is set to "foo" and other way arround." "Well, ok." - we say and commit this new version of SomeMetaVariables:

class SomeMetaVariables {
    std::string foo;
    bool bar;

    public:
    std::string getFoo() {
        return foo;
    }

    std::string setFoo(std::string newFoo) {
        foo = newFoo;
        bar = (foo == "foo");
        return foo;
    }

    bool getBar() {
        return bar;
    }

    bool setBar(bool newBar) {
        bar = newBar;
        foo = bar ? "foo" : "";
        return bar;
    }
};

We implemented the requested feature, but SomeMetaVariables' interface has changed... "But why are you mad clients? You asked for it!" - cries the C++ developer.

Continue reading