Re: Final properties

From: Date: Tue, 05 Apr 2016 19:09:20 +0000
Subject: Re: Final properties
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to internals+get-92118@lists.php.net to get a copy of this message
Hi Robert, Marco and Chris, now I see your point. Lastly I've found in DZone newsletter about Java putting var and val keywords, interesting is the second which is going to be used in case of immutable "variables" like a "values" (that's where val came from) see here http://openjdk.java.net/jeps/286 at "Syntax Choices" section. Checked C# for such feature and found out that there is something like sealed keyword which prevents from changing reference and also readonly keyword which states for property read only everywhere except class constructor (interesting isn't it?). I also read about "Immutable modifier" discussion and IMHO it looks like it's about time to get such feature. I also agree that final keyword may be not so good choice for immutability, I've checked Scala, Kotlin and Swift about final properties and it looks like there it is used to unable to override property accedentally, and putting additional override (see https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Inheritance.html) section "Overriding" says: "To override a characteristic that would otherwise be inherited, you prefix your overriding definition with the override keyword. Doing so clarifies that you intend to provide an override and have not provided a matching definition by mistake. Overriding by accident can cause unexpected behavior, and any overrides without the override keyword are diagnosed as an error when your code is compiled." Considerring all of that thoughts I think that final keyword in properties declaration whould be awesome with Typed Properties https://wiki.php.net/rfc/typed-properties keeping to not override the Type Hint declaration. I'll try my best to continue implementation of somehow immutable variables as they would be great at ValueObjects impl. The choice for proprietary keyword could be a subject of discuccion. Cheers, -- Michał 2016-04-05 20:08 GMT+02:00 Robert Stoll <php@tutteli.ch>: > Hi Marco, > > > > I am aware of what final means in other languages, it just > > seems that > everyone then needs to translate back and forth > > from final to immutable. > > In addition to that, final has different > meaning in inheritance (re-used keyword), so this adds > > to the confusion for people unfamiliar with the feature. > > I think immutable is also not ideal because to me, it sounds like the > whole object is immutable even though only the property is. I do not know a > better solution than final though > > Cheers, > Robert > > >

« previous php.internals (#92118) next »