Contributed by Angela Hall, Senior Technical Architect at SAS, (@angelahall1)
The SAS Global Forum Technology Session included the technically funny comedian Don McMillan , who pulled out the #SASGF11 program and stated, very seriously, that there was plenty of comedy material within those pages. He then highlighted the long and windy, the Shakespearian, and the most likely to leave you hungry paper titled ‘Plate of Spaghetti Anyone? Techniques for Learning Existing SAS® Programs’. My friend and co-author Tricia Aanderud was suddenly responsible for making the entire audience wish they'd eaten a bigger, expensive breakfast @CaesarsPalace .
However during Tricia’s presentation, she explained that over time many programmed applications become inflicted with scope creep. (Personally, I think she was very generous with this assessment.) Code can get so entangled it resembles a plate of spaghetti, making it impossible for the observer to see where the same noodle starts and ends or how many noodles there are. This correlation between the title and the method of madness that creates spaghetti code became even more apparent when she opened the talk to the entire audience. Tricia asked attendees to air their own dirty laundry (oh wait, we are talking about food). Included are some of the tips they provided on how to walk through existing processes as well as suggestions on how to better code processes:
- Review the output (or expected result) before walking through the code, this ‘bottom-up’ approach can provide insight into understanding what the prior coder was trying to accomplish.
- Discontinue reusing temporary table names in the program. (This can cause problems for the new programmer to step through the process when they are studying it.)
- Use macro and variable names that make sense. The eight character limit is gone, take advantage of it.
- Comment – Comment – Comment, and it’s all about quality over quantity.
- Build a flow chart, plotting what steps are taken to get from input to output.
- Run the program and analyze the log.
A funny moment was when an attendee admitted sadly that they had used these techniques on one of their own programs to ‘relearn’ it. But it highlighted the fact that everyone can benefit from good programming techniques.
What examples or suggestions do you have for SAS programmers who are creating applications or those that are parsing through and trying to learn previously created code?
By the way, Tricia’s paper also offers a sample mechanism (written in BASE SAS) that trolls through the .sas programs and generates an excel spreadsheet with information on all of the jobs and macros, and gives an analysis of the code. So in spaghetti speak - this offers an initial menu of the types of spaghetti being sold.