HOME

TheInfoList



OR:

In computing, a line number is a method used to specify a particular sequence of characters in a
text file A text file (sometimes spelled textfile; an old alternative name is flatfile) is a kind of computer file that is structured as a sequence of lines of electronic text. A text file exists stored as data within a computer file system. In operatin ...
. The most common method of assigning numbers to lines is to assign every
line Line most often refers to: * Line (geometry), object with zero thickness and curvature that stretches to infinity * Telephone line, a single-user circuit on a telephone communication system Line, lines, The Line, or LINE may also refer to: Art ...
a unique number, starting at 1 for the first line, and incrementing by 1 for each successive line. In the C
programming language A programming language is a system of notation for writing computer programs. Most programming languages are text-based formal languages, but they may also be graphical. They are a kind of computer language. The description of a programming ...
the line number of a
source code In computing, source code, or simply code, is any collection of code, with or without comments, written using a human-readable programming language, usually as plain text. The source code of a program is specially designed to facilitate the w ...
line is one greater than the number of
new-line Newline (frequently called line ending, end of line (EOL), next line (NEL) or line break) is a control character or sequence of control characters in character encoding specifications such as ASCII, EBCDIC, Unicode, etc. This character, or a ...
characters read or introduced up to that point. Programmers could also assign line numbers to statements in older
programming languages A programming language is a system of notation for writing computer program, computer programs. Most programming languages are text-based formal languages, but they may also be visual programming language, graphical. They are a kind of computer ...
, such as Fortran,
JOSS Joss may refer to: * Joss (name), including a list of people with the name * JOSS, a time-sharing programming language * Joss (Chinese statue), a religious object * Joss JP1, an Australian-built supercar * Joss paper, a type of burnt offering * Jo ...
, and
BASIC BASIC (Beginners' All-purpose Symbolic Instruction Code) is a family of general-purpose, high-level programming languages designed for ease of use. The original version was created by John G. Kemeny and Thomas E. Kurtz at Dartmouth College i ...
. In Fortran, not every statement needed a line number, and line numbers did not have to be in sequential order. The purpose of line numbers was for branching and for reference by formatting statements. Both JOSS and BASIC made line numbers a required element of
syntax In linguistics, syntax () is the study of how words and morphemes combine to form larger units such as phrases and sentences. Central concerns of syntax include word order, grammatical relations, hierarchical sentence structure (constituency ...
. The primary reason for this is that most
operating systems An operating system (OS) is system software that manages computer hardware, software resources, and provides common daemon (computing), services for computer programs. Time-sharing operating systems scheduler (computing), schedule tasks for ef ...
at the time lacked interactive
text editors A text editor is a type of computer program that edits plain text. Such programs are sometimes known as "notepad" software (e.g. Windows Notepad). Text editors are provided with operating systems and software development packages, and can be u ...
; since the programmer's interface was usually limited to a
line editor In computing, a line editor is a text editor in which each editing command applies to one or more complete lines of text designated by the user. Line editors predate screen-based text editors and originated in an era when a computer operator typic ...
, line numbers provided a mechanism by which specific lines in the
source code In computing, source code, or simply code, is any collection of code, with or without comments, written using a human-readable programming language, usually as plain text. The source code of a program is specially designed to facilitate the w ...
could be referenced for editing, and by which the programmer could insert a new line at a specific point. Line numbers also provided a convenient means of distinguishing between code to be entered into the program and
direct mode In computing, direct or immediate mode in an interactive programming system is the immediate execution of commands, statements, or expressions. In many interactive systems, most of these can both be included in programs or executed directly in a ...
commands to be executed immediately when entered by the user (which do not have line numbers). Largely due to the prevalence of interactive text editing in modern
operating system An operating system (OS) is system software that manages computer hardware, software resources, and provides common daemon (computing), services for computer programs. Time-sharing operating systems scheduler (computing), schedule tasks for ef ...
s, line numbers are not a feature of most programming languages, even modern Fortran and Basic.


History


FORTRAN

In Fortran, as first specified in 1956, line numbers were used to define input/output patterns, to specify statements to be repeated, and for conditional branching. For example: DIMENSION ALPHA(25), RHO(25) 1) FORMAT(5F12.4) 2) READ 1, ALPHA, RHO, ARG SUM = 0.0 DO 3 I=1, 25 IF (ARG-ALPHA(I)) 4,3,3 3) SUM = SUM + ALPHA(I) 4) VALUE = 3.14159*RHO(I-1) PRINT 1, ARG, SUM, VALUE GO TO 2 Like assembler language before it, Fortran did not assume every line needed a label (line number, in this case). Only statements referenced elsewhere required a line number: * Line 1 specifies a format pattern for input; the command in line 2 and the later command both reference this line. * The loop executes line 3. * The arithmetic IF statement branches to line 4 on a negative value, line 3 on zero, and again line 3 on a positive value. While the line numbers are sequential in this example, in the very first "complete but simple ortranprogram" published the line numbers are in the sequence 1, 5, 30, 10, 20, 2. (2+51+1 pages) Line numbers could also be assigned to fixed-point variables (e.g., ''i'' ''n'') for referencing in subsequent assigned GO TO statements (e.g., ''n,(n1,n2,...nm)'').


