Importance of Private/ Importance of type...

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?
LVL 1
RobK6364Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
GrahamSkanConnect With a Mentor RetiredCommented:
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.
0
 
kiranghagConnect With a Mentor Commented:
>>does declaring a variable as Long when it could have been Integer
>>use more memory once my EXE is compiled?
yes..
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.
0
 
mlmccConnect With a Mentor Commented:
>>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.

mlmcc
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
_agj_Connect With a Mentor Commented:
variant types DO use up a lot of memory....use them ONLY when specifically required.

the same goes for long etc.

As for Private/Public...it 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.
0
 
martin_wattsCommented:
>>>>does declaring a variable as Long when it could have been Integer
>>>>use more memory once my EXE is compiled?
>>yes..
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.
0
 
RobK6364Author Commented:
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
0
 
mlmccCommented:
Glad I could help

mlmcc
0
All Courses

From novice to tech pro — start learning today.