The Depository Trust and Clearing Corporation
An email I sent to a co-worker at DTCC containing a discussion on how to convert inline 4Test code to a function.
To: Katie Ackerly/DTCC@DTCC cc: Gerard Sczepura/DTC@DTCC Subject: Coding Techniques
Katie: I use the following procedure when I start coding a new 4Test function.
First, I check to see if I have already written something similar so as to reuse as much code as possible. If not, then I always begin with a scratch test script file. I then put all new code in main ().
Next, I don’t worry so much about variables and such—I just use hardcoded values to get started. This comes in handy when I’m trying to figure out how a built-in 4Test function is working. Speaking of built-in 4Test functions, I usually test drive the built-in functions I plan to use with a sample of real data, just to make sure the functions will do what I expect them to do.
After selecting and testing any 4Test functions I will need, I then begin coding the basic algorithm. That is, I write only the base code to make the function work with a sample of good data. I don’t worry that much about error conditions and data validation and such. I’m doing what is called a proof of concept in this stage to see if what I’m thinking of will really work.
Next, I think of how to code start and stop conditions if I’m using a for or while loop. Then I usually consider data validation and what error messages I want to raise.
When I convince myself that the code really works, I code a function declaration in the same test script file and then I copy, not cut, everything in main () to the new function.
Next, if the function is somewhat simple, I code the function arguments directly; if not then I convert all literals to variables and substitute these in the main body of code. Finally, I code or double-check that the function arguments are correct.
If the function returns a value, I now verify that this value is computed within the main body of code.
After making this conversion from main () to a function, I go back in main () and I code a call to the new function with sample test data to verify the function is still working correctly. I always use valid and invalid data when I’m test driving the function.
As a final clean up step, I comment out all the variables in the function and re-compile the script. I then check all the …is not defined errors and I then go back and uncomment only those variables that were flagged as not defined. All other variables are not used so I delete them and re-compile one last time.
The last step I do is to copy the entire function into the appropriate 4Test Include file. Depending on how difficult the function is to write I may repeat any sequence of the above procedure until I get the thing to work.