Why are there Properties in D?
Marc Schütz" <schuetzm at gmx.net>
Marc Schütz" <schuetzm at gmx.net>
Sun Feb 16 02:11:50 PST 2014
On Saturday, 15 February 2014 at 15:45:40 UTC, Robin wrote:
> On Friday, 14 February 2014 at 19:24:58 UTC, Marc Schütz wrote:
>> Another example: The `length` property of ranges. It is
>> possible to turn builtin slices (dynamic arrays) into ranges
>> by importing `std.range` or `std.array`. Slices already have a
>> member field `length` by default. Here you have an example
>> where it's impossible to define a method `length()`. With
>> properties, nothing special needs to be done: You can always
>> use `length` without parens, even if it happens to be a method.
>
> Uhm, ... I thought that enum types for variables are determined
> at compiletime and as pure functions aren't affected by
> side-effects and cause no side-effects their result should be
> determinable at compiletime, too.
>
> Couldn't it be possible again if we just add another getter
> method "length()" for the slice's length? Then you would have a
> uniform access as length() instead of length (without parens) if
> you do it analogiously for all other cases. There is just no
> difference in my opinion - the one solution forces an interface
> with parens and the other forces an interface without them.
You can't define a method and a member variable with the same
name.
More information about the Digitalmars-d
mailing list