another syntax we don't need (initializers)

Carl Banks imbosol at vt.edu
Mon Dec 9 15:28:04 EST 2002


Jeff Epler wrote:
> Some people might miss C++'s initializers, which are written like
>    class Foo {
>     public:
>        double x;
>        Foo(_x) : x(_x) {}
>    }
> 
> We could add syntax to Python to support something like this:
>    class Foo:
>        def __init__(self, self.x): pass


Initializers exist in C++ only to avoid assignments in the
constructor, and to initialize base classes.  It's a low-readability
hack.

They have no benefit in a language like Python (which does not have
customizable assignment, and can call the base initializer), except as
a minor, and unreadable, shortcut.



-- 
CARL BANKS



More information about the Python-list mailing list