I'd like to add generic code. For an example, look at ranges: their `front` and `empty` must be callable without parens. This makes it possible for some ranges to have a normal member variable `front`, or a static enum member `empty` (which can even be tested for at compile time!), and for others to use methods/UFCS functions instead. Without these, a lot of the generic algorithms in `std.algorithm` would be full of `is(typeof(range.empty)) || is(typeof(range.empty()))`, or similar tests, making them harder to read and get right.
It's true that it hides what happens behind the scenes, but there
are several advantages. Rikki Cattermole already mentioned
instrumentation; more generally, this makes it easy to change
between getter/setter and member variable without modifying all
the use sites.
- Why are there Properties in D? Robin
- Re: Why are there Properties in D? Francesco Cattoglio
- Re: Why are there Properties in D? Rikki Cattermole
- Re: Why are there Properties in D? Casper Færgemand
- Re: Why are there Properties in D? Rikki Cattermole
- Re: Why are there Properties in D? Timon Gehr
- Re: Why are there Properties in D? Daniel Murphy
- Re: Why are there Properties in D? Marc Schütz
- Re: Why are there Properties in D? Marc Schütz
- Re: Why are there Properties in D? Robin
- Re: Why are there Properties in D? Jesse Phillips
- Re: Why are there Properties in D? Robin
- Re: Why are there Properties in ... Marc Schütz
- Re: Why are there Properties... Robin
- Re: Why are there Proper... Marc Schütz
- Re: Why are there Properties in D? Nick Sabalausky
- Re: Why are there Properties in D? Dejan Lekic
