Elastic Tabstop - Example

Example

The following C program demonstrates how related code can be aligned using elastic tabstops, even when using a proportional font. The coloured backgrounds show the tabstop grouping.

#include
const float SQRT2 = 1.41421356; /* square root of 2 */
const float PI = 3.1416; /* mathematical constant pi */

/* This blank line prevents the red and yellow tabstops from combining */

float volume_cylinder( float radius,
float height)
{
float volume = PI * radius * radius * height;
return volume;
}
int main
{
float radius, height;
for (height = 1.0; height <= 3.0; ++height)
for (radius = 1.0; radius <= 3.0; ++radius)
printf( "Volume of cylinder of height %.0f and radius %.0f is %.2f.\n",
height,
radius,
volume_cylinder(radius, height));
return 0;
}

If the programmer, for example, changes the function name "volume_cylinder" to "volume" and constant name "PI" to "MATH_CONSTANT_PI", the code automatically realigns:

#include
const float SQRT2 = 1.41421356; /* square root of 2 */
const float MATH_CONSTANT_PI = 3.1416; /* mathematical constant pi */

/* This blank line prevents the red and yellow tabstops from combining */

float volume( float radius,
float height)
{
float volume = MATH_CONSTANT_PI * radius * radius * height;
return volume;
}
int main
{
float radius, height;
for (height = 1.0; height <= 3.0; ++height)
for (radius = 1.0; radius <= 3.0; ++radius)
printf( "Volume of cylinder of height %.0f and radius %.0f is %.2f.\n",
height,
radius,
volume(radius, height));
return 0;
}

Read more about this topic:  Elastic Tabstop

Famous quotes containing the word example:

    Our intellect is not the most subtle, the most powerful, the most appropriate, instrument for revealing the truth. It is life that, little by little, example by example, permits us to see that what is most important to our heart, or to our mind, is learned not by reasoning but through other agencies. Then it is that the intellect, observing their superiority, abdicates its control to them upon reasoned grounds and agrees to become their collaborator and lackey.
    Marcel Proust (1871–1922)