Microsoft should have simplified properties

  • Thread starter James Allen Bressem
  • Start date
J

James Allen Bressem

If you aare going to change the entire Basic language in a new distribution
the least Microsoft coulds have done for VBers is give us a new simplified
syntax. I have seen many cases in VB.net where they seem to have had "no
insightfullness" into these considerations.



Their implementation of the property for example is gaudy at best:
Property Name(ByVal Value As String) As String
Get
Return m_sName
End Get
Set(ByVal Value As String)
m_sName = Value
End Set
End Property

When it would have been so much more intuitive to simply use the following:

Property Name(ByVal Value As String) As String
Get Return m_sName
Set m_sName = Value
End Property


--
-----------------------------
Name: James Allen Bressem
Phone: (323) 691-4279
Email: (e-mail address removed)
UCOM: http://www.ucom-ism.com
Mirror site: http://www.geocities.com/wizardofwizards
-----------------------------
 
C

Cor

Hi James
When it would have been so much more intuitive to simply use the following:

Property Name(ByVal Value As String) As String
Get Return m_sName
Set m_sName = Value
End Property

A matter of taste, maybe.

I don't like
If a = b then a = c
either

It confuse me always I wish they had never made it posible.

And the IDE makes it automaticly for you.

Just a thought

Cor
 
N

Nice Chap

Well James, your example is very simple. What if there was more than one
line of code in your property ? Lets say you validated the input value
before you set the private variable ??

If you have simple properties and don't like the ugly syntax then I would
suggest that you use 'Fields'.
 
J

Jay B. Harlow [MVP - Outlook]

James,
You do realize that you just defined an indexed property? :)
Property Name(ByVal Value As String) As String

Your sample should be:
Their implementation of the property for example is gaudy at best:
Property Name() As String
Get
Return m_sName
End Get
Set(ByVal Value As String)
m_sName = Value
End Set
End Property

which supports defining an indexed property:
Property Name(ByVal index As Integer) As String
Get
Return m_sName(index)
End Get
Set(ByVal Value As String)
m_sName(index) = Value
End Set
End Property

To support indexed properties the shorted syntax would need to be:
Property Name() As String
Get Return m_sName
Set m_sName = Value
End Property

Where "Value" is a known parameter similiar to how it is in C#.

which allows, defining an indexed property, such as:
Property Name(ByVal index As Integer) As String
Get Return m_sName(index)
Set m_sName(index) = Value
End Property

Of course supporting a short form of a property may lead us to short forms
of Functions & Subs! (Similar to the QBasic DEF FN statement)

Function CalculateTax(Byval income As Decimal) As Decimal = income *
1.10 / .1

Sub DoSomething() = Call SomethingElse()

Of course the short version of the Function may get more use then the short
form of the Sub.

If they do support the short forms, I hope you will agree they need to
continue supporting the long forms! As Cor pointed out there is a short form
of the If statement as well as the long form. And as Nice Chap pointed out
there is a need for the long forms.

Personally I don't think I would ever use the shortened syntax, if it was
available, just like I rarely use the short form of the If statement. I do
however see some marginal benefit in the short form.

I don't remember if C# defined "Value" to be a keyword or not, which is
another consideration in supporting shorted syntax

If you feel strongly about the suggestion, you can always submit something
to MS Wish.

http://register.microsoft.com/mswish/suggestion.asp

BTW: The above statements are not intended to sound as if I am mocking you,
I agree there is some marginal benefit in a short form. Whether the "juice
is worth the squeeze" is a different matter. Is there enough "bang for the
buck" to have the compiler team add short form properties, or should the
team spend their time in other areas, such as generics & overloading
operators? Personally I would prefer generics & overloading operators.

Hope this helps
Jay
 

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