A"Hello, World!" program is usually a simplecomputer program that displays on the screen (often theconsole) a message similar to "Hello, World!". A small piece of code in mostgeneral-purpose programming languages, this program is used to illustrate a language's basicsyntax. Such a program is often the first written by a student of a new programming language,[1] but it can also be used as asanity check to ensure that thecomputer software intended tocompile or runsource code is correctly installed, and that its operator understands how to use it.
While several small test programs have existed since the development of programmablecomputers, the tradition of using the phrase "Hello, World!" as a test message was influenced by an example program in the 1978 bookThe C Programming Language,[2] with likely earlier use inBCPL. The example program from the book prints"hello, world", and was inherited from a 1974Bell Laboratories internal memorandum byBrian Kernighan,Programming in C: A Tutorial:[3]
main(){printf("hello, world");}
In the above example, themain( )function defines where the programshould start executing. The function body consists of a singlestatement, a call to theprintf() function, which stands for "print formatted"; it outputs to theconsole whatever is passed to it as theparameter, in this case thestring"hello, world".
The C-language version was preceded by Kernighan's own 1972A Tutorial Introduction to the LanguageB,[4] where the first known version of the program is found in an example used to illustrate external variables:
main( ) { extrn a, b, c; putchar(a); putchar(b); putchar(c); putchar('!*n');} a 'hell';b 'o, w';c 'orld';
The program above printshello, world! on the terminal, including anewline character. The phrase is divided into multiple variables because inB, a character constant is limited to fourASCII characters. The previous example in the tutorial printedhi! on the terminal, and the phrasehello, world! was introduced as a slightly longer greeting that required several character constants for its expression.
TheJargon File reports that "hello, world" instead originated in 1967 with the languageBCPL.[5] Outside computing, use of the exact phrase began over a decade prior; it was thecatchphrase of New York radio disc jockeyWilliam B. Williams beginning in the 1950s.[6]
"Hello, World!" programs vary in complexity between different languages. In some languages, particularlyscripting languages, the "Hello, World!" program can be written as one statement, while in others (more so manylow-level languages) many more statements can be required. For example, inPython, to print the stringHello, World! followed by a newline, one only needs to writeprint("Hello, World!"). In contrast, the equivalent code inC++[7] requires the import of theC++ standard library, the declaration of anentry point (main function), and a call to print a line of text to the standard output stream.
The phrase "Hello, World!" has seen various deviations in casing and punctuation, such as "hello world" which lacks the capitalization of the leadingH andW, and the presence of the comma or exclamation mark. Some devices limit the format to specific variations, such as all-capitalized versions on systems that support only capital letters, while someesoteric programming languages may have to print a slightly modified string. Other human languages have been used as the output; for example, a tutorial for theGo language emitted both English and Chinese or Japanese characters, demonstrating the language's built-inUnicode support.[8] Another notable example is theRust language, whose management system automatically inserts a "Hello, World" program when creating new projects.
Some languages change the function of the "Hello, World!" program while maintaining the spirit of demonstrating a simple example.Functional programming languages, such asLisp,ML, andHaskell, tend to substitute afactorial program for "Hello, World!", as functional programming emphasizes recursive techniques, whereas the original examples emphasize I/O, which violates the spirit of pure functional programming by producingside effects. Languages otherwise able to print "Hello, World!" (assembly language,C,VHDL) may also be used inembedded systems, where text output is either difficult (requiring added components or communication with another computer) or nonexistent. For devices such asmicrocontrollers,field-programmable gate arrays, andcomplex programmable logic devices (CPLDs), "Hello, World!" may thus be substituted with a blinkinglight-emitting diode (LED), which demonstrates timing and interaction between components.[9][10][11][12][13]
TheDebian andUbuntuLinux distributions provide the "Hello, World!" program through theirsoftware package manager systems, which can be invoked with the commandhello. It serves as asanity check and a simple example of installing a software package. For developers, it provides an example of creating a.deb package, either traditionally or usingdebhelper, and the version ofhello used,GNU Hello, serves as an example of writing aGNU program.[14]
Variations of the "Hello, World!" program that produce agraphical output (as opposed to text output) have also been shown.Sun demonstrated a "Hello, World!" program inJava based onscalable vector graphics,[15] and theXL programming language features a spinning Earth "Hello, World!" using3D computer graphics.[16]Mark Guzdial andElliot Soloway have suggested that the "hello, world" test message may be outdated now that graphics and sound can be manipulated as easily as text.[17]
"Time to hello world" (TTHW) is the time it takes to author a "Hello, World!" program in a given programming language. This is one measure of a programming language's ease of use. Since the program is meant as an introduction for people unfamiliar with the language, a more complex "Hello, World!" program may indicate that the programming language is less approachable.[20] For instance, the first publicly known "Hello, World!" program inMalbolge (which actually output "HEllO WORld") took two years to be announced, and it was produced not by a human but by a code generator written inCommon Lisp(see§ Variations, above).
The concept has been extended beyond programming languages toAPIs, as a measure of how simple it is for a new developer to get a basic example working; a shorter time indicates an easier API for developers to adopt.[21][22]
Wikipedia articles containing "Hello, World!" programs
^Vries, Joey de (2020).Learn OpenGL - Graphics Programming. Kendall & Welling. p. 26.ISBN978-90-90-33256-7.
^Beuken, Brian (January 2018). "Coding games on the Raspberry Pi in C/C++ Part 01".The MagPi. No. 65. p. 57.next time we will expand our code to start working with graphics and the famous 'hello triangle' code that absolutely no one uses except game coders