Forums >> Programming >> RPG Programming >>
Prefixing Procedure Names




Posted:
bvstone

Prefixing Procedure Names

 
Prefixing Procedure Names

Before we go any further I'd like to share another practice I use.

When looking through source code and coming upon a procedure it will be obvious since I always prefix my procedure names with a hash tag (#).  But, in the past few years I've also added a prefix to each procedure name so I know which module or service program it is from.

For example, our first procedure we've written is #getSumInt.  This name is pretty unique as it stands, but what if we start using more generic names like #getValue or #setValue?  Because each module will need to have unique procedure names, that's where the prefix comes in.

Examine the update /COPY source for our module, P.MATH:

 *//////////////////////////////////////////////////////////////*             
 * #math_getSumInt - Return the sum of two integers             *             
 *//////////////////////////////////////////////////////////////*             
D #math_getSumInt...                                                          
D                 PR            10i 0                                         
D  Augend                       10i 0 Const                                   
D  Addend                       10i 0 Const                                   

You'll notice we added a prefix of #math_ to our procedure name.  

The same goes four our module source F.MATH:

H NOMAIN                                                                    
 ****************************************************************           
 * Prototypes                                                   *           
 ****************************************************************           
 /COPY QCOPYSRC,P.MATH                                                      
 *//////////////////////////////////////////////////////////////*           
 * #math_getSumInt - Return the sum of two integers             *           
 *//////////////////////////////////////////////////////////////*           
P #math_getSumInt...                                                        
P                 B                   EXPORT                                
 *--------------------------------------------------------------*           
D #math_getSumInt...                                                        
D                 PI            10i 0                                       
D  Augend                       10i 0 Const                                 
D  Addend                       10i 0 Const                                 
 *--------------------------------------------------------------*           
 /free                                                                      
                                                                            
  return (Augend + Addend);                                                 
                              
 /end-free                    
P #math_getSumInt...          
P                 E           

And finally, our program MATHTEST:

 ****************************************************************      
 * Prototypes                                                          
 ****************************************************************      
 /COPY QCOPYSRC,P.MATH                                                 
 ****************************************************************      
D Sum             S             10i 0                                  
 ****************************************************************      
 /free                                                                 
                                                                       
  Sum = #math_getSumInt(20:21);                                        
                                                                       
  *INLR = *ON;                                                         
 /end-free                                                             

You can choose to do this or not.  But, what I find is when I'm looking through source code and I see a procedure being called, with the appropriate prefix I'll know right away which module or service program it is being called from.

Next, we'll look into creating a Service Program from our module and look into the pros and cons of using Modules or Service Programs.


Last edited 04/03/2015 at 06:34:30


Reply




Copyright 1983-2017 BVSTools
GreenBoard(v3) Powered by the eRPG SDK, MAILTOOL Plus!, GreenTools for Google Apps, jQuery, jQuery UI, BlockUI, CKEditor and running on the IBM i (AKA AS/400, iSeries, System i).