Elastic tabstop

From Wikipedia, the free encyclopedia
Jump to: navigation, search

In text editor applications in computing, elastic tabstops are an alternative way to handle tabstops, with a primary focus on editing source code in computer programming. The idea was first proposed by Nick Gravgaard as a solution for programmers who argue about what kind of indentation is best; tab or space characters. Joel Spolsky wrote a short note giving publicity to this idea.[1]

Elastic tabstops differ from traditional fixed tabstops because columns in lines above and below the "cell" that is being changed are always kept aligned. As the width of text before a tab character changes, the tabstops on adjacent lines are also changed to fit the widest piece of text in that column.

This method has some strengths over the older methods of code indentation, as it saves time for the programmer when he or she arranges the code and allows for proportional fonts in addition to the fixed-width fonts. On the other hand, this approach can make the code look unorganized on editors that do not have support for it, and it requires an indentation style which is interpreted correctly by this feature.

Contents

[edit] 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 <stdio.h>
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 <stdio.h>
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;
}

[edit] Implementations

Current implementations of elastic tabstops:

[edit] See also

[edit] References

[edit] External links

Personal tools
Namespaces
Variants
Actions
Navigation
Interaction
Toolbox
Print/export