Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

"Hello, World!" program

From Wikipedia, the free encyclopedia
Traditional first example of a computer programming language
"Hello, World" and "Helloworld" redirect here. For other uses, seeHello World (disambiguation).

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.

History

[edit]
"Hello, World!" program handwritten in theC language and signed byBrian Kernighan (1978)

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]

Variations

[edit]
A "Hello, World!" program running on Sony'sPlayStation Portable as aproof of concept

"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.

Computernumerical control (CNC) machining test inpoly(methyl methacrylate) (Perspex)

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.

A "Hello, World!" message being displayed through long-exposurelight painting with a moving strip oflight-emitting diodes (LEDs)

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]

Incomputer graphics, rendering a triangle—the "Hello Triangle"—is sometimes used as an introductory example forgraphics libraries.[18][19]

Time to Hello World

[edit]

"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

[edit]

See also

[edit]

References

[edit]
  1. ^Langbridge, James A. (3 December 2013).Professional Embedded ARM Development. John Wiley & Sons.ISBN 9781118887820.
  2. ^Kernighan, Brian W.;Ritchie, Dennis M. (1978).The C Programming Language (1st ed.).Englewood Cliffs, New Jersey:Prentice Hall. p. 6.ISBN 0-13-110163-3.
  3. ^Kernighan, Brian (1974)."Programming in C: A Tutorial"(PDF). Bell Labs.Archived(PDF) from the original on 22 March 2022. Retrieved9 January 2019.
  4. ^Johnson, S. C.;Kernighan, B. W.The Programming Language B. Bell Labs.Archived from the original on 11 June 2015. Retrieved8 August 2024.
  5. ^"BCPL".Jargon File.Archived from the original on 3 April 2018. Retrieved21 April 2013.
  6. ^"William B. Williams, Radio Personality, Dies".The New York Times. 4 August 1986.
  7. ^"C++ Programming/Examples/Hello world".Wikibooks.Archived from the original on 28 March 2022. Retrieved16 March 2022.
  8. ^A Tutorial for the Go Programming Language.Archived 26 July 2010 at theWayback Machine The Go Programming Language. Retrieved 26 July 2011.
  9. ^Silva, Mike (11 September 2013)."Introduction to Microcontrollers - Hello World".EmbeddedRelated.com.Archived from the original on 22 May 2015. Retrieved19 May 2015.
  10. ^George, Ligo (8 May 2013)."Blinking LED using Atmega32 Microcontroller and Atmel Studio".electroSome.Archived from the original on 5 November 2014. Retrieved19 May 2015.
  11. ^PT, Ranjeeth."2. AVR Microcontrollers in Linux HOWTO".The Linux Documentation Project.Archived from the original on 2 May 2015. Retrieved19 May 2015.
  12. ^Andersson, Sven-Åke (2 April 2012)."3.2 The first Altera FPGA design". Raidió Teilifís Éireann. Archived fromthe original on 21 May 2015. Retrieved19 May 2015.
  13. ^Fabio, Adam (6 April 2014)."CPLD Tutorial: Learn programmable logic the easy way".Hackaday.Archived from the original on 20 May 2015. Retrieved19 May 2015.
  14. ^"Hello".GNU Project. Free Software Foundation. Archived fromthe original on 29 May 2014. Retrieved7 July 2017.
  15. ^Jolif, Christophe (January 2003). "Bringing SVG Power to Java Applications".Sun Developer Network.
  16. ^de Dinechin, Christophe (24 July 2010)."Hello world!". Grenouille Bouillie.
  17. ^"Teaching the Nintendo Generation to Program"(PDF).bfoit.org. Archived fromthe original(PDF) on 5 May 2016. Retrieved27 December 2015.
  18. ^Vries, Joey de (2020).Learn OpenGL - Graphics Programming. Kendall & Welling. p. 26.ISBN 978-90-90-33256-7.
  19. ^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
  20. ^O'Dwyer, Arthur (September 2017).Mastering the C++17 STL: Make full use of the standard library components in C++17.Packt Publishing Ltd. p. 251.ISBN 978-1-78728-823-2. Retrieved4 December 2019.
  21. ^Wiegers, Harold (28 June 2018)."The importance of "Time to First Hello, World!" an efficient API program".Archived from the original on 19 February 2020. Retrieved19 February 2020.
  22. ^Jin, Brenda; Sahni, Saurabh; Shevat, Amir (29 August 2018).Designing Web APIs: Building APIs That Developers Love. O'Reilly Media.ISBN 9781492026877. Retrieved19 February 2020.

External links

[edit]
Wikimedia Commons has media related toHello World.
The WikibookComputer Programming has a page on the topic of:Hello world
Wikiversity has learning resources about"Hello, World!" program
Standard test items
Artificial intelligence
(Machine learning)
Television (test card)
Computer languages
Data compression
3D computer graphics
2D computer graphics
Typography (filler text)
Other
Retrieved from "https://en.wikipedia.org/w/index.php?title=%22Hello,_World!%22_program&oldid=1337054123"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2026 Movatter.jp