Re: RFC: constructor argument promotion

From: Date: Thu, 08 Aug 2013 11:11:48 +0000
Subject: Re: RFC: constructor argument promotion
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-68435@lists.php.net to get a copy of this message
Am 08.08.2013 12:34 schrieb "Jordi Boggiano" <j.boggiano@seld.be>:
>
> On 08.08.2013 10:34, Leigh wrote:
> > I'm not sure what problem this is really trying to solve, the
boilerplate
> > code you mention is very explicit and it is very clear to the reader
what
> > is being done. Each property documented with its type, purpose and
> > visibility in a common place for easy reference (at the top of the
class).
> > Each property that takes a value from the constructor assigned in the
> > constructor. Very clear.
>
> I for one am pretty tired of writing this boilerplate in every second
> class I write. Using dependency injection you end up having to write a
> LOT of those usually, and constructors typically only contain assignments.
>
> Adding a property means: declaring the property, adding the ctor arg,
> adding the assignment in the ctor. You have to write the property name 4
> times. With this RFC in it'd come down to writing it once, and would
> avoid having undeclared properties because someone forgot.
>
> I am very supportive the idea, although I see that it could be confusing
> to some. Maybe the syntax needs to change, but the overall change is
> much welcome.

The syntax itself i feel is self explaining. You read it and you know whats
going on.

But somehow i feel this is "wrong". Declaring visibility directly in the
arguments? This looks very scary to me. (Maybe only because i've never seen
it before...)

Other reasons against:
Phpdoc generator break
Code completion break
If constructor is not at the beginning never see a var declaration
Auto generation of set/get can be achieved with IDE..so its not much work


Thread (18 messages)

« previous php.internals (#68435) next »