Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Public or Private?

Status
Not open for further replies.

gpalmer711

IS-IT--Management
May 11, 2001
2,445
GB
I'm sorry if this is a stupid question and if it has been discussed before, I couldn't find a definitive answer anywhere.

What are the benefits of using Private instead of Public when working with Sub's and Function's?

Are there any extra overheads when using public? Is it bad usage to always use Public in VB?

I always use unique names for Sub's/Function's within a project so a clash of names is not a problem to consider.

TIA for your thoughts

Greg Palmer
Free Software for Adminstrators
 
Hi,

I am not sure about overheads, but it is generally accepted programming practice to avoid using public declerations for anything, be it variables or functions. The reason for this as I see it is that it helps prevent 'spaghetti code', i.e where a function is called from within another module, which then in turns calls another function in another module and so on. This makes the code incredibly difficult to read. In practice it is not feasible to always use private functions, but as far as possible they should be avoided.

What I tend to do is that if I have functionality that I need to use in different functions then I create a new module called COMMON_FUNCTIONS, which contains all the common code I need. Then, if I need to use this code then I simply call the function required and then control will be passed back to my calling function. I am sure there are many better ways to do it, but that is my preferred one.

Hope this helps

Andrew
 
Hi Andrew,
You think along the same lines as myself, I tend to use a specific module for public values etc..

Thanks for your comments.

Greg Palmer
Free Software for Adminstrators
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top