Solved

Thoughts on "proper" coding

Posted on 2004-10-12
4
135 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 16

Accepted Solution

by:
jimbobmcgee earned 25 total points
ID: 12288392
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
ID: 12288397
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
ID: 12288435
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
ID: 12288443
Thanx guys. : )
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…

688 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