> The typical situation is some functions have exactly the same code (which
> looks like copy-and-paste directly by developers). In my opinion, such lines
> of code should be extracted to an independent function and be shared by two
> functions.
This is always the desired goal, but not always possible because of library
boundaries, dependencies, or there simply not being a suitable place to put the
shared code. Each must be considered on a case-by-case basis.
> Another kind of duplicate code is not intuitive to reduce. For instance,
> comparing the code in nmg_kill_v.c and nmg_move_v.c, the most parts of loop
> body are same except two or three lines. I think it may be proper to add a
> function with function pointer parameter to encapsulate the same parts, and
> the different part depends on the function pointer introduced. Details
> displayed in the attachment (duplicate code.png).
That’s definitely a tricky case you found. You’d have to be careful that the
refactored visitor pattern (your function pointer suggestion is this) would
actually be significantly less code. Once you create the new generic iterator
function, the individualized function pointer callbacks, and proper checks to
ensure argument validity, it could turn into diffidcult code, trading one risk
(duplication complexity) with another (logic or usage complexity).
> Most duplicate code in C++ occurs in the third-party library, such as
> openNURBS and openSceneGraph. May I skip them?
Anything in src/other is not ours to modify. They are provided for download
and complication convenience.
Cheers!
Sean
------------------------------------------------------------------------------
Transform Data into Opportunity.
Accelerate data analysis in your applications with
Intel Data Analytics Acceleration Library.
Click to learn more.
http://pubads.g.doubleclick.net/gampad/clk?id=278785351&iu=/4140
_______________________________________________
BRL-CAD Developer mailing list
brlcad-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/brlcad-devel