January 26, 2013 Re: @property - take it behind the woodshed and shoot it? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | On Saturday, 26 January 2013 at 13:21:37 UTC, Jacob Carlborg wrote:
>
> It's always possible to avoid keywords in favor of syntax. Example:
>
> Declaring a getter:
>
> int foo {}
>
> Just as a regular function declaration but without the parentheses.
>
> Declaring a setter:
>
> void foo= (int value) {}
>
> Append an equal sign to the function name.
How would you declare a template property? The getter would be ambiguous with a regular function declaration, wouldn't it?
|
January 26, 2013 Re: @property - take it behind the woodshed and shoot it? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nicolas Sicard | On 2013-01-26 16:06, Nicolas Sicard wrote: > How would you declare a template property? The getter would be ambiguous > with a regular function declaration, wouldn't it? Right... didn't think of that. -- /Jacob Carlborg |
January 26, 2013 Re: @property - take it behind the woodshed and shoot it? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | On Saturday, 26 January 2013 at 13:28:46 UTC, Jacob Carlborg wrote:
> On 2013-01-25 19:00, Rob T wrote:
>
>> Why was a partial implementation of an experimental half-backed idea
>> released into the wild?
>
> It seems just to be how things are done in the D community. Another recent example of this is the UDA that popped up and got implemented from nowhere.
That is probably the #1 problem with D.
|
January 26, 2013 Re: @property - take it behind the woodshed and shoot it? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | On Saturday, 26 January 2013 at 13:28:46 UTC, Jacob Carlborg wrote:
> Another recent example of this is the UDA that popped up and got implemented from nowhere.
That design is almost identical to a discussion we had a few months ago about it though; the timing was a surprise, but it wasn't bungled the way @property was.
|
January 26, 2013 Re: @property - take it behind the woodshed and shoot it? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | On 1/26/13 8:21 AM, Jacob Carlborg wrote:
> On 2013-01-25 22:20, Andrei Alexandrescu wrote:
>
>> That's right with the amendment that we're looking for a solution, not
>> pushing one. Even the title of the thread is a question.
>>
>> Clearly properties are good to have. In an ideal world we wouldn't need
>> a keyword for them and we'd have some simple rules for determining
>> property status (especially when it comes to writes). If syntactic help
>> is necessary, so be it. We want to make the language better, not worse.
>
> It's always possible to avoid keywords in favor of syntax. Example:
>
> Declaring a getter:
>
> int foo {}
>
> Just as a regular function declaration but without the parentheses.
>
> Declaring a setter:
>
> void foo= (int value) {}
>
> Append an equal sign to the function name.
This is interesting. I wonder how to make it work for UFCS functions (which _do_ have one argument).
Andrei
|
January 26, 2013 Re: @property - take it behind the woodshed and shoot it? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On Saturday, 26 January 2013 at 16:29:16 UTC, Andrei Alexandrescu wrote:
> On 1/26/13 8:21 AM, Jacob Carlborg wrote:
>> On 2013-01-25 22:20, Andrei Alexandrescu wrote:
>>
>>> That's right with the amendment that we're looking for a solution, not
>>> pushing one. Even the title of the thread is a question.
>>>
>>> Clearly properties are good to have. In an ideal world we wouldn't need
>>> a keyword for them and we'd have some simple rules for determining
>>> property status (especially when it comes to writes). If syntactic help
>>> is necessary, so be it. We want to make the language better, not worse.
>>
>> It's always possible to avoid keywords in favor of syntax. Example:
>>
>> Declaring a getter:
>>
>> int foo {}
>>
>> Just as a regular function declaration but without the parentheses.
>>
>> Declaring a setter:
>>
>> void foo= (int value) {}
>>
>> Append an equal sign to the function name.
>
> This is interesting. I wonder how to make it work for UFCS functions (which _do_ have one argument).
>
I have to say it will get my vote if a way if found to make this UFCS compliant.
|
January 26, 2013 Re: @property - take it behind the woodshed and shoot it? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On 2013-01-26 17:29, Andrei Alexandrescu wrote: > This is interesting. I wonder how to make it work for UFCS functions > (which _do_ have one argument). There's two problems with the getter syntax. 1. How to distinguish a template property from a regular function 2. How to distinguish a property without an implementation from a variable declaration -- /Jacob Carlborg |
January 26, 2013 Re: @property - take it behind the woodshed and shoot it? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | On 2013-01-26 17:26, Adam D. Ruppe wrote: > That design is almost identical to a discussion we had a few months ago > about it though; the timing was a surprise, but it wasn't bungled the > way @property was. Not the syntax. Walter added a two syntaxes one deprecated using brackets and the one we're using now with the at sign and parentheses. -- /Jacob Carlborg |
January 26, 2013 Re: @property - take it behind the woodshed and shoot it? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | On Saturday, 26 January 2013 at 13:21:37 UTC, Jacob Carlborg wrote:
> It's always possible to avoid keywords in favor of syntax. Example:
>
> Declaring a getter:
>
> int foo {}
>
> Just as a regular function declaration but without the parentheses.
>
> Declaring a setter:
>
> void foo= (int value) {}
>
> Append an equal sign to the function name.
This looks nice, but I favor for C# properties.
The root of the issue is that in C/C++/D there is tremendous difference between object types and functions types (which are incompatible) and property is like a bridge between them - I think that is why the feature is demanded.
However in D a property is essentially a function. Few characteristics that are intrinsic to data types are typeof(prop) which is data type for properties and parenthesis-less access. There is no property as a special entity per se.
In C# property and getter/setter are separated, so there is no confusion between data and functions. In D it would look like this:
class A
{
private int i;
@property int foo // may be without @property at all?
{
get { return i; }
set { i = @value; }
}
}
In this solution property is not defined by naming of two separate functions and is independent of any function in general.
|
January 26, 2013 Re: @property - take it behind the woodshed and shoot it? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Maxim Fomin | On Sat, 26 Jan 2013 11:10:20 -0800, Maxim Fomin <maxim@maxim-fomin.ru> wrote: > On Saturday, 26 January 2013 at 13:21:37 UTC, Jacob Carlborg wrote: >> It's always possible to avoid keywords in favor of syntax. Example: >> >> Declaring a getter: >> >> int foo {} >> >> Just as a regular function declaration but without the parentheses. >> >> Declaring a setter: >> >> void foo= (int value) {} >> >> Append an equal sign to the function name. > > This looks nice, but I favor for C# properties. > > The root of the issue is that in C/C++/D there is tremendous difference between object types and functions types (which are incompatible) and property is like a bridge between them - I think that is why the feature is demanded. > > However in D a property is essentially a function. Few characteristics that are intrinsic to data types are typeof(prop) which is data type for properties and parenthesis-less access. There is no property as a special entity per se. > > In C# property and getter/setter are separated, so there is no confusion between data and functions. In D it would look like this: > > class A > { > private int i; > @property int foo // may be without @property at all? > { > get { return i; } > set { i = @value; } > } > } > > In this solution property is not defined by naming of two separate functions and is independent of any function in general. C# does not have a property keyword precisely because get/set are enough for the compiler to determine whether or not it is a property. So this is completely valid C#: class A { private int i; public int foo { get { return i; } set { i = @value; } } } -- Adam Wilson IRC: LightBender Project Coordinator The Horizon Project http://www.thehorizonproject.org/ |
Copyright © 1999-2021 by the D Language Foundation