Post by EduardoPost by ralphAs a Public in a Form is converted to a Property, I can see how there
might be more clicks involved in pcode, but nothing measurable in
native compiled code.
I don't know how the compiler works so...
You mean that
Public VariableName as Long
Private mVariableName as Long
Public Property Let VariableName (nValue as Long)
mVariableMane = nValue
End Property
Public Property Get VariableName() as Long
VariableName= mVariableName
End Property
??
Even if it's the same in terms of performance, it's not the same in terms
of lines to be written.
Yes. Both for performance and "lines" of code.
Because all *Public variables* are converted to a Property in a Form
or Class module. Thus the running code is identical whether declared
as a single variable or spelled out as a Property.
[I gave an out to such code running in pcode. But even that may not be
the whole truth. I based that on the fact if one examines the 'pcode'
(opcode or excode) in the VBIDE there is a difference between "typed
in" Properties and the equivalent "default" Properties. It looks like
a tad more "clicks" for the former. However, if you examine compiled
code - you will see little to no difference. Probably should not have
even gone there. I just figured if I left that out and said "no
difference" - someone would call me on it - so I played safe. <g>]
Post by EduardoPost by ralphA Property vs a Global in a .bas module would definitely add clicks,
but there the benefit is often substantial.
Sometimes there are not real benefits.
Many times I wrote with Public variables to make is fast, and a time later I
converted them to properties (for some reason).
A case where I don't see any benefit are the classes used like UDTs. In
those cases public variables are OK.
Sure they are "OK". More than OK - perfectly good code.
The point of my initial post was to point out that neither is or can
be "evil" - simply because they are both the same. Not as to which
style is "better".
"Public VariableName as Long" is simply short-hand for generating a
Property.
Perhaps a better way to think of Public vs Property is to decide if
you want to go with the hidden default or if you want a "code
presence".
There are many situations (including the example you gave) where a
single variable is fine, even to me. The code is simple. Easy to read.
Looks fine. And darn sure saves a ton of typing. <g>
I tend to go with spelling out Properties with a "code presence" for
the following reasons...
1) Typing time is of little consequence to me because I use a variety
of code generators. I mouse-click more than I type, and ponder more
than I click. <g>
2) I like to only code once. I'm there, why not spell it out and be
done with it. <g>
If later on I decide to add validation, make a change to read-only,
etc. The code is already there.
3) I like the fact that during debugging the code stops in the
Property, inside the class or form.
4) Since most of my code is in this style - I don't mind the clutter.
<g>
But note. This is all just my opinion. My comfort zone. My Bennies.
-ralph