Indentation in CHOOSE CASE

Share this topic:



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, "Unprocessable ls_xxx " + nvl("'" + ls_xxx + "'", "NULL") + "."))
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, "Unprocessable ls_xxx " + nvl("'" + ls_xxx + "'", "NULL") + "."))
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 a 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: 111
Joined: 19 Feb 2013, 20:33

Return to Elegant Code

Who is online

Users browsing this forum: No registered users and 1 guest


Indentation in CHOOSE CASE

Share this topic:


If you think that this site is not too bad, please LIKE it in Facebook. Thanks!





cron
free counters

eXTReMe Tracker