RE: [Cppunit-devel] CppUnit 1.8.0 features...
Brought to you by:
blep
From: Summerwill, B. <BSu...@eu...> - 2001-09-25 13:10:29
|
I personally disagree with lots of these comments, as do lots of other people, whose comments you can see if you follow some of the links from these Wiki pages (see UseConstMemberFunctions and ConstCorrectness). Specifically ... 1. Make all member functions virtual unless there is a compelling need not too. ---------------------------------------------------------------------------- --- I can't agree with this. If you need to subclass something, and override a method, you should make the method virtual _when you need to_. Otherwise it's just a case of YouArentGoingToNeedIt. The code will run slower for no real gain. 2. Make all functions public. ----------------------------- As covered in some of the WikiWeb pages, this actually makes refactoring harder, because it breaks encapsulation. 3. Avoid const on members ------------------------- In my experience, having const-correct members doesn't make refactoring harder. It does restrict your code, but this is in a good way. The compiler is making additional checks that your code is doing what you expect. 4. Have uniform conventions --------------------------- I absolutely agree with this. Following up your comments, Baptiste ... >> 1) avoid pass-by-value or non const reference, prefer pointer >> => allow polymorphism Yes. >> 2) prefer pass-by-value to const reference >> => don't need to had "const" method to object. If the object you're passing to a method isn't const-correct, then you'll obviously need to do this. >> 3) avoid to return const reference, prefer return by value >> => the former make it difficult to change the implementation Not sure I agree with that. I think it probably varies by class. >> 4) never use const method. >> => const is often more an hinderance that help when refactoring. Disagree. I'd urge you to read more fully through all the follow-up comments to Michael's posting before making any changes. What does everyone else think? Cheers, Bob -----Original Message----- From: Baptiste Lepilleur [mailto:gai...@fr...] Sent: 25 September 2001 13:19 To: Cpp Unit Develpment Mailing List Subject: Re: [Cppunit-devel] CppUnit 1.8.0 features... Quoting Volker Boerchers <boe...@we...>: > On Tue, 25 Sep 2001, Baptiste Lepilleur wrote: > > > Quoting Baptiste Lepilleur <bl...@cl...>: > > > > 7) remove consteness on ASSERT_EQUAL. > > I would actually call that one a bug fix. While const is usefull > when > > manipulating value object, it is a strong constraint. Personnaly, I > have taken > > Michael Feather's advice on XP and C++ and don't use const on > reference object > > (object who don't have public copy constructor). This make refactoring > a lot > > easier, but writing assertion_traits black magic :-(. > > Hi Baptiste, > > could you give me a reference on this subject, some online docs or so > - > This advice is new to me. This is part the extreme programming challenges: http://c2.com/cgi/wiki?ExtremeProgrammingChallenge and the more specifically the C++ challenge (the page you're interested in): http://c2.com/cgi/wiki?ExtremeProgrammingChallengeSeven The comment is very short, but my current working rules are: 1) avoid pass-by-value or non const reference, prefer pointer => allow polymorphism 2) prefer pass-by-value to const reference => don't need to had "const" method to object. 3) avoid to return const reference, prefer return by value => the former make it difficult to change the implementation 4) never use const method. => const is often more an hinderance that help when refactoring. I still don't realy know what to do about non const reference. I usually avoid them (so reference are only use as optimisation to pass-by-value), but it sometimes lead to clumsy code (pointer on std::vector)... I still haven't got around using the make everything virtual, but adding the virtuality when needed is not a problem. Part of those rules where inferred from Michael Feather's CppUnit. And we still haven't our refactoring catalog (we have multiple inheritance and template)... Baptiste. > > Thanks and > Thanks for your work on cppunit! > Volker > -- > Volker Boerchers, boe...@we... > > --- Baptiste Lepilleur <gai...@fr...> http://gaiacrtn.free.fr/index.html Language: English, French _______________________________________________ Cppunit-devel mailing list Cpp...@li... https://lists.sourceforge.net/lists/listinfo/cppunit-devel |