Lately I am interested in refactoring; as I understand it to repartition code 
into smaller subfunctions, there by increasing oversight, re-usability etc. I 
want to propose some code using a template for the variable-section. This is 
useful for refactoring because then you can transplant parts of the function to 
a new functions and simply recall the template in the new function. Using late 
initialization facilitates copy/paste to a new function.

Here is sample-code:
    
    
    template varSection() =
      
      var
        var1st {.inject.}, var2st {.inject.}: string
    
    
    proc newFunc() =
      
      varSection()
      
      var2st = "goodbye"
      echo var2st
    
    
    
    proc someProc() =
      
      varSection()
      
      var1st = "hallo"
      echo var1st
      
      # these are moved to newFunc
      #var2st = "goodbye"
      #echo var2st
      
      newFunc()
    
    
    someProc()
    
    
    
    Run

It worked when I compiled but the variable-section becomes more laborious with 
all the injects.

Questions:

Is there some "inject-all" statement ?

Do you have other ideas on refactoring or code-breakup?

Thanks in advance.

Reply via email to