4 ms·
Adding properties would just make the language MORE complex. Then you would have fields, getters/setters AND properties. That said, a "property" keyword that
by mohaine 10y ago
Adding properties would just make the language MORE complex. Then you would have fields, getters/setters AND properties. That said, a "property" keyword that auto-generated default getters/setters would be nice.
This was one of things that always bothered me about C#, What is the point of properties. What do the offer that public fields don't?
- tigershark 10y agoYou don't need getters and setters in c#. If you don't have any side effect in a read-write property you can just use an automatic property. The same for read only properties that don't need to be recalculated on the fly. And I hope that I don't need to explain why using a write only property is almost always a code smell. In the other cases you can use a normal property with a backing field. If your code is well written and you use the appropriate tools, only rarely you need normal properties (that are as annoying as getters/setters). What do getters and setters offer that public fields don't? Properties offer exactly the same advantage as getters and setters, fields encapsulation https://en.m.wikipedia.org/wiki/Field_encapsulation https://en.m.wikipedia.org/wiki/Field_encapsulation No wonder that you don't understand properties if you don't know why getters and setters are useful.
- krzat 10y agoI prefer Swift's solution, where fields and properties are unified. Makes so much more sense.