Thanks for your in-depth response to my original question.
"Joseph M. Newcomer" <firstname.lastname@example.org> wrote in message
I am always offering a contrarian opinion on this: I would NEVER, EVER
a variable to
hold a value except in some extremely rare and estoteric situations
I hardly ever
encounter, so NEVER, EVER is a pretty good characterization of what I
I make all the variables "control" variables which are just ways to name
the control, and
use methods of those variables to extract the data from the control,
GetWindowText, GetCheck, GetCurSel, etc.
I never, ever call UpdateData in a dialog or formview; I think the ONLY
valid times this
is called is when the framework calls them before OnInitDialog or after
OnOK is called,
and 99% of the time, I never use this capability either. I seriously
preach that the
whole DDX mechanism should not be used, EXCEPT for DDX_Control that
variables, and the entire DDV mechanism should be ignored completely, in
intelligent real-time input validation.
I generally react to code that arrives on my desk by removing all these
removing all UpdateData calls, and replacing them with what I consider
sane and robust
code. I allow ONLY control variables to exist.
On Wed, 5 May 2010 14:23:35 -0500, "JCO" <email@example.com> wrote:
I have a general question concerning members of class and assigning the
content. Particularly if I have a class that, for instance has an
If I use the Wizard, I can create a member data of type "Control" or
"Variable". If I choose variable, the wizard does it's thing. Is this
variable simply used as a conduit? Should it be used simply to set my
actual data member that I created manually in my Class? Example.
m_editClientName was created from the Wizard as type variable CString.
m_strClientName was created by me as part of my private class member.
You can tell this was designed by an amateur because UpdateData takes an
argument, true or
false, to indicate the direction of flow. If anything resembling
intelligent design was
used, there would have been methods called ControlsToVariables and
instead of the non-mnemonic 'true' and 'false' options of UpdateData.
can always tell
bad design because it exhibits pathologies like this. I never liked it
when I first
encountered it, because I had already spent over two decades arguing
against this kind of
design (it is hard to use, highly error-prone, and basically sucks)
m_strClientName = m_editClientName; //editbox variable is simply
conduit to set my my actual member
I would use
which makes it obvious what is going on; there is never a chance that
the controls are out-of-sync. There is only one truth, the truth in the
that because I rely on the truth of the control, there is never a need
have the string
value kept in a member variable at all! In fact, it is not at all clear
why you wrote the
B = A:
above, because A already has the value and there is no reason to make a
copy of it in B!
I'm asking the question because sometimes I fill like I'm creating more
variables than really needs to be. So, is it good practice to do it the
shown above? In reality (I just didn't show it), my data is private
use Public "Get" & "Set" statements to get & set the variables. So
the way I've been doing it.
My opinion: if you have n data variables, you have n-too-many variables.
SetClientsName( m_editClientName );
It is not clear why you need to do this inside the implementation. Not
that it is bad,
but if the whole point is to copy a private value to a public value,
questions that should be asked, such as why there is even a private copy
MyClass::SetClientsName ( CString strName )
m_strClentName = strName;
What good does it do to set this name in a variable if the variable is
the control? The whole point of using a setter is that it should
do something to
make this internal copy be the control contents, or the control and the
out-of-sync and if the user types something we are going to have
Note that doing this right is not always easy or straightforward, but
doing it wrong
(UpdateData) is really easy and supported by the framework; so it is
to get wrong.
None of my dialogs have ever been so trivial as to be able to use
example, I want to enable the Dothis button when the edit control is
doesn't have any provision for this.
We really need to have dialogs support the OnUpdateCommandUI mechanism;
but I essentially
do that explicitly with my constraint-based model (see my essay on
management on my MVP Tips site)
Thanks for your response.
Joseph M. Newcomer [MVP]
MVP Tips: http://www.flounder.com/mvp_tips.htm