I believe it should be looking at a mechanism which fits in with
everything that exists today. Extension properties are a natural
extension of where we are today - making brackets optional isn't.
No extension properties are not a natural extension for C#. In fact they go
against the C# rule of not allowing parameters to property gets *except* in
the case of indexers, in which case you are required ot use [] and the
property name Item is hidden.
But at the point of *use* they don't take a parameter - they act on an
instance.
You're kidding me right ? The ReadOnly properties can only create a very
narrow predefined set of objects based on the public exposed state of the
object being extended. You certainly could not be adding line items to a
record.
Who said I'd be adding line items to a record? The example Martin
happens to give isn't the only use of fluent interfaces. In many cases
the publicly exposed state is more than enough to get to the next
value.
None that require properties though
Nothing *requires* properties, but that doesn't mean there isn't an
appeal to them. Extension methods aren't *required* but they make code
easier to read.
Well I haven't seen them. I thought if it was a major issue they'd be well
known and well described. If you wish to present soem examples, that'd be
good, it may even further the conversation.
As I suggested, search for them. A search for
"extension properties" "fluent interfaces"
gets interesting hits from people such as Scott Guthrie. For instance,
from:
http://weblogs.asp.net/scottgu/archive/2007/03/13/new-orcas-language-feature-extension-methods.aspx
<quote>
Right now we don't support extension properties. It is something I
know the language teams are considering for the future - but for right
now you can only add methods.
</quote>
So it sounds like it's not exactly far-fetched.
I was commenting about your statement in regards to LINQ not in regards to
Martin's statements, so that wasn't the point at all
Martin was talking about rich fluent interfaces, something which extension
properties in C# would NOT provide.
They would make various situations more readable than they are now.
Martin was talking about modifier methods, which are useful in some
cases but not all. I wouldn't use a property in such cases - but that
doesn't mean there's no value in them.
Extension properties with setters raise a whole heap of issues. It really
is important to step back and look at basic OO principles. They aren't
properties of the object and they could only manipulate existing public
properties. It's fundamentally wrong to present them as properties.
Not necessarily. Suppose something had a Size property, but you only
wanted to change the Width. That ends up being:
foo.Size = new Size (newWidth, foo.Size.Height);
You could easily encapsulate that in extension properties for Height
and Width. Are there potential issues with properties not being
orthogonal? Sometimes - but sometimes it makes life easier, too.
So you think a null reference should have properties ?
If it can have methods, I don't see why it shouldn't have properties.
As you keep pointing out, properties are just wrappers for methods.
What makes it okay for extension methods but not for extension
properties?
OO 101
A method is not claiming to be a property of a non existant
object.
No, it's claiming to be a method acting on a non-existent object. I
don't see why that's any better or worse.
ROFL, now I know you are kidding me. C# hides indexers from you guys
because they don't want you to create properties that take parameters.
Go-on, have a look at what get's compiled and call it from IL
I don't need to - I'm not exactly a C# newbie. But generally, C#
doesn't give you the sort of ambiguity which VB allows. For instance,
you can't do this from C#, thank goodness:
Thread t = new Thread(...);
t.Sleep(1000);
You can in VB, although I understand it was made an optional warning/
error in VB8.
They aren't claiming to be **properties**.
They're just wrappers for methods, right? I really don't see what the
philosophical different is.
So who defines where that state is ? And how does that state get serialized
if it isn't inside the type ? And why don't the getter and setter have the
ability to opt in/opt out of xml serialization after all they are
*properties* ??? (rhetorical
)
All the state is in the existing type. It has to be, because we can't
add state. The extension properties can add more convenient ways of
accessing the same state. As the nature of the state itself hasn't
changed, the existing serialization should work just fine.
What ? So now you are saying that an extension property wouldn't add state ?
Of course it wouldn't - none that wasn't already in the object. Where
could it store that state?
So if you had a setter, then the getter wouldn't return that value ?
Taking the Size example from earlier, the Height extension property
would return the set value because the *existing* Size state of the
object would have changed. The amount of state hasn't changed, just
the ways of accessing it.
Of course not, they are not claiming to be **properties** of the type.
No, they're claiming to be **methods** of the type despite being just
as absent from the type itself.
State. Both the state of the object and the state they represent.
The amount of state held in an instance wouldn't change. Just the ways
of accessing it.
Well today, Vb.NET can have Shared properties that take parameters, so can
already work as extension properties mechanics would require. A languages
such as C# can't see those properties though as it only supports a single
indexer per type as it's support for properties that take parameters. It's
just another issue to consider, that kind of incompatibility versus people
having to use ()
I really don't think it would be a problem. You'd need some C# syntax
to explain to the compiler that you really wanted an extension
property on a particular type, but that's all. The calling code
wouldn't look any different to normal C#.
I suspect we'll have to just agree to differ on this matter - I'm
pretty sure neither of us is actually convincing the other at all.
Jon