Path: utzoo!attcan!uunet!zephyr.ens.tek.com!uw-beaver!rice!cs.utexas.edu!usc!apple!voder!pyramid!leadsv!practic!vlsisj!davidc From: davidc@vlsisj.VLSI.COM (David Chapman) Newsgroups: comp.lang.c++ Subject: Re: f***ing comments -- another pitfall to avoid Message-ID: <15587@vlsisj.VLSI.COM> Date: 31 May 90 00:31:16 GMT References: <1504@trlluna.trl.oz> <69.UUL1.3#5109@pantor.UUCP> <54683@microsoft.UUCP> <0682@sheol.UUCP> <54781@microsoft.UUCP> <31891@sparkyfs.istc.sri.com> <219@taumet.COM> <31914@sparkyfs.istc.sri.com> Reply-To: davidc@vlsisj.UUCP (David Chapman) Organization: VLSI Technology Inc., San Jose, CA Lines: 37 In article <31914@sparkyfs.istc.sri.com> mckenney@perth.itstd.sri.com.UUCP (Paul E. McKenney) writes: >I sympathize with your interpretation of how commentmacro should >be expanded, but I dislike the results, to say the least! The effect >is that the first ``//'' comment encountered throws the rest of the >macro definition away. > >(example macro follows:) >#define DEFINE_notifier(BASECLASS, MODIFIER) \ >... lots of stuff deleted ... \ >class notifier_##BASECLASS##_##MODIFIER##_class; \ >inline int notifier_##BASECLASS##_##MODIFIER##_class::add_recipient( \ > notifiee_##BASECLASS##_##MODIFIER##_class &x \ >... > if (x.next != NULL) \ > { \ > // Added to the list twice, so die. \ >... Examples like this remind me why I hate multi-line macros so much, along with macros that try to do anything more than a simple expression. They're extremely hard to understand and debug. (We've had flamewars here about them, so I won't say any more.) My solutions would be: a) comment an example expansion of the macro, and leave the macro itself without any comments (would make the macro easier to read as well), or b) don't use macros at all and just write the function explicitly for each class type. I can see the need for templates as a language feature, but in its absence you need to worry about code clarity and ease of maintenance. I think that very complicated macros such as this fail both tests. -- David Chapman {known world}!decwrl!vlsisj!fndry!davidc vlsisj!fndry!davidc@decwrl.dec.com