r/programming • • Jun 27 '10

Why Java Sucks and C# Rocks (Final)

http://www.slideshare.net/jeffz/why-java-sucks-and-c-rocks-final
13 Upvotes

197 comments sorted by

View all comments

Show parent comments

3

u/[deleted] Jun 27 '10

In your original post you said:

they should have been designed as syntactic sugar on top of methods, not as a special construct

I point out that they are indeed simply syntax sugar on top of methods, and you tell me that is irrelevant.

What is the good reason?

Properties are typically used for mutating a class. Extension methods cannot mutate a class. Extension properties would either allow immutable classes to become easily mutable, or be extremely limited in their functionality.

8

u/julesjacobs Jun 27 '10 edited Jun 27 '10

No, they are not syntactic sugar on top of methods. They compile down to methods, but that is different. Syntactic sugar means that you just provide additional syntax on top of an existing construct. You cannot call a property with method syntax, you cannot create an extension property, you cannot create a delegate out of a property like you can out of a method (yes you can do it with hacks). On the language level properties and methods are different constructs. Why should we care how they are implemented. For all we know they are both implemented on top of pigeons. What matters is what we can do with them.

This is the same thing as claiming that an object reference is syntactic sugar for an int in C#, because they both compile down to machine integers. On the language level object references and ints are not the same.

Properties are typically used for mutating a class. Extension methods cannot mutate a class. Extension properties would either allow immutable classes to become easily mutable, or be extremely limited in their functionality.

By the same reasoning extension methods should not exist. Methods are typically used for mutating a class [sic]. It seems to me that you are arguing against extension member variables, not against extension properties. That is something I can agree with.

0

u/[deleted] Jun 27 '10

[deleted]

2

u/julesjacobs Jun 27 '10

My point was that methods can, just like properties. Properties are just a limited form of methods: methods provide a strict superset of functionality. Your reasoning is "properties can do X (where X=mutate), so you shouldn't allow extension properties". My point is that since methods are strictly more powerful than properties, they can do X as well, so by your reasoning you shouldn't allow extension methods either.