Solved

Thoughts on "proper" coding

Posted on 2004-10-12
4
130 Views
Last Modified: 2010-05-02
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"

or

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...
0
Comment
Question by:sirbounty
4 Comments
 
LVL 16

Accepted Solution

by:
jimbobmcgee earned 25 total points
Comment Utility
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...

HTH

J.
0
 
LVL 6

Assisted Solution

by:bkthompson2112
bkthompson2112 earned 25 total points
Comment Utility
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.
0
 
LVL 28

Assisted Solution

by:AzraSound
AzraSound earned 25 total points
Comment Utility
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.
0
 
LVL 67

Author Comment

by:sirbounty
Comment Utility
Thanx guys. : )
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now