Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.

Channels ▼

Paul Kimmel

Dr. Dobb's Bloggers

Automatic Properties in VB 2010: Sanity at Last

May 25, 2010

I heard through the grapevine that there has been some kind of cosmic merging of the VB and C# teams. This is a good thing. There is no credible reason at this point not to have similar capabilities in VB and C#. For the most part .NET development is about syntax and the .NET framework. VB development should not imply limited features and capabilities no matter how individual developers choose to develop in a language.

Evidence that a more sane approach is being taken internal is the correction in Visual Studio/VB 2010 of some absent features. VB Lambda expressions now support sub-Lambdas that don't return a value that can be assigned to the generic delegate Action(Of T)-and automatic properties.

Many times programmers use properties because using properties instead of fields is considered a best practice, and things like grid controls use reflection to bind to properties not fields. The drawback was that most properties simply returned or set the value of the backing field. That is, the property getters and setters didn't have logic in them. With an automatic property:

Public Property Foo As String

The getters, setters, and backing fields are implied. If you use an automatic property it saves some typing. If you use a metaprogramming tool like CodeRush -- which makes code generation much faster -- then an automatic property still eliminates the need to read do-nothing properties. When you use an automatic property just refer to the property both internally and externally instead of the non-present backing field and you are all set.

VB should not mean a limited language. Equity with C# is just fair, and thankfully someone at Microsoft seems to agree with this assertion. To borrow from Alan Cooper, "maybe the inmates aren't totally in charge of the asylum".

VB should have feature equity comparable to C#. Programming with VB or C# should be about syntax preference not access to features. Finally, a more reasoned approach from Microsft for VB developers.

Related Reading

More Insights

Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.