From: Daniel A. S. <da...@us...> - 2008-07-24 14:21:57
|
Hi Remigiusz, On 24/07/2008, at 16:03, Remigiusz Jan Andrzej Modrzejewski wrote: > I've got a bunch of repeating code blocks currently in Open(). Now, > I would fold this into a macro, to avoid the repeating. But on the > other hand, many people grieve about any macro usage that has more > than one line. What should I do now? I agree it would be nice to do some refactoring to eliminate similar code, in particular the error handling throughout the whole of dtrace.c is very similar and could probably be factored out into a single macro or maybe even into an inline function (with gcc, inline functions are just as fast as macros but cleaner, OTOH I personally have nothing against multiline macros, as long as they are at the top of dtrace.c and not into dtrace.h) if the error checking and handling in Open() were abstracted away, it would certainly make the function easier to read, enough to make other factoring out unnecessary IMO. it should be possible to have a single macro/function that does the error condition checking, calls Tcl_AppendResult(), Tcl_SetErrorCode() (optionally also doing the errnum sprintf) as well as optionally closing and/or deleting the handle. there are also other opportunities for refactoring, e.g. in Dtrace_Init() you could use a static array and call Tcl_CreateObjCommand in a loop instead of repeating the call multiple times, but I would not worry about that type of change too soon... Cheers, Daniel -- ** Daniel A. Steffen ** ** <mailto:da...@us...> ** |