Page 1 of 1

Indentation in CHOOSE CASE

PostPosted: 19 Feb 2013, 22:15
by Ursego
Avoid an unneeded indenting inside of CHOOSE CASE construction.

Speaking about choose case-es, let's mention the rule "Indent code fragments with as few tabs as possible".

*** BAD code: ***

Code: Select all
choose case as_win_name
   case "w_emp"
      // do something
   case "w_dept"
      // do something
   case else
     f_throw(PopulateError(0, "Invalid as_win_name " + IfNull("'" + as_win_name + "'", "NULL") + ". It must be 'w_emp' or 'w_dept'"))
end choose

*** GOOD code: ***

Code: Select all
choose case as_win_name
case "w_emp"
   // do something
case "w_dept"
   // do something
case else
   f_throw(PopulateError(0, "Invalid as_win_name " + IfNull("'" + as_win_name + "'", "NULL") + ". It must be 'w_emp' or 'w_dept'"))
end choose

Logically, the "// do something" line has the same nesting level as if it would appear in an if construction (rather than choose case), so why to use MORE tabs to express the SAME level?

This style is looking unusual, but try it, and you will really enjoy more understandable scripts, especially when choose cases are nested (or mixed with ifs and loops).