COBOL

In
COBOL COBOL (; an acronym for "common business-oriented language") is a compiled English-like computer programming language designed for business use. It is an imperative, procedural and, since 2002, object-oriented language. COBOL is primarily us ...
, line numbers were specified in the first six characters (the ''sequence number area'') of
punched card A punched card (also punch card or punched-card) is a piece of stiff paper that holds digital data represented by the presence or absence of holes in predefined positions. Punched cards were once common in data processing applications or to di ...
s. This was originally used for facilitating mechanical card sorting to assure intended program code sequence after manual handling. The line numbers were actually ignored by the compiler.


DOPE

In 1962,
DOPE (Dartmouth Oversimplified Programming Experiment) DOPE, short for Dartmouth Oversimplified Programming Experiment, was a simple programming language designed by John Kemény in 1962 to offer students a transition from flow-charting to programming the LGP-30. Lessons learned from implementing D ...
became one of the first programming languages to require a line number for every statement and to use sequential ordering of line numbers. Line numbers were specified as destinations for two commands, C (Compare operation, an arithmetic IF) and T (To operation, a GO TO).


JOSS

In 1963,
JOSS Joss may refer to: * Joss (name), including a list of people with the name * JOSS, a time-sharing programming language * Joss (Chinese statue), a religious object * Joss JP1, an Australian-built supercar * Joss paper, a type of burnt offering * Jo ...
independently made line numbers mandatory for every statement in a program and ordered lines in sequential order. JOSS introduced the idea of a single
command line A command-line interpreter or command-line processor uses a command-line interface (CLI) to receive commands from a user in the form of lines of text. This provides a means of setting parameters for the environment, invoking executables and pro ...
editor that worked both as an interactive language and a program editor. Commands that were typed without a line number were executed immediately, in what JOSS referred to as "direct mode". If the same line was prefixed with a line number, it was instead copied into the program code storage area, which JOSS called "indirect mode". Unlike FORTRAN before it or BASIC after it, JOSS required line numbers to be fixed-point numbers consisting of a pair of two-digit integers separated by a period (e.g., 1.1). The portion of the line number to the left of the period is known as the "page" or "part", while the portion to the right is known as the "line"; for example, the line number refers to page 10, line 12. Branches can target either a page or a line within a page. When the later format is used, the combined page and line is known as a "step". Pages are used to define subroutines, which return when the next line is on a different page. For instance, if a subroutine for calculating the square root of a number is in page 3, one might have three lines of code 3.1, 3.2 and 3.3, and it would be called using The code would return to the statement after the Do when it reaches the next line on a different page, for instance, 4.1. There is no need for the equivalent of a at the end, although if an early return is required, accomplishes this. Example: *Routine to ask the user for a positive value and repeat until it gets one 01.10 Demand X as "Enter a positive value greater than zero". 01.20 Done if X>0. 01.30 To step 1.1


