Am Fri, 25 Jan 2013 00:11:24 +0100 schrieb Timon Gehr <[email protected]>:
> On 01/24/2013 04:45 PM, Johannes Pfau wrote: > > Am Thu, 24 Jan 2013 09:20:44 +0100 > > schrieb Jacob Carlborg <[email protected]>: > > > >> On 2013-01-24 03:02, Nick Sabalausky wrote: > >> > >>> foo.bar() // Perform action > >>> foo.bar // Access data > >> > >> Who says it has to be like this. > >> > > > > .NET guidelines since .NET 1.1 for example: > > > > "In general, methods represent actions and properties represent > > data." (http://msdn.microsoft.com/en-us/library/bzwdh01d%28v=vs.71%29.aspx). > > > > This is not C#. I think I misunderstood the question. If the question was whether the parenthesis mark an action as opposed to data access, then my statement is of course void. (But it's a tradition from C that () mark function calls). I thought he meant properties should be used for data access. This is almost by definition: Java used setX /getX, C# formalized that into properties, D took properties from C#. Properties where always used for data access, if you don't use properties for data access but for other things the whole concept doesn't make sense. So in that case "this is C#". Properties are polymorphic fields, nothing more nothing less. The D implementation is horrible though as you can't do stuff like x.field++. However, how would you implement this without properties and fields: x.value++; //Field or property x.setValue(x.getValue()++); //How ugly... x.setValue(x.getValue++); //Really ugly (optional parentheses func call) You can't allow these rewrites for normal functions, it'll be a disaster and this is why we need properties. And it's also the reason why properties are data: they're fields and fields are data.
