ClarionLive show notes for August 2 2013

I've had to miss several recent webinars, and I also missed the first part of this week's webinar. I joined in around the thirty minute mark where Mike Hanson was talking about the Clarion Smell of the Week: Divergent Change. This included some discussion of code refactoring. 

Feature presentation: Refactoring the TimeSaver templates!

John and Mike had a look through the TSGizmos templates, looking for a suitable refactoring candidate:

Mike began with the AlertKeyManager application extension, and put that extension into its own file to avoid accidentally changing any other template code. 

Mike noted the extension is very long and doesn't use any #Groups. 

Indent the prompts section appropriately for better readability. 

Be careful with blank lines as they may get generated into your source code, especially inside loops.

Use comment lines to separate sections of template code, e.g. at end of prompts section. 

It's very important to properly indent template code. 

Before making any material changes, John suggested making sure the test (Invoice) app would run and that the template would do what it was expected to do. With that out of the way Mike proceeded with some refactoring. 

Not all of the template symbols had descriptive names, which made the template harder to read. Symbols that are internal to the template code can easily be changed, but if you change template prompt symbols then anyone using the template will lose their settings. 

Mike showed how to use #Equate (essentially a #Declare followed by a #Set) to create a local, more appropriately named copy of a template symbol. This needs some care so you don't replace the original symbol but once done it allows you to rename the copy symbols freely. 

Mike also showed how to use #Group structures to make the core of the template more readable. 

When he was done the first page of the template mainly contained #AT statements each with one or more #Insert statements, and gave a nice overview of where the template is generating code.