Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
VB.NET General VB.NET discussions for issues that don't fall into other VB.NET forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 1st, 2005, 09:51 AM
Friend of Wrox
 
Join Date: Oct 2003
Location: Albany, NY, USA.
Posts: 218
Thanks: 0
Thanked 0 Times in 0 Posts
Default Curious

Does using a With...End With block give you any performance gains/hits other than making the code more readable?

- - - - - - - - - - - - - - - - - - - - - - -
In God we trust, everything else we test.
 
Old April 1st, 2005, 12:08 PM
Authorized User
 
Join Date: Mar 2004
Location: , , .
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It used to in VB6, but not in .NET.


 
Old April 1st, 2005, 12:10 PM
Friend of Wrox
 
Join Date: Oct 2003
Location: Albany, NY, USA.
Posts: 218
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks!

- - - - - - - - - - - - - - - - - - - - - - -
In God we trust, everything else we test.
 
Old April 1st, 2005, 12:18 PM
Friend of Wrox
 
Join Date: Nov 2004
Location: Port Orchard, WA, USA.
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

No performance gains. When a program is compiled, all object references are converted to means of identifying that make sense only to the machine.
When With ... End With is compiled, all references within the block become specific references; the resultant code is identical to what it would have been if the author had been explicit, rather than using the With ... End With block. (Just to answer the question)

It is the same with using constants. They simplify authoring code, and they reduce the potential for typos (though they propogate a typo in the constant definition to all parts that use the constant).
But when the code is compiled, all constants are replaced with the literal value they are defined as. Compilation is slowed a tad, but the resultant program is byte-for-byte what it would have been if you had typed the literal value everywhere you used the constant.
 
Old April 1st, 2005, 12:22 PM
Friend of Wrox
 
Join Date: Oct 2003
Location: Albany, NY, USA.
Posts: 218
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I appreciate the explanation. It's more helpful to us humans than anything else. I think I'll use it when it helps readability of the source code. Thanks.

- - - - - - - - - - - - - - - - - - - - - - -
In God we trust, everything else we test.
 
Old April 13th, 2005, 10:11 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

In consideration to readability, I personally discourage my own use of this construct because I think it actually makes things less readable. If you have lots of lines that start with "." you may soon lose track of what's before the ".". Particularly if you start nesting them.

Also, when you're debugging, you can't just mouseover the property that's dangling off the ".". If you find yourself using With to avoid a repetition of some complicated code chunk (like "CType(e.Item.Cells(0).Controls(2), Button)") then perhaps a better solution would be to make another variable to house that repeated object.

I'd rather see this:
   objButton.property
   objButton.property
   objButton.property
than this:
   .property
   .property
   .property

I seldom use With aside from a case where i have only a few (<=3) lines that could use it.

-Peter




Similar Threads
Thread Thread Starter Forum Replies Last Post
Curious image map issue... can you help? BananaJim Javascript 2 November 29th, 2006 03:10 PM
curious problem with W3C validator spineynorman HTML Code Clinic 1 April 3rd, 2006 08:20 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.