osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Style Q: Instance variables defined outside of __init__


On Tuesday, March 20, 2018 at 6:14:34 AM UTC-5, Alister wrote:
> On Tue, 20 Mar 2018 08:52:29 +0000, Steven D'Aprano wrote:
> > On Tue, 20 Mar 2018 02:43:13 -0400, Terry Reedy wrote:
> > 
> > > I think a claim that in all programs all attributes
> > > should be set *in* __init__, as opposed to *during*
> > > initialization, is wrong.  All attribute setting is side-
> > > effect from a functional view (and usually 'bad' to a
> > > functionalist).  There is no reason to not delegate some
> > > of it to sub-init functions when it makes sense to do do.
> > > There is good reason to do so when it makes the code
> > > easier to understand *and test*.
> > 
> > That is really well said Terry, thank you for articulating
> > what I was thinking but couldn't find the words for.
> 
> but why would a functional programmer be programming an OOP
> class?

The question does indeed beg, but we're not allowed to
question mandates form "on high", we are simply required to
follow them.

IOWs, "Do as they _say_, not as logic dictates"