What best practices/principles could help me improve my routine call placement?


I’m trying to change my module’s outline since I feel I’m blocking some reuse possibilities, but I don’t know how to justify it under the lens of good practices/design principles. Keep in mind this is supposed to become a template for this type of module.

My reasoning for the proposed change lies with the possible reuse of the action subroutines whereas I could construct the chg_rec action by simply calling dlt_rec and add_rec. Currently, the reuse of the action routines to compose more complex actions is partially disabled, since I only want one log per action (CHG_REC) and because transaction_recovery would commit the sub-actions independently.

I do believe the better approach would be to have middleware to handle auth, logs, and transaction recovery, but my architecture isn’t there yet, so I would appreciate it if the conversation wouldn’t deviate into that part of the problem without tackling the question directly.

Right now my module outline looks like this (language RPG ILE):

 * Mainline -----------------------------------------------------------------------------------
C                   exsr      first_routine                                                    
C     action        caseq     'ADD_REC'     add_rec
C     action        caseq     'CHG_REC'     chg_rec
C     action        caseq     'DLT_REC'     dlt_rec
C                   cas                     not_recognized
C                   endcs                                 
C                   exsr      last_routine                                                     
 * ADD_REC -----------------------------------------------------------------------------------
C     add_rec      begsr                                                                      
C                   exsr      auth
C                   exsr      start_log                                                        
 * add record logic here...                                                                      
C                   exsr      end_log                                                          
C                   exsr      transaction_recovery
C                   endsr                                                                      
 * CHG_REC -----------------------------------------------------------------------------------
C     chg_rec      begsr                                                                      
C                   exsr      auth
C                   exsr      start_log                                                        
 * chg record logic here...                                                                      
C                   exsr      end_log                                                          
C                   exsr      transaction_recovery
C                   endsr                                                                      
 * DLT_REC -----------------------------------------------------------------------------------
C     dlt_REC      begsr                                                                      
C                   exsr      auth
C                   exsr      start_log                                                        
 * dlt record logic here...                                                                      
C                   exsr      end_log                                                          
C                   exsr      transaction_recovery
C                   endsr                                                                      
 * NOT_RECOGNIZED -----------------------------------------------------------------------------
C     not_recognizedbegsr                                                                      
C                   exsr      auth
C                   exsr      start_log                                                        
 * send error message                                                                          
C                   exsr      end_log                                                          
C                   exsr      transaction_recovery
C                   endsr                                                                      
 * FIRST_ROUTINE ------------------------------------------------------------------------------
C     first_routine begsr                                                                      
 * do some initializations here...                                                             
C                   endsr                                                                      
 * LAST_ROUTINE -------------------------------------------------------------------------------
C     last_routine  begsr                                                                      
 * cleanup if needed here...                                                                   
C                   return                                                                     
C                   endsr                                                                      

Right now my proposal is to move the four repeating subroutines (auth, start_log, end_log and transaction_recovery) to the first_routine and last_routine making them look like the following snippet and clearing up all the other routines.

 * FIRST_ROUTINE ------------------------------------------------------------------------------
C     first_routine begsr                                                                      
 * do some inicializations here...                                                             
C                   exsr      auth
C                   exsr      start_log                                                        
C                   endsr                                                                      
 * LAST_ROUTINE -------------------------------------------------------------------------------
C     last_routine  begsr                                                                      
C                   exsr      end_log                                                          
C                   exsr      transaction_recovery
 * cleanup if needed here...                                                                   
C                   return                                                                     
C                   endsr                                                                      

All modules have the first_routine and last_routine, so that isn’t something I’m adding as part of the proposal.