On Thu, Apr 27, 2017 at 7:28 PM, Steven D'Aprano <steve@pearwood.info> wrote:
> In my experience, what Python is lacking is a way to declare attributes
> outside of the constructor. Take a look at how it's done in C#, Swisft, or
> Go.

Since you apparently already know how they do it, how about telling us
(1) how they do it, and (2) *why* they do it?

They make attribure declarations at the class declaration scope be instance attributes. Python makes that kind of declaration class attributes (statics in some other languages).

This is the spec for C#: https://goo.gl/FeBTuy

The reason *why* they do it that way is because declaring instance fields/variables is much more frequent than declaring class ones.
 
> Object attributes outside of the constructor would solve things more
> relevant than the vertical space used when assigning constructor parameters
> to attributes.

Solve which things?

Instance attributes may be defined with or without default values without having to pass them as arguments to or mention them in a constructor.
 
> For example, multiple inheritance is well designed in
> Python, except that it often requires constructors with no parameters,
> which leads to objects with no default attributes.

Can you elaborate?

A class hierarchy in which there is multiple inheritance requires constructors with no arguments. This is typical: https://goo.gl/l54tx7

I don't know which would be the best syntax, but it would be convenient to be able to declare something like:

class A:
    var a = 'a'

And have "a"  be an instance attribute.

--
Juancarlo Añez