Re: Properties
Hi Jon,
I think there is a need to take you literally. Please write what you really mean, literally :)
What are the other benefits? Less error prone means what exactly?
If I can't access the field then I'll have to access the property. I'd rather have the flexibility to avoid properties that perform
error checking or examine the state of the object, for example. Those properties are used quite often in my coding experience.
i.e., Properties that are useful ;)
So the only benefit so far is consistancy, and no longer error reduction or less code?
So, what does consistancy mean exactly?
Could you please clarify this statement?
I disagree with your assumption that properties, commonly, are nothing more than simple field wrappers and that fields, commonly,
are only referenced in properties. And even if the latter was true, then the only way to get the data would be to reference the
property, but then you have to deal with all that "bounds checking", as you say, which can negatively affect performance or produce
undesireable changes in state. I prefer having more options.
I need the features I mentioned. I make fields internal and protected internal in some cases. I also mark them as NonSerializable
from time to time. Sometimes, fields are static.
The "special" case, as I see it, is coding without a need for flexibility.
I think, techincally, it's a less complicated reason. Your idea is meant to help, but it actually hurts instead because it removes
flexibility and leaves something to be desired. And there's always something to be desired!
And just to clarify, I don't think that it's "not worth doing" because it might not be worth the effort. I think it won't add any
value at all.
I'm sure your intentions are good, however :)
Hi Jon,
Theres no need to take me literally. Surely you can see also that it is less error prone(well, atleast for the most part).
If your so worried about typing then just use an @ simple or something to suggest that.
>That is more typing or could potentially be more typing than just:
>private string name; [FIX: "Name"]
>private string name; [FIX: "Name"]
yeah, but I'm not so worry about how much more letters one has to type if the benefits outway it. adding a few more characters are
fine if its clearer and less error prone.
fine if its clearer and less error prone.
Remember, your probably not going to use the .this field out side of the property anyways so it could be less code depending on
how you write it(and you could use a temp variable as an alias for the field property.
how you write it(and you could use a temp variable as an alias for the field property.
>Obviously you will need some mechanism such as ".this", as you suggested, which is going to add at least 1 (probably 2 or more)
>characters each time the hidden field is referenced in code, which happens quite often in my coding practices
>characters each time the hidden field is referenced in code, which happens quite often in my coding practices
error checking or examine the state of the object, for example. Those properties are used quite often in my coding experience.
i.e., Properties that are useful ;)
Well, you mention some good things but I never said you had to give them up(which I mentioned on top).
You can do exactly what you do and it will work. I'm not changing anything but adding to it and what I add doesn't change any
pre-existing syntax or grammar.
You can do exactly what you do and it will work. I'm not changing anything but adding to it and what I add doesn't change any
pre-existing syntax or grammar.
>I understand that you aren't attempting to replace this functionality or remove it, but I like having it at my disposal all the
>time.
>time.
This really just makes it easier and less error prone(not so much error prone as it is consistancy).
So, what does consistancy mean exactly?
if I want to do a quick getter and setter I do not have to create the "explicit" field as one will already be supplied to me. If I
choose to create an explicit field than I can and I can do whatever I want with it as I normally can do.
choose to create an explicit field than I can and I can do whatever I want with it as I normally can do.
>I understand that you aren't attempting to replace this functionality or remove it, but I like having it at my disposal all the
>time.
>time.
Ofcours would could add the ability to do all the things you mentioned in the property itself but then it becomes more ambiguous
and more error prone and one would use the original method.
and more error prone and one would use the original method.
I would imagine that the majority of properties are simply accessors with "bounds" checking and one doesn't really need any of the
features you mentioned and hence my idea would be less ambiguous/error prone and "less" code. But again, in those few times I need
something special I can just use the original C# syntax to get it.
features you mentioned and hence my idea would be less ambiguous/error prone and "less" code. But again, in those few times I need
something special I can just use the original C# syntax to get it.
are only referenced in properties. And even if the latter was true, then the only way to get the data would be to reference the
property, but then you have to deal with all that "bounds checking", as you say, which can negatively affect performance or produce
undesireable changes in state. I prefer having more options.
I need the features I mentioned. I make fields internal and protected internal in some cases. I also mark them as NonSerializable
from time to time. Sometimes, fields are static.
The "special" case, as I see it, is coding without a need for flexibility.
Now the best argument I have heard against it is simply that it might not be worth doing. i.e., its really does not save all that
much. Thats fine and thats a valid argument. I didn't say that it needed to be implemented but was more asking about why it
wasn't as if theres some technical reason. That reason might simply be what I just stated or it could be some more complicated.
much. Thats fine and thats a valid argument. I didn't say that it needed to be implemented but was more asking about why it
wasn't as if theres some technical reason. That reason might simply be what I just stated or it could be some more complicated.
flexibility and leaves something to be desired. And there's always something to be desired!
And just to clarify, I don't think that it's "not worth doing" because it might not be worth the effort. I think it won't add any
value at all.
I'm sure your intentions are good, however :)
Comment