Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Thoughts on "proper" coding

Posted on 2004-10-12
4
Medium Priority
?
137 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 100 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 100 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 100 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

604 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