Coding Style Conflict, Algorithmic Efficiency vs Repeated Source Code

By Xah Lee. Date: .

Code Optimization Conflict, Algorithmic Efficiency vs Repeated Source Code

here's code

(if PrintCurrentPath
    (mapc (lambda (x)
            (print (format "Validating: %s" x))
            (xah-html-validate-xml-file x t)) xfiles)
  (mapc (lambda (x)
          (xah-html-validate-xml-file x t)) xfiles))

notice the repeated code

so you refactor and it looks nice like this

(mapc
 (lambda (x)
   (if PrintCurrentPath
       (print (format "Validating: %s" x))
     nil)
   (xah-html-validate-xml-file x t)) xfiles)

but now, ur code is less efficient, because it has to check a value thousands of times.

i think this is a example that you can not have both ways, in almost all existing programing languages.

is it possible, to design a programing language feature, so this problem can be solved?