[swift-evolution] RFC: didset and willset
Jeremy Pereira
jeremy.j.pereira at googlemail.com
Thu May 19 09:03:16 CDT 2016
> On 18 May 2016, at 21:51, Leonardo Pessoa via swift-evolution <swift-evolution at swift.org> wrote:
>
> I may be wrong but I don't remember any other case of a keyword in
> Swift composed of two or more words,
dynamicType, associatedtype, typealias, privatefile
> so I believe these should be
> exceptions. I would agree best to change these keywords for others
> consisting of only one word but I myself have no suggestion what those
> could be. Otherwise I'd rather keep them as-is.
At some point (I think it was during the bike shedding for associatedtype), somebody declared that camel case for keywords is abhorrent and everybody accepted it without question. Looking back on it, I think that was a mistake. The point of camel case is to help resolve the individual words in an identifier. I don’t see why that shouldn’t also apply to keywords, especially as, in the list above, Apple Mail kept inserting spaces into the ones that weren’t in camel case, which is really annoying.
A better convention might be to put keywords in ALL CAPS like in Algol. << Ducks >>
>
> On 18 May 2016 at 17:38, Michael Peternell via swift-evolution
> <swift-evolution at swift.org> wrote:
>> Hi Erica,
>>
>> "didset" and "willset" are outliers in the general rule that when combining multiple words into an identifier, that you should use camelCase. which rule is more important? I'd like to introduce a third rule: don't fix it if it isn't broken, or more mildly: if in doubt, keep it the way it is. or another one: embrace precedent.. "@IBOutlet" is also not all-lowercase, should it be changed too? I'd say no, because in objc it is called "IBOutlet" as well. Also, for my Apple Mail client, "didset" and "willset" are marked as typos, but "didSet" and "willSet" is okay :)
>>
>> => I vote for "didSet" and "willSet".
>>
>> I think we should be more careful when trying to argue with "consistency". It sounds objective, when in reality it's often very subjective, because Immanuel Kant's imperative is ambiguous ;) there are multiple ways to be consistent. If you are saying that something is inconsistent, you either assert a specific rule of consistency (like "keywords are always lowercase"), or you must argue that there is no general/sane rule under which the individual parts of the system are consistent.
>>
>> And for all the others who want to abolish didSet and willSet completely:
>> NO WAY! they are both useful and I even used them for real code. For example, from code in my bachelors thesis (it's about polygons):
>>
>> public var points: Array<CGPoint> = [] {
>> didSet {
>> _area = nil
>> _centroid = nil
>> }
>> }
>>
>> I want to cache the _area and _centroid of a polygon, because I'm going to use it many many times more often than I change points. I would have to rewrite that code to something like
>>
>> private var _points: Array<CGPoint> = []
>> public var points {
>> get {
>> return _points
>> }
>> set {
>> _area = nil
>> _centroid = nil
>> _points = newValue
>> }
>> }
>>
>> That's not better, and it probably breaks the COW-optimization of the underlying array. (And don't tell me that my design is bad because I use "didSet", I really don't think so.)
>>
>> -Michael
>>
>>> Am 18.05.2016 um 17:09 schrieb Erica Sadun via swift-evolution <swift-evolution at swift.org>:
>>>
>>> didSet and willSet remain outliers in the general rule of conjoined lowercase keywords. Is there any support for bringing these outliers into the fold?
>>>
>>> -- E, going through her "ttd notes" this morning
>>>
>>> _______________________________________________
>>> swift-evolution mailing list
>>> swift-evolution at swift.org
>>> https://lists.swift.org/mailman/listinfo/swift-evolution
>>
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org
>> https://lists.swift.org/mailman/listinfo/swift-evolution
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
More information about the swift-evolution
mailing list