Elastic tabstop
Encyclopedia
In text editor
Text editor
A text editor is a type of program used for editing plain text files.Text editors are often provided with operating systems or software development packages, and can be used to change configuration files and programming language source code....

 applications in computing
Computing
Computing is usually defined as the activity of using and improving computer hardware and software. It is the computer-specific part of information technology...

, elastic tabstops are an alternative way to handle tabstops, with a primary focus on editing source code
Source code
In computer science, source code is text written using the format and syntax of the programming language that it is being written in. Such a language is specially designed to facilitate the work of computer programmers, who specify the actions to be performed by a computer mostly by writing source...

 in computer programming
Computer programming
Computer programming is the process of designing, writing, testing, debugging, and maintaining the source code of computer programs. This source code is written in one or more programming languages. The purpose of programming is to create a program that performs specific operations or exhibits a...

. The idea was first proposed by Nick Gravgaard as a solution for programmers who argue about what kind of indentation
Indentation
An indentation may refer to:* A notch, or deep recesses; for instance in a coastline, or a carving in rock* The placement of text farther to the right to separate it from surrounding text....

 is best; tab or space character
Character (computing)
In computer and machine-based telecommunications terminology, a character is a unit of information that roughly corresponds to a grapheme, grapheme-like unit, or symbol, such as in an alphabet or syllabary in the written form of a natural language....

s. Joel Spolsky
Joel Spolsky
Avram Joel Spolsky is a software engineer and writer. He is the author of Joel on Software, a blog on software development. He was a Program Manager on the Microsoft Excel team between 1991 and 1994. He later founded Fog Creek Software in 2000 and launched the Joel on Software blog...

 wrote a short note giving publicity to this idea.

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.

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;
}


Implementations

Current implementations of elastic tabstops:
  • Gedit
    Gedit
    gedit is a text editor for the GNOME desktop environment, Mac OS X and Microsoft Windows. Designed as a general purpose text editor, gedit emphasizes simplicity and ease of use...

     (requires Nick Gravgaard's plugin)
  • Code Browser
    Code browser
    A code Browser is an editor, sometimes with folding or other advanced layout capabilities, designed to structure source code or, by extension, other kinds of text file...

  • Inform 7
  • Google's Go programming language
    Go (programming language)
    Go is a compiled, garbage-collected, concurrent programming language developed by Google Inc.The initial design of Go was started in September 2007 by Robert Griesemer, Rob Pike, and Ken Thompson. Go was officially announced in November 2009. In May 2010, Rob Pike publicly stated that Go was being...

     in the tabwriter package

See also

  • Indentation
    Indentation
    An indentation may refer to:* A notch, or deep recesses; for instance in a coastline, or a carving in rock* The placement of text farther to the right to separate it from surrounding text....

     for the task
  • Indentation style for the various styles
  • Programming style
    Programming style
    Programming style is a set of rules or guidelines used when writing the source code for a computer program. It is often claimed that following a particular programming style will help programmers to read and understand source code conforming to the style, and help to avoid introducing errors.A...

  • Tab key
    Tab key
    Tab key on a keyboard is used to advance the cursor to the next tab stop.- Origin :The word tab derives from the word tabulate, which means "to arrange data in a tabular, or table, form"...

     for the keyboard key and the ASCII character
  • Tab stop
    Tab stop
    A tab stop on a typewriter is a location where the carriage movement is halted by mechanical gears. Tab stops are set manually, and pressing the tab key causes the carriage to go to the next tab stop...

    for the general concept

External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK