Indentation in CHOOSE CASE


Link to this posting

Postby Ursego » 19 Feb 2013, 22:15

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).
User avatar
Ursego
Site Admin
 
Posts: 143
Joined: 19 Feb 2013, 20:33



Ketones are a more high-octane fuel for your brain than glucose. Become a biohacker and upgrade yourself to version 2.0!



cron
Traffic Counter

eXTReMe Tracker