Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Making a case for case


From   "David Elliott" <dcelliott@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Making a case for case
Date   Tue, 6 Feb 2007 14:54:44 -0400

Thank you, Nick, your point on indentation convention is well taken.
I use a tabwidth of only 2 spaces in my editor, a habit I acquired
when writing deeply nested xhtml to prevent exactly the "march off the
right side" of which you speak. Consequently the additional indent on
the else doesn't over-indent my code in practise.  However,
semantically, the if and else are at an equivalent level and should
share the same indent, so I may have to reconsider my habit in light
of your assertion that it may be less clear to other Stata
programmers.

While I agree with the assertion that complex code is complex, i
believe an alternative to deeply nested ifs would be welcome to many,
I think, and only wanted to spark some discussion.  We have seen the
-for- construct mature in functionality from the original for to
today's -foreach- and -forvalues-.  Before they were introduced
someone like me must have said, "I wish...".

I should like to add that the other construct with utility similar to
do case is the combination in some languages of else & if (elseif)
such that:

if #1 {
 do something
 }
elseif #2 {
 do something else
 }
 elseif #3 {
   do something else entirely
   }

You actually can use -else if- in Stata, achieving a similar utility:

if #1 {
 do something
 }
else if #2 {
 do something else
 }
 else if #3 {
   do something else entirely
   }

On the subject of text editors, a number of (free) editors (Crimson,
Notepad++, SciTE, for example) can be configured to automatically mark
nested code and also include provisions for "code-folding" - the
collapsing of a block of code between braces - a feature helpful in
writing long (a)do files.

DCE
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index