Keyword suggestion 'Exposes'. (Bill, Jon, Others?)

R

Rory Becker

I was hoping to get the opinion of Bill McCarthy and Jon Skeet ( I do enjoy
their "discussions" :) ) on a suggestion I made to the VBTeam on a new keyword
"Exposes".

I know it's just syntactic sugar but I thought it might be nice all the same
:)

It would work like Extension methods in that 2.0 compatible IL would be generated
and it would not change the runtime requirements but just a new compiler.


My keyword would allow the compression of existing code like

-------------------------------------------------------------
Private MyLabel as Label ' Assume instantiation elsewhere
Public Property LabelText as String
Get
return MyLabel.Text
End Get
Set(Value as String)
MyLabel.Text = Value
End Set
End Property
-------------------------------------------------------------
to
-------------------------------------------------------------
Private MyLabel as Label ' Assume instantiation elsewhere
Property LabelText Exposes MyLabel.Text
-------------------------------------------------------------

Or

-------------------------------------------------------------
Private MyTextBox as TextBox ' Assume instantiation elsewhere
Public Readonly Property Value() as String
Get
return MyTextBox.Text
End Get
End Property
-------------------------------------------------------------
to
-------------------------------------------------------------
Private MyTextBox as TextBox ' Assume instantiation elsewhere
Property Readonly Value Exposes MyTextBox.Text
-------------------------------------------------------------

I have suggested this in many places but have yet to recieve comments on it.

Just interested to know what people think.

I see it as helping reduce the chaff in the creation of composite controls
but it could be used in other situations.

What do you think
 
B

Bill McCarthy

Hi Rory,

I think it's a subset of specifying a backing store. Allowing for a
declarative syntax that provides the specification of various kinds of
backing stores including sparse storage, and properties or fields or
existing fields, as well as just plain old vanilla fields is an interesting
idea. The issue of course would be when does the backing store get
instantiated, and as such should the generated property instantiate the
backing store as needed etc; and this could also be circular which could be
a problem.

As to a name, I don't think "exposes" is the right word as it really "hides"
the backing store. Perhaps "BackedBy" or "BackingStore"

$0.02
 
P

Phill W.

Rory Becker wrote:

------------------------------------------------------------
Public Property LabelText as String
Get
Return MyLabel.Text
End Get
Set(Value as String)
MyLabel.Text = Value
End Set
End Property
to -------------------------------------------------------------
Public Property LabelText Exposes MyLabel.Text
------------------------------------------------------------

It's quick.
It's easy.
It makes for lots of "good stuff" happening with very little code.

I don't like it. :)

My problem with this is that the "Set" routine is where I'd usually put
"filtering" code to prevent rubbish values getting through to the
underlying data store. Although this construct makes exposing things
"easier", it doesn't make for a "safe" run-time environment.

Contrast these two:

(1) The "old-fashioned" way:

Public Property TextBoxSelectionStart() as Integer
Get
Return Text1.SelectionStart
End Get
Set ( value as Integer )
Select Case value
Case 0 To Text1.Text.Length
Text1.SelectionStart = value
End Select
End Set
End Property

(2) Using the suggested "Exposes" keyword

Public Property TextBoxSelectionStart _
Exposes Text1.SelectionStart

.... then ...

object1.TextBoxSelectionStart = -13

Under (1), nothing happens. The TextBox remains perfectly happy and
your code execution continues on its way - which, admittedly, /may/ or
may /not/ be what you want.
Under (2), you can't avoid getting a nice, big, fat ArgumentException
(IIRC). You could, of course, demand that the range-checking code is
duplicated into every single, possible client of your class, which kind
of defeats the point of encapsulation.

Just my tuppence worth ...

HTH,
Phill W.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top