B (programming language)

Last updated
B
Designed by Ken Thompson
Developer Ken Thompson, Dennis Ritchie
First appeared1969;55 years ago (1969) [1]
Typing discipline typeless (everything is a word)
Filename extensions .b
Influenced by
BCPL, PL/I, TMG
Influenced
C

B is a programming language developed at Bell Labs circa 1969 by Ken Thompson and Dennis Ritchie.

Contents

B was derived from BCPL, and its name may possibly be a contraction of BCPL. Thompson's coworker Dennis Ritchie speculated that the name might be based on Bon, an earlier, but unrelated, programming language that Thompson designed for use on Multics. [note 1]

B was designed for recursive, non-numeric, machine-independent applications, such as system and language software. [3] It was a typeless language, with the only data type being the underlying machine's natural memory word format, whatever that might be. Depending on the context, the word was treated either as an integer or a memory address.

As machines with ASCII processing became common, notably the DEC PDP-11 that arrived at Bell Labs, support for character data stuffed in memory words became important. The typeless nature of the language was seen as a disadvantage, which led Thompson and Ritchie to develop an expanded version of the language supporting new internal and user-defined types, which became the C programming language.

History

BCPL semantics with a lot of SMALGOL syntax

Ken Thompson, [4]

Circa 1969, Ken Thompson [2] and later Dennis Ritchie [3] developed B basing it mainly on the BCPL language Thompson used in the Multics project. B was essentially the BCPL system stripped of any component Thompson felt he could do without in order to make it fit within the memory capacity of the minicomputers of the time. The BCPL to B transition also included changes made to suit Thompson's preferences (mostly along the lines of reducing the number of non-whitespace characters in a typical program). [2] Much of the typical ALGOL-like syntax of BCPL was rather heavily changed in this process. The assignment operator := reverted to the = of Rutishauser's Superplan, and the equality operator = was replaced by ==.

