octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Style question


From: John W. Eaton
Subject: Style question
Date: Fri, 27 Apr 2007 11:03:33 -0400

On 27-Apr-2007, Kim Hansen wrote:

| When working on sub2ind I noticed that it was written in this style
| (pseudo code):
| 
| if (no_error1)
|   if (no_error2)
|     do stuff
|   else
|     error(message 2)
|   endif
| else
|   error(message 1)
| endif
| 
| In sub2ind there were 4 error checks like this inside each other, and
| I found it difficult to read compared to this style:
| 
| if (error1)
|   error(message 1)
| endif
| if (error2)
|   error(message 2)
| endif
| do stuff
| 
| Are there performance issues or other reasons for the first style?

I tend to prefer a single exit from a function and also to have the
checks look like this:

  if (things_are_ok)
    do_the_main_job_of_this_function ();
  else
    error (...);
  endif

jwe


reply via email to

[Prev in Thread] Current Thread [Next in Thread]