BASIC

Introduced in 1964,
Dartmouth BASIC Dartmouth BASIC is the original version of the BASIC programming language. It was designed by two professors at Dartmouth College, John G. Kemeny and Thomas E. Kurtz. With the underlying Dartmouth Time Sharing System (DTSS), it offered an intera ...
adopted mandatory line numbers, as in JOSS, but made them integers, as in FORTRAN. As defined initially, BASIC only used line numbers for and (go to subroutine, then return). Some
Tiny BASIC Tiny BASIC is a family of dialects of the BASIC programming language that can fit into 4 or fewer KBs of memory. Tiny BASIC was designed in response to the open letter published by Bill Gates complaining about users pirating Altair BASIC, which ...
implementations supported numeric expressions instead of constants, while
switch statement In computer programming languages, a switch statement is a type of selection control mechanism used to allow the value of a variable or expression to change the control flow of program execution via search and map. Switch statements function som ...
s were present in different dialects ( ; ; ). Line numbers were rarely used elsewhere. One exception was allowing the pointer used by (which iterated through statements) to be set to a specific line number using . 1 REM RESTORE COULD BE USED IF A BASIC LACKED STRING ARRAYS 2 DIM M$(9): REM DEFINE LENGTH OF 9 CHARACTERS 5 INPUT "MONTH #?"; M: IF M<1 OR M>12 THEN 5 7 RESTORE 10*M: READ M$: PRINT M$ 10 DATA "JANUARY" 20 DATA "FEBRUARY" 30 DATA "MARCH" ... In the first editions of Dartmouth BASIC, could only be followed by a line number (for an ''implied GOTO''), not - as in later implementations - by a statement. The range of valid line numbers varied widely from implementation to implementation, depending on the representation used to store the binary equivalent of the line number (one or two bytes; signed or unsigned). While Dartmouth BASIC supported 1 to 99999, the typical microcomputer implementation supported 1 to 32767 (a signed 16-bit word). 1) While QBASIC does make use of structured programming and thus doesn't need line numbers, it is still possible to run code with line numbers in QBASIC.


Line numbers and style

It was a matter of
programming style Programming style, also known as code 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 read and understand sour ...
, if not outright necessity, in these languages to leave gaps between successive line numbers—i.e., a programmer would use the sequence (10, 20, 30, ...) rather than (1, 2, 3, ...). This permitted the programmer to insert a
line of code Source lines of code (SLOC), also known as lines of code (LOC), is a software metric used to measure the size of a computer program by counting the number of lines in the text of the program's source code. SLOC is typically used to predict the am ...
at a later time. For example, if a line of code between lines 20 and 30 was left out, the programmer might insert the forgotten line at line number 25. If no gaps were left in the numbering, the programmer would be required to renumber line 3 and all subsequent lines in order to insert the new line after line 2. Of course, if the programmer needed to insert more than nine additional lines, renumbering would be required even with the sparser numbering. However, this renumbering would be limited to renumbering only 1 line per ten lines added; when the programmer finds they need to add a line between 29 and 30, only line 30 would need to be renumbered and line 40 could be left unchanged. Some BASICs had a command, which typically would go through the program (or a specified portion of it), reassigning line numbers in equal increments. It would also renumber all references to those line numbers so they would continue to work properly. In a large program containing subroutines, each subroutine would usually start at a line number sufficiently large to leave room for expansion of the main program (and previous subroutines). For example, subroutines might begin at lines 10000, 20000, 30000, etc.


Line numbers and GOTOs