Thompson added "two-address assignment operators" using x =+ y syntax to add y to x (in C the operator is written +=). This syntax came from Douglas McIlroy's implementation of TMG, in which B's compiler was first implemented (and it came to TMG from ALGOL 68's x +:= y syntax). [2] [5] Thompson went further by inventing the increment and decrement operators (++ and --). Their prefix or postfix position determines whether the value is taken before or after alteration of the operand. This innovation was not in the earliest versions of B. According to Dennis Ritchie, people often assumed that they were created for the auto-increment and auto-decrement address modes of the DEC PDP-11, but this is historically impossible as the machine didn't exist when B was first developed. [2]

The semicolon version of the for loop was borrowed by Ken Thompson from the work of Stephen Johnson. [6]

B is typeless, or more precisely has one data type: the computer word. Most operators (e.g. +, -, *, /) treated this as an integer, but others treated it as a memory address to be dereferenced. In many other ways it looked a lot like an early version of C. There are a few library functions, including some that vaguely resemble functions from the standard I/O library in C. [3] In Thompson's words: "B and the old old C were very very similar languages except for all the types [in C]". [6]

Early implementations were for the DEC PDP-7 and PDP-11 minicomputers using early Unix, and Honeywell GE 645 [7] 36-bit mainframes running the operating system GCOS. The earliest PDP-7 implementations compiled to threaded code, and Ritchie wrote a compiler using TMG which produced machine code. [8] [9] [10] In 1970 a PDP-11 was acquired and threaded code was used for the port; an assembler, dc , and the B language itself were written in B to bootstrap the computer. An early version of yacc was produced with this PDP-11 configuration. Ritchie took over maintenance during this period. [2] [10]

The typeless nature of B made sense on the Honeywell, PDP-7 and many older computers, but was a problem on the PDP-11 because it was difficult to elegantly access the character data type that the PDP-11 and most modern computers fully support. Starting in 1971 Ritchie made changes to the language while converting its compiler to produce machine code, most notably adding data typing for variables. During 1971 and 1972 B evolved into "New B" (NB) and then C. [2]

B is almost extinct, having been superseded by the C language. [11] However, it continues to see use on GCOS mainframes (as of 2014) [12] and on certain embedded systems (as of 2000) for a variety of reasons: limited hardware in small systems, extensive libraries, tooling, licensing cost issues, and simply being good enough for the job. [11] The highly influential AberMUD was originally written in B.

Examples

The following examples are from the Users' Reference to B by Ken Thompson: [3]

/* The following function will print a non-negative number, n, to   the base b, where 2<=b<=10.  This routine uses the fact that   in the ANSCII character set, the digits 0 to 9 have sequential   code values.  */printn(n,b){extrnputchar;autoa;/* Wikipedia note: the auto keyword declares a variable with      automatic storage (lifetime is function scope), not      "automatic typing" as in C++11. */if(a=n/b)/* assignment, not test for equality */printn(a,b);/* recursive */putchar(n%b+'0');}
/* The following program will calculate the constant e-2 to about   4000 decimal digits, and print it 50 characters to the line in   groups of 5 characters.  The method is simple output conver-   sion of the expansion      1/2! + 1/3! + ... = .111...   where the bases of the digits are 2, 3, 4, ... */main(){extrnputchar,n,v;autoi,c,col,a;i=col=0;while(i<n)v[i++]=1;while(col<2*n){a=n+1;c=i=0;while(i<n){c=+v[i]*10;v[i++]=c%a;c=/a--;}putchar(c+'0');if(!(++col%5))putchar(col%50?' ':'*n');}putchar('*n*n');}v[2000];n2000;

Notes

  1. "Its name most probably represents a contraction of BCPL, though an alternate theory holds that it derives from Bon [Thompson 69], an unrelated language created by Thompson during the Multics days. Bon in turn was named either after his wife Bonnie or (according to an encyclopedia quotation in its manual), after a religion whose rituals involve the murmuring of magic formulas." [2]

Related Research Articles

<span class="mw-page-title-main">Brian Kernighan</span> Canadian computer scientist

Brian Wilson Kernighan is a Canadian computer scientist. He worked at Bell Labs and contributed to the development of Unix alongside Unix creators Ken Thompson and Dennis Ritchie. Kernighan's name became widely known through co-authorship of the first book on the C programming language with Dennis Ritchie. Kernighan affirmed that he had no part in the design of the C language.

BCPL is a procedural, imperative, and structured programming language. Originally intended for writing compilers for other languages, BCPL is no longer in common use. However, its influence is still felt because a stripped down and syntactically changed version of BCPL, called B, was the language on which the C programming language was based. BCPL introduced several features of many modern programming languages, including using curly braces to delimit code blocks. BCPL was first implemented by Martin Richards of the University of Cambridge in 1967.

C is a general-purpose programming language. It was created in the 1970s by Dennis Ritchie and remains very widely used and influential. By design, C's features cleanly reflect the capabilities of the targeted CPUs. It has found lasting use in operating systems code, device drivers, and protocol stacks, but its use in application software has been decreasing. C is commonly used on computer architectures that range from the largest supercomputers to the smallest microcontrollers and embedded systems.

<span class="mw-page-title-main">Dennis Ritchie</span> American computer scientist, co-creator of the Unix operating system

Dennis MacAlistair Ritchie was an American computer scientist. He created the C programming language and, with long-time colleague Ken Thompson, the Unix operating system and B language. Ritchie and Thompson were awarded the Turing Award from the Association for Computing Machinery (ACM) in 1983, the IEEE Richard W. Hamming Medal from the Institute of Electrical and Electronics Engineers (IEEE) in 1990, and the National Medal of Technology from President Bill Clinton in 1999.

A "Hello, World!" program is generally a simple computer program which emits to the screen a message similar to "Hello, World!" while ignoring any user input. A small piece of code in most general-purpose programming languages, this program is used to illustrate a language's basic syntax. A "Hello, World!" program is often the first written by a student of a new programming language, but such a program can also be used as a sanity check to ensure that the computer software intended to compile or run source code is correctly installed, and that its operator understands how to use it.

<span class="mw-page-title-main">Multics</span> Time-sharing operating system

Multics is an influential early time-sharing operating system based on the concept of a single-level memory. Nathan Gregory writes that Multics "has influenced all modern operating systems since, from microcomputers to mainframes."

QED is a line-oriented computer text editor that was developed by Butler Lampson and L. Peter Deutsch for the Berkeley Timesharing System running on the SDS 940. It was implemented by L. Peter Deutsch and Dana Angluin between 1965 and 1966.

Yacc is a computer program for the Unix operating system developed by Stephen C. Johnson. It is a lookahead left-to-right rightmost derivation (LALR) parser generator, generating a LALR parser based on a formal grammar, written in a notation similar to Backus–Naur form (BNF). Yacc is supplied as a standard utility on BSD and AT&T Unix. GNU-based Linux distributions include Bison, a forward-compatible Yacc replacement.

<span class="mw-page-title-main">PDP-7</span> Minicomputer introduced in 1964

The PDP-7 is an 18-bit minicomputer produced by Digital Equipment Corporation as part of the PDP series. Introduced in 1964, shipped since 1965, it was the first to use their Flip-Chip technology. With a cost of US$72,000, it was cheap but powerful by the standards of the time. The PDP-7 is the third of Digital's 18-bit machines, with essentially the same instruction set architecture as the PDP-4 and the PDP-9.

Joseph Frank Ossanna, Jr. was an American electrical engineer and computer programmer who worked as a member of the technical staff at the Bell Telephone Laboratories in Murray Hill, New Jersey. He became actively engaged in the software design of Multics, a general-purpose operating system used at Bell.

TYPSET is an early document editor that was used with the 1964-released RUNOFF program, one of the earliest text formatting programs to see significant use.

roff is a typesetting markup language. As the first Unix text-formatting computer program, it is a predecessor of the nroff and troff document processing systems.

<span class="mw-page-title-main">Douglas McIlroy</span> American mathematician and computer scientist

Malcolm Douglas McIlroy is an American mathematician, engineer, and programmer. As of 2019 he is an Adjunct Professor of Computer Science at Dartmouth College. McIlroy is best known for having originally proposed Unix pipelines and developed several Unix tools, such as spell, diff, sort, join, graph, speak, and tr. He was also one of the pioneering researchers of macro processors and programming language extensibility. He participated in the design of multiple influential programming languages, particularly PL/I, SNOBOL, ALTRAN, TMG and C++.

<i>Space Travel</i> (video game) 1969 video game

Space Travel is an early video game developed by Ken Thompson in 1969 that simulates travel in the Solar System. The player flies their ship around a two-dimensional scale model of the Solar System with no objectives other than to attempt to land on various planets and moons. The player can move and turn the ship, and adjust the overall speed by adjusting the scale of the simulation. The ship is affected by the single strongest gravitational pull of the astronomical bodies.

<span class="mw-page-title-main">History of Unix</span> Operating system

The history of Unix dates back to the mid-1960s, when the Massachusetts Institute of Technology, AT&T Bell Labs, and General Electric were jointly developing an experimental time-sharing operating system called Multics for the GE-645 mainframe. Multics introduced many innovations, but also had many problems. Bell Labs, frustrated by the size and complexity of Multics but not its aims, slowly pulled out of the project. Their last researchers to leave Multics – among them Ken Thompson, Dennis Ritchie, Doug McIlroy, and Joe Ossanna – decided to redo the work, but on a much smaller scale.

<span class="mw-page-title-main">Unix</span> Family of computer operating systems

Unix is a family of multitasking, multi-user computer operating systems that derive from the original AT&T Unix, whose development started in 1969 at the Bell Labs research center by Ken Thompson, Dennis Ritchie, and others.

<span class="mw-page-title-main">Ken Thompson</span> American computer scientist, co-creator of the Unix operating system

Kenneth Lane Thompson is an American pioneer of computer science. Thompson worked at Bell Labs for most of his career where he designed and implemented the original Unix operating system. He also invented the B programming language, the direct predecessor to the C language, and was one of the creators and early developers of the Plan 9 operating system. Since 2006, Thompson has worked at Google, where he co-developed the Go language.

Increment and decrement operators are unary operators that increase or decrease their operand by one.

<span class="mw-page-title-main">TMG (language)</span>

In computing TMG (TransMoGrifier) is a recursive descent compiler-compiler developed by Robert M. McClure and presented in 1965. TMG ran on systems including OS/360 and early Unix. It was used to build EPL, an early version of PL/I.

In computer programming, self-hosting is the use of a program as part of the toolchain or operating system that produces new versions of that same program—for example, a compiler that can compile its own source code. Self-hosting software is commonplace on personal computers and larger systems. Other programs that are typically self-hosting include kernels, assemblers, command-line interpreters and revision control software.

References

  1. "B - computer programming language".
  2. 1 2 3 4 5 6 7 Ritchie, Dennis M. (March 1993). "The Development of the C Language". ACM SIGPLAN Notices. 28 (3): 201–208. doi: 10.1145/155360.155580 .
  3. 1 2 3 4 Thompson, Ken (7 January 1972). "Users' Reference to B" (PDF). Bell Laboratories. Archived from the original (PDF) on 17 March 2015. Retrieved 21 March 2014.
  4. Jensen, Richard (9 December 2020). ""A damn stupid thing to do"—the origins of C". Ars Technica. Retrieved 2022-03-28.
  5. Michael S. Mahoney (18 August 1989). "Interview with M.D. McIlroy". Princeton.edu. Murray Hill.
  6. 1 2 Ken Thompson. "VCF East 2019 -- Brian Kernighan interviews Ken Thompson". YouTube . Archived from the original on 2021-11-23. Retrieved 2020-11-16. I saw Johnson's semicolon version of the for loop and I put that in [B], I stole it.
  7. Ritchie, Dennis M. (1984). "The Evolution of the Unix Time-sharing System". AT&T Bell Laboratories Technical Journal. 63 (6 Part 2): 1577–1593. doi:10.1002/j.1538-7305.1984.tb00054.x. Archived from the original on 11 June 2015.
  8. "TMG". multicians.org.
  9. Ritchie, Dennis M. "The Development of the C Language". Bell Labs/Lucent Technologies. Archived from the original on 11 June 2015.
  10. 1 2 McIlroy, M. D. (1987). A Research Unix reader: annotated excerpts from the Programmer's Manual, 1971–1986 (PDF) (Technical report). CSTR. Bell Labs. 139. Archived (PDF) from the original on 2022-10-09.
  11. 1 2 Johnson and Kernighan. "THE PROGRAMMING LANGUAGE B". Bell Laboratories. Archived from the original on 11 June 2015. Retrieved 21 March 2014.
  12. "Thinkage UW Tools Package". Thinkage, Ltd. Retrieved 26 March 2014.