6 ms·
Any time you repeat some block of code twice, you should religiously turn it into a function which is called twice with the same arguments. Any time you call a
by kazinator 10y ago
Any time you repeat some block of code twice, you should religiously turn it into a function which is called twice with the same arguments.
Any time you call a function twice with the same arguments, you should religiously write a two-iteration loop around just one call.
Any time you have more than one two-iteration loop in the same program, you should write a 'dotwice' macro and use that instead.
Any time you have a function call sitting in a loop just for the sake of being repeated, you should avoid the argument expressions being evaluated multiple times; you must religiously evaluate the arguments to temporary variables outside of the loop, and in the looped function call, refer only to the temporaries.
In order not to repeat this pattern itself you need a proper "calltwice" macro, and to be working in Lisp, ideally: (calltwice yourfunc expr ...).
yourfunc and each expr are evaluated once, then the resulting values are applied to the function twice.
This is a DRY town, damn it!