In "unstructured" programming languages such as
BASIC BASIC (Beginners' All-purpose Symbolic Instruction Code) is a family of general-purpose, high-level programming languages designed for ease of use. The original version was created by John G. Kemeny and Thomas E. Kurtz at Dartmouth College i ...
, line numbers were used to specify the targets of branching statements. For example: 1 S=0: N=-1 2 INPUT "ENTER A NUMBER TO ADD, OR 0 TO END"; I 3 S=S+I: N=N+1: IF I<>0 THEN GOTO 2 4 PRINT "SUM="; S: PRINT "AVERAGE="; S/N
GOTO GoTo (goto, GOTO, GO TO or other case combinations, depending on the programming language) is a statement found in many computer programming languages. It performs a one-way transfer of control to another line of code; in contrast a function c ...
-style branching can lead to the development of
spaghetti code Spaghetti code is a pejorative phrase for unstructured and difficult-to- maintain source code. Spaghetti code can be caused by several factors, such as volatile project requirements, lack of programming style rules, and software engineers with insu ...
. (See Considered harmful,
Structured programming Structured programming is a programming paradigm aimed at improving the clarity, quality, and development time of a computer program by making extensive use of the structured control flow constructs of selection ( if/then/else) and repetition ( ...
.) Even in some later versions of BASIC that still mandated line numbers, the use of line number-controlled GOTOs was phased out whenever possible in favor of cleaner constructs such as the
for loop In computer science a for-loop or for loop is a control flow statement for specifying iteration. Specifically, a for loop functions by running a section of code repeatedly until a certain condition has been satisfied. For-loops have two part ...
and
while loop In most computer programming languages, a while loop is a control flow statement that allows code to be executed repeatedly based on a given Boolean condition. The ''while'' loop can be thought of as a repeating if statement. Overview The '' ...
. Many modern languages (including C and
C++ C, or c, is the third letter in the Latin alphabet, used in the modern English alphabet, the alphabets of other western European languages and others worldwide. Its name in English is ''cee'' (pronounced ), plural ''cees''. History "C" ...
) include a version of the GOTO statement; however, in these languages the target of a GOTO is specified by a
line label In programming languages, a label is a sequence of characters that identifies a location within source code. In most languages, labels take the form of an identifier, often followed by a punctuation character (e.g., a colon). In many high-l ...
instead of a line number.


Line numbers and syntax errors

If a programmer introduces a syntax error into a program, the
compiler In computing, a compiler is a computer program that translates computer code written in one programming language (the ''source'' language) into another language (the ''target'' language). The name "compiler" is primarily used for programs th ...
(or interpreter) will inform the programmer that the attempt to compile (or execute) failed at the given line number. This simplifies the job of finding the error immensely for the programmer. The use of line numbers to describe the location of errors remains standard in modern programming tools, even though line numbers are never required to be manually specified. It is a simple matter for a program to count the
newline Newline (frequently called line ending, end of line (EOL), next line (NEL) or line break) is a control character or sequence of control characters in character encoding specifications such as ASCII, EBCDIC, Unicode, etc. This character, or a ...
s in a
source file In computing, source code, or simply code, is any collection of code, with or without comments, written using a human-readable programming language, usually as plain text. The source code of a program is specially designed to facilitate the w ...
and display an automatically generated line number as the location of the error. In IDEs such as
Microsoft Visual Studio Visual Studio is an integrated development environment (IDE) from Microsoft. It is used to develop computer programs including web site, websites, web apps, web services and mobile apps. Visual Studio uses Microsoft software development platfor ...
, Eclipse or
Xcode Xcode is Apple's integrated development environment (IDE) for macOS, used to develop software for macOS, iOS, iPadOS, watchOS, and tvOS. It was initially released in late 2003; the latest stable release is version 14.2, released on December 13, ...
, in which the compiler is usually integrated with the text editor, the programmer can even
double-click A double-click is the act of pressing a computer mouse button twice quickly without moving the mouse. Double-clicking allows two different actions to be associated with the same mouse button. It was developed by Bill Atkinson of Apple Computer (n ...
on an error and be taken directly to the line containing that error.


See also

*
Line label In programming languages, a label is a sequence of characters that identifies a location within source code. In most languages, labels take the form of an identifier, often followed by a punctuation character (e.g., a colon). In many high-l ...
*
Listing (computer) A listing or program listing is a printed list of lines of computer code or digital data (in human-readable form). Use cases Listings are commonly used in education and computer-related books to show examples of code. In the early days of p ...


References

{{reflist Source code Articles with example code Text editor features