Re: cvs commit: squid3/lib MemPool.cc

From: Henrik Nordstrom <henrik@dont-contact.us>
Date: Wed, 23 May 2007 23:21:00 +0200

tor 2007-05-24 klockan 06:58 +1000 skrev Robert Collins:
> On Wed, 2007-05-23 at 22:49 +0200, Henrik Nordstrom wrote:
> >
> > Mem::Init needs to be called via the setUp() method, not from an
> > automatic instantiation constructor..
>
> Actually I spent quite some time making it work correctly without setUp.
> I think manual setup is very annoying and error prone: if we can avoid
> it lets do so.

I disagree.

The initialization should mimic the main program as much as possible. In
squid Mem::Init is called by main(), and setUp() is the closest
equivalence.

Also the two methods is equally manual. Each test needs a list of stuff
to initialize. The only difference is that it's explicitly called by
cppunit and not the compiler. All I did was to remove the static object
which caused the compiler to call the test initialization and moved this
to the test setUp() method instead.

The day Squid is changed to not do manual setup of these things the
tests obviously no longer need (or should) do it either. But that's a
separate question.

Imho doing heavy dependent stuff from static constructors is very
dangerous from the simple fact that you don't know for sure in which
order these is called. It's both link order and compiler dependent, and
for this reason extremely error prone. It's in the area of C++ magics
best avoided. Keep static constructors as simple as possible.

Regards
Henrik

Received on Wed May 23 2007 - 15:21:11 MDT

This archive was generated by hypermail pre-2.1.9 : Fri Jun 01 2007 - 12:00:09 MDT