473,789 Members | 2,781 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is C# 2.0 syntax of Properties closed?

I red MSDN article of C# 2.0 this week... and i found
very strange syntax for properties e.g.:

public int MyIntValue {
get {
// ...
}
protected set {
// ...
}
}

.... Is this syntax defined and obligatory?

Maybe it's not only my feeling that aboved syntax is
not a best choice.
Any answer and discussion will be very interesting.

Marcin
Nov 16 '05
23 2074

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Daniel O'Connell [C# MVP] <onyxkirx@--NOSPAM--comcast.net> wrote:
> I think we'll probably have to disagree on this. I think there are just
> so many differences between properties and fields (space and garbage
> collection implications, exceptions, time taken, limitations such as
> ref/out etc) that thinking of them as fields leads to far more
> confusion than thinking of them as syntactic sugar over method calls.
Whereas I consider the field like qualities(Assoc iated get and set, field
like syntax, etc) suggests that they shouldn't be considered as just
syntactic sugar for methods


But those qualities *are* just the syntactic qualities - they're just
easier syntax for calling the methods. In what way *isn't* that
syntactic sugar, albeit very "good" sugar? As you say later on, there's
extra CLR support for properties, but I would say that at least
*nearly* all the stuff that makes them appear field-like is just
syntactic sugar.


I'll agree, with the caveat that a property is there strictly to provide
field like access, which I consider a bit ironic. A property is a set of
methods that exist so that languages can treat them like fields
syntactically
(as a note, I generally consider it bad form to
use a field as a ref or an out, I'd rather use a variable and assign the
field post-method).


Agreed :)
As Frans said in another post in this
thread(paraphra sed), a field is a field, a method a method, and a
property a
property.


And I'd be happy with that - it's when people claim that a property is
more "field-like" than "pair-of-methods-like" that I have problems,
because it's *only* the syntax which is field-like, not the semantics.


In the language, which is what the original post was about at that, syntax
tends to matter a bit more than semantics. In programming the semantics
matter more.
I think its all a matter of where each of us thinks the concept
lies. I doubt any of our idea of what properties are\should be are really
taht different, they just happen to lie on opposite sides of the "ideal
property" line.


Sure.

<snip agreement stuff>
Beyond that, most people probably still don't understand how properties
really work. They know that they compile to 2 methods(In C# and VB
atleast,
thats not really a restriction) prefixed with get_ and set_(although that
isn't strictly required either), but fewer seem to realize that a
property
itself has no accessibility or even that a property is a seperate
metadata
construct which associates those methods(in other words, the methods
themselves do not make up the property, the property references the
methods).


That's fine - the fact that they're compiled to methods is all that I
would particularly urge people to know. The fact that they have
semantics which are very close to methods is important - the rest is
only important to a few people who are either doing low-level stuff or
are just incorrigibly nosy, like ourselves. :)


Being nosy has its perks, ;)
Personally, given the runtime support for properties, to be fully correct
I
would probably be hesitant to call properties syntactic sugar, although
the
compiler does offer sugary syntax for defining them, the concept is baked
into the runtime as properties. The compiler would have to provide
something
to distinguish them, perhaps like the __property keyword in C++.
Yes, there definitely more to it than *just* syntactic sugar -
apologies for the previous over-generalisation. The bits that make them
look like fields are just syntactic sugar though, IMO :)


Yes, that I'll agree on.
--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #21
Jon Skeet [C# MVP] <sk***@pobox.co m> wrote in
news:MP******** *************** *@msnews.micros oft.com:
Daniel O'Connell [C# MVP] <onyxkirx@--NOSPAM--comcast.net> wrote:
> I think we'll probably have to disagree on this. I think there are
> just so many differences between properties and fields (space and
> garbage collection implications, exceptions, time taken, limitations
> such as ref/out etc) that thinking of them as fields leads to far
> more confusion than thinking of them as syntactic sugar over method
> calls.


Whereas I consider the field like qualities(Assoc iated get and set,
field like syntax, etc) suggests that they shouldn't be considered as
just syntactic sugar for methods


But those qualities *are* just the syntactic qualities - they're just
easier syntax for calling the methods. In what way *isn't* that
syntactic sugar, albeit very "good" sugar? As you say later on, there's
extra CLR support for properties, but I would say that at least
*nearly* all the stuff that makes them appear field-like is just
syntactic sugar.


But these syntactic qualities reach very far. You can bind a
collection with object instances of a class with properties to a grid
without having to implement ITypedList to produce custom property
descriptors which call into the methods.

It's easier, but not just 'easier', it helps tremendously in some
areas as the usage of classes in a data-binding scenario can become very
complex (ITypedList is no picknick)

So this sugar tastes really good :) (and is IMHO far less sugar
than, say, foreach)
As Frans said in another post in this
thread(paraphra sed), a field is a field, a method a method, and a
property a property.


And I'd be happy with that - it's when people claim that a property is
more "field-like" than "pair-of-methods-like" that I have problems,
because it's *only* the syntax which is field-like, not the semantics.


Agreed! :)

FB

--
Get LLBLGen Pro, the new O/R mapper for .NET: http://www.llblgen.com
My .NET Blog: http://weblogs.asp.net/fbouma
Microsoft C# MVP
Nov 16 '05 #22
> I don't regard the phrase "syntactic sugar" as derogatory like some
people do, btw. The using(...) statement is syntactic sugar, but
incredibly useful - just like properties. That said, I think it's
important to recognise syntactic sugar for what it is, and know what
lies behind it.

The whole OOP itself (objects, interfaces,virt ual methods..) is just
syntactic sugar. You could do everything by yourself, building your own
vtables and so on.
All higher level programming languages are only syntactical sugar that makes
inputting machine instructions in the computer easier than per hand.

But syntactical sugar is good when it makes the code more readable and
selfexplanory so idea of properties looking like fields is not that bad.
The only problem is that you never know wheather a call to a certain propery
is a simple field access internally or wheather the property most do
expensive calculation to return you the value you want. But the same problem
you would have with an old school getter method so who cares.

--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk
Nov 16 '05 #23
Wow!

I didn't expect that this thread discussion takes so far...
far... from my question.

Really i want to ask You (group) for personal feeling
of new concept of Properties syntax.

My todays "C# code rules" are standing before serious question:
where the new "two accesors" properties would fit?

Marcin

PS: I know that my english is weak... but i can try to
explain any question :)
Nov 16 '05 #24

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

23
391
by: Marcin Grzębski | last post by:
I red MSDN article of C# 2.0 this week... and i found very strange syntax for properties e.g.: public int MyIntValue { get { // ... } protected set { // ... }
0
9666
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10200
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10139
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9020
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7529
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5418
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4093
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2909
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.