Home

hersto:  Source Code Indentation / Nested Functions

 

Rant to the author:

    

Check for a response

Please read Source Code Indentation for the basic idea first.

Some programming languages support nesting of functions. Such source code would look like the following if the indentation rules suggested here are applied:

An Example:

 1:  function SomeFunc(A, B, C)
 2:  {
 3:      if(A > B && B > C)
 4:  return -1;
 5:
 6:
 7:      function ProcessIt(X, Y)
 8:      {
 9:          if(Y < 0)
10:      return -1;
11:
12:          if(X * X > Y)
13:      return -2;
14:
15:          var A= X * X;
16:          var B= Y * Y;
17:
18:          var Result= A + 2;
19:          if(B < 100)
20:              Result+= B;
21:
22:      return Result;
23:      }
24:
25:
26:      var ValAB= ProcessIt(A, B);
27:      var ValAC= ProcessIt(A, C);
28:      var ValBC= ProcessIt(B, C);
29:
30:  return ValAB * ValAB + ValAC * ValAC + ValBC * ValBC;
31:  }

Here the return statements inside the ProcessIt(.) function terminate only the ProcessIt(.) function, but not the outer SomeFunc(.) function. Therefore they are indented the same level as the declaration of the ProcessIt(.) function is. Conversely, the return statements which terminate the SomeFunc(.) function are indented according to the SomeFunc(.) funciton.

 

__.-.__
end of document