I find it is very common to have a private field that properties use to hold
there value, like

get{return holder;}set{holder=value;}

Does anyone have opinions regarding making that a part of a language, much
like 'value' is in C#? Of course it would compile to exactly what it
compiles to now. It would just be a shorthand way of doing it manually, much
like what properties do anyway. Of course if you didn't use the keyword
'holder' in either your get or set, nothing would get created
automatically...

I'm writing a compiler to swf bytecode and thinking of putting that in, but
I'm worried I'm missing some of the implications. One issue would be setting
default values. I'm thinking if you didn't want to have a way to assign
defaults right in the language, the compiler could probably grab defaults in
most cases off the first line of the 'get', which would almost always look
like:

if(holder == null) holder = "default";  //(or the ? : equivalent)

At least that would get rid of the overhead that each get with a default
would otherwise have.

On the plus side, a holder keyword would eliminate problems when people take
shortcuts within the class, and call the 'holder' value directly (assuming
that is faster) - and later add more code to the get/set methods that these
direct calls then miss. The compiler would probably have an easier time
inlining those calls when appropriate too.

It would keep properties from being defined in two places, for people who
are more comfortable putting private fields above the class definition.
Default values would always be visible without scrolling.

It also can get weird if you have protected properties - should the 'holder'
value be protected or private? If the holder value is visible, it needs some
kind of m_ prefix (against ms recommended style) to reamain cts compatible,
otherwise identifiers would vary only by case. I understand that is an edge
case, but there are a lot of things about that 'holder' value that are sort
of a gray area, and maybe an official holder value would make these things
better. Or not. Thoughts?

Cheers,
Robin

===================================
This list is hosted by DevelopMentorŪ  http://www.develop.com
NEW! ASP.NET courses you may be interested in:

2 Days of ASP.NET, 29 Sept 2003, in Redmond
http://www.develop.com/courses/2daspdotnet

Guerrilla ASP.NET, 13 Oct 2003, in Boston
http://www.develop.com/courses/gaspdotnet

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to