• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 141
  • Last Modified:

Thoughts on "proper" coding

Potentially part 1.
I'm curious what you guys do in 'the real world'.

When you code, do you skip object properties when you're using the default?

For instance:

txtData="My text"


txtData.Text = "My text"

I know it's 6 one way and a 1/2 dozen the other - just looking for what the general consensus is...
3 Solutions
I, personally, never rely on the default properties.  txtData.Text is correct.  In recent updates to the language (VB.NET, for example), default properties no longer exist.  It's also harder to understand, for anyone re-reading your code; referring to txtData suggests you mean the control itself as in:

    Set a = txtData
    a.Text = "My Text"

says 'when I say a, I mean txtData', whereas

    a = txtData.Text

says 'put the text in txtData into a variable called a'.

Just my two cents...


I always use the properties.  IMO, the code is more readable and maintainable.

Also, VB.NET does not support default properties, so migrating code is easier if the properties are already in code.
I always type in the property, even if it is the default.  It's "cleaner" and there is no ambiguity, especially since not all object's have the same default property.
sirbountyAuthor Commented:
Thanx guys. : )
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now