Importance of Private/ Importance of type...

Posted on 2004-09-02
Last Modified: 2010-05-02
hello experts, this is maybe a juvenile type of question, but here goes...

i'm wondering what the effect of using Private versus Public function has on the compiled EXE... does using Private make the program smaller, or use less memory?  or does using Public when not needed somehow increase the possibilty of the program being hacked... somehow using the program to gain access to something they shouldn't be allowed?

also along the same lines... i'm wondering if declaring your variables as a specific type will effect the efficiency of the program... does declaring everything as varient type use more memory?  does declaring a variable as Long when it could have been Integer use more memory once my EXE is compiled?
Question by:RobK6364
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
LVL 10

Assisted Solution

kiranghag earned 25 total points
ID: 11969740
>>does declaring a variable as Long when it could have been Integer
>>use more memory once my EXE is compiled?
but this will be noticeable only when you use huge number of variables...or larger arrays
long variables require double the space than an integer.
LVL 101

Assisted Solution

mlmcc earned 25 total points
ID: 11970146
>>does using Private make the program smaller, or use less memory?  
I don't think so.  Public and Private have to do with the visibility of the function from other forms or modules.

>>using Public when not needed somehow increase the possibilty of the program being hacked
I don't think so.  Public is really only used by the compiler.  It might if you  provided your program in a library that someone could link in to their program and try to use it but they would still need to know function names and the like.


Assisted Solution

_agj_ earned 25 total points
ID: 11970683
variant types DO use up a lot of memory....use them ONLY when specifically required.

the same goes for long etc.

As for Private/ only affects visibility in code, not the exe efficiency or size.
It might affect it if u are compiling to p-code. But if u compile to native assembly, there is no reason u shud have any difference.

Regarding hack-ability, declaring something as public only makes it callable...which makes it less secure/exposed to the outside world. In that sense, expose as public only your required functions. Everything that is supposd to be 'internal' and 'non-exposed' should be private.
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.


Expert Comment

ID: 11970938
>>>>does declaring a variable as Long when it could have been Integer
>>>>use more memory once my EXE is compiled?
on the other hand, performance wise, using long integers (32 bits wide, "LONG" in VB) is more efficient than using short integers (16 bits wide, "INTEGER" in VB). This is because almost all processors these days are 32 bit, and internally have to convert a 16 bit integer to a 32 bit integer before processing it. Difference in VB is marginal however.
LVL 76

Accepted Solution

GrahamSkan earned 50 total points
ID: 11971027
The reason for having both Private and Public is for the benefit of the programmer. It would be possible to have all your variables (and procedures) declared as Public, but you could easily lose track of what is modifying the value of public variables. So, as a rule of thumb, keep the scope of variables a small as possible, if necessary passing them into procedures as parameters. This does use more resources, but the effect on performance would only be marginal.

I take the same attitude to declaring the type of variables. You can save a bit of time by not declaring them, but if do you declare your variables as their intended type, then you will know sooner when you have made an error. I always have Option Explicit in the Decalarations section of the code. You can ensure that it's put there automatically: Tools/Options..., Editor tab, Require Variable Declaration checkbox.

Author Comment

ID: 11993229
thanks for all the replies... most of my program is "optimized" with the correct declarations..but going back finding and changing things that already work but could be "optimized" would be a pain... so basically i just wanted to get a feel for if that was a very important thing to do...

and although there seem to be some varying opinions, it seems to not be any huge concern as long as my entire program isn't all variant, which it's not.

not sure who to give the points to... so i'll split em up
LVL 101

Expert Comment

ID: 11993573
Glad I could help


Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month9 days, 3 hours left to enroll

617 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