Re: Check on correctness



You need to do two things to become a better developer:

Never, ever under any circumstances embed assignments in any other
construct. Not in an if, not in a while, and most especially not in an ASSERT.
Embedded assignment is a very poor programming methodology, and serves
little if any useful purpose at any time and should be abandoned as a
programming technique

Never, ever, under any circumstances make any document or view class visible
to a dialog. Dialogs should only work on their own member variables or
structures used for communication and not know about anything else outsdie
themselves.

joe

On 1 Jul 2006 05:21:56 -0700, "tim@xxxxxxxxxxxxxxxxxxxxxx" <tim@xxxxxxxxxxxxxx> wrote:

Thanks for the reply, sheesh what a chump.

Yours...one step closer to being a decent developer.

Tim

www.fruitfruit.com wrote:
I had a problem with CMyView->GetDocument() in release.

Within the constructor of the dialog class, I assigned the attribute,
m_pDoc to the document

ASSERT(m_pDoc = pParent->GetDocument());

In release, my program would throw an exception because m_pDoc was
NULL. I trawled through google, to see this is a common error (also
reading that I should call GetDocument every time rather than assigning
to an attribute).

However, if I assign m_pDoc within the dialog's initialisation list the
attribute is assigned correctly.

CExternalEffectorDlg::CExternalEffectorDlg(CState_SdiView*
pParent,const int AtomIndex)
: CDialog( CExternalEffectorDlg::IDD, pParent ),
m_pDoc( pParent->GetDocument() ),


Is calling a getter in an initialisation list bad practice?

That is due to the fact that ASSERT is ignored in release configuration.
You shall not put initialize code in ASSERT, do it in the following way:
m_pDoc = pParent->GetDocument();
ASSERT(m_pDoc);
This shall work for both Debug and Release.
Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.



Relevant Pages

  • Re: Role Based access control
    ... > Project LeaderAssign developer role to a user for a project ... > A bug goes thru stages like: ... note that you have introduced a new entity relevant to assignments: ... instantiation will ensure that whatever Processes are at the end of the ...
    (comp.object)
  • Re: Help with understanding leveling... MS Project 2003
    ... realized that even very simple work assignments were not being leveled in my ... developer to complete. ... dummy resource would be set to work at 400%. ... if you change duration, units are recalculated. ...
    (microsoft.public.project)
  • Replace resource for all tasks on a project
    ... Sometimes we have a case where one developer leaves a group and will be ... of the remaining work for the old developer to new assignments for the new ... Select the new resource in the Replace dialog and click OK ... This works okay if the old developers does NOT have any completed tasks. ...
    (microsoft.public.project.pro_and_server)
  • Re: assigning variables in e.g. an if ....
    ... It's a short way of writing something and almost any programming ... language allows basic assignments like that. ... produce bigger and better idiots. ... So far, the Universe is winning." ...
    (comp.lang.php)
  • [EGN] Re: Please any one suggest me some project ideas
    ... >> Georgia Tech did something like this to detect cheaters in ... his students' programming style might well ... "hello world" assignments from a first ... Given the abilities of Mr. Nilges demonstrated previously in this ...
    (comp.programming)