Here are the last two tips for this series to help you build quick and clean survey questionnaires in mobile survey software.
Include few or no hard coded strings in scripting
In general, scripting should be as compact and clean as possible, and you should avoid putting literal strings in the script. This is for two reasons:
Literal strings make it extremely cumbersome to run a multilingual survey questionnaires as translations need to be hard-coded as well. Note that scripting is never included in translation files, so any survey translations sent to translators from Entryware will not include these strings
Scripts need to be parsed on each client every time they are run. That means if you include an especially long string in your scripting, the mobile devices will need to parse over it character-by-character. With sufficient strings in scripting, this can result in a noticeable slowdown in performance.
It is often safer and more elegant to use dummy categorical type of questions for these literal strings and text piping to accommodate scripted strings.
Simplify conditions used in multiple questions by using flag variables
Sometimes you have a few “classes” of respondent which are asked very specific questions. Rather than create multiple copies of projects or questions, common sense tells you to use scripting in the prequestion of relevant questions to skip past if the respondent doesn’t need to answer the question. This is exactly the correct way to program the survey, but there are shortcuts you can use to reduce large numbers of conditional statements in multiple questions by using flag variables to simplify conditions.
A flag variable, in its simplest form, is a variable you define to have one value until some condition is true, in which case you change the variable's value. It is a variable you can use to control the flow of a function or statement, allowing you to check for certain conditions while your function progresses. The idea is to use the flag variable mainly as a memory of other conditions which the function checks earlier in its execution.
It is easy to see how the amount of scripted logic can snowball when you have multiple preconditions or you need to combine the original logic with additional constraints. By creating a temporary “flag” variable, small bits of logic can be stored and frequently reused. The best place for this is in the postquestion of the last question that affects the logic. The scripting for each of the relevant questions is, obviously, much simpler.
Take care in using flag variables. They can quickly become overly complex if you create too many or don’t use clear names.
Comments for Scripting Survey Questionnaire