Hello World: Difference between revisions

From Citizendium
Jump to navigation Jump to search
imported>Joshua Beckerman
imported>Meg Taylor
No edit summary
 
(12 intermediate revisions by 6 users not shown)
Line 1: Line 1:
{{subpages}}
{{subpages}}


[[Image:HelloWorld.jpg|right|frame|Results of executing a Hello World program in a console on a Linux or Unix system.]]
A '''Hello World''' computer program, as first introduced in the book ''The C Programming Language'', is a very short program that typically just prints a word or two of output to a console. Such a program is often one of the first programs that a [[programmer]] writes when learning a [[programming language]], as it provides a cursory introduction to the language's [[syntax]] and output.


A '''Hello World''' program, as first introduced in the book ''The C Programming Language'', is a very short program that typically just prints a word or two of output to a console.  Such a program is often one of the first programs that a [[programmer]] writes when learning a [[programming language]], as it provide's a cursory introduction to the language's [[syntax]] and output.
== Hello World as a first program ==


== Example in some of the most popular languages ==
In teaching a new language, there arises a need for a minimal, 'first phrase' to introduce students to the new language. In natural language, this is often "Hello, my name is John" or a variation thereof. The equivalent in computing is the program that says, prints, or displays "Hello, World!" or something else to that effect. Such programs, regardless of the actual wording, are called "Hello World" programs. The program is usually not meant to display the features or design of a language, since printing simple strings is seldom the main focus of a language. Instead, the example aims to give some 'feel' for the language, its basic syntax and the minimal structure of a program. Despite the apparent simpleness of the example, such programs vary greatly in their design from language to language.
=== Example in [[C programming language|C]] ===
<pre>
#include <stdio.h>


int main()
== Kernighan & Ritchie's Hello World ==
{
    printf("This is my first C program!\n");
    return 0;
}
</pre>


=== Example in [[C%2B%2B|C++]] ===
Brian Kernighan and Dennis Ritchie's book ''The C Programming Language'' was the first book to use Hello World. The example, essentially as it appeared in the later, [[ANSI C]] standard-conformant, edition of the book was as follows:
<pre>
// Hello World in C++ (pre-ISO)


#include <iostream.h>
#include <stdio.h>
int main(int argc, char *argv[]) {
    printf("Hello, World!\n");
    return 0;
}


int main()
== Limitations of Hello World examples ==
{
    cout << "Hello World!" << endl;
    return 0;
}
</pre>


=== Example in Java ===
In some languages, it is not a particularly useful way to demonstrate the key benefit of using that particular language. [[Functional programming]] languages like [[Haskell]], [[OCaml]], [[F#]] and the [[Lisp]] family often substitute a mathematical problem like calculation of [[factorial]]s in place of Hello World examples.
<pre>
// Hello World in Java


class HelloWorld {
Consider a language like [[Clojure]], a Lisp-derived dynamic language on the Java platform. Learning how to write Hello World is of less interest to a Clojure programmer than learning how to do a task that is not trivially easy to accomplish in Java, the language many Clojure programmers are initially familiar with.
  static public void main( String args[] ) {
    System.out.println( "Hello World!" );
  }
}
</pre>
=== Example in [[Perl]] ===
<pre>
# Hello world in perl


print "Hello World!\n";
Similarly, languages designed primarily for running concurrent, high-performance services (like [[Erlang]], [[Scala]] etc.) are not best served by showing Hello World examples, and so many prefer to show how to construct concurrently operating, multi-threaded services like HTTP servers.
</pre>
=== Example in [[PHP]] ===
<pre>
<?php
  // Hello World in PHP
  echo 'Hello World!';
?>
</pre>


=== Example in [[Python programming language|Python]] ===
Browser-based [[JavaScript]] is another example of a language not best served by Hello World examples: these are often implemented using document.write, which is not considered a good technique anymore.
<pre>
# Hello World in Python
print "Hello world"
</pre>


=== Example in VBScript ===
<pre>
'Hello World in VBScript
WScript.Echo "Hello world"
</pre>


=== Example in [[Ruby programming language|Ruby]] ===
<!-- == See also == -->
<pre>
# Hello World in Ruby
puts 'Hello world'
</pre>
 
=== Example in [[C_Sharp|C#]] ===
<pre>
// Hello World in C#
class Hello
{
  static void Main()
  {
      System.Console.WriteLine("Hello World");
  }
}
</pre>
 
=== Example in [[Quick Basic]] ===
<pre>
// Hello World in QBasic
CLS
phrase$ = "Hello World!"
PRINT phrase$
END
</pre>
 
=== Example in [[Actionscript]] ===
<pre>
// Hello World in Actionscript
trace("Hello World!")
</pre>
 
=== Example in [[Javascript]] ===
<pre>
// Hello World in Javascript
document.write("Hello World!")
</pre>
 
== Hello World in Other Languages ==
*[[AIML]]
*[[Erlang_programming_language/Tutorials#Examples|Erlang]]
*[[MySQL/Tutorials|MySQL]]
*[[Prolog]]
 
== See also ==
 
[[99 Bottles of Beer]]


== External links==
== External links==


[http://www.roesler-ac.de/wolfram/hello.htm The Hello World Collection] in more than 300 programming languages
[http://www.roesler-ac.de/wolfram/hello.htm The Hello World Collection] in more than 300 programming languages

Latest revision as of 10:02, 16 July 2013

This article is a stub and thus not approved.
Main Article
Discussion
Related Articles  [?]
Bibliography  [?]
External Links  [?]
Citable Version  [?]
Code [?]
 
This editable Main Article is under development and subject to a disclaimer.

A Hello World computer program, as first introduced in the book The C Programming Language, is a very short program that typically just prints a word or two of output to a console. Such a program is often one of the first programs that a programmer writes when learning a programming language, as it provides a cursory introduction to the language's syntax and output.

Hello World as a first program

In teaching a new language, there arises a need for a minimal, 'first phrase' to introduce students to the new language. In natural language, this is often "Hello, my name is John" or a variation thereof. The equivalent in computing is the program that says, prints, or displays "Hello, World!" or something else to that effect. Such programs, regardless of the actual wording, are called "Hello World" programs. The program is usually not meant to display the features or design of a language, since printing simple strings is seldom the main focus of a language. Instead, the example aims to give some 'feel' for the language, its basic syntax and the minimal structure of a program. Despite the apparent simpleness of the example, such programs vary greatly in their design from language to language.

Kernighan & Ritchie's Hello World

Brian Kernighan and Dennis Ritchie's book The C Programming Language was the first book to use Hello World. The example, essentially as it appeared in the later, ANSI C standard-conformant, edition of the book was as follows:

#include <stdio.h>

int main(int argc, char *argv[]) {
    printf("Hello, World!\n");
    return 0;
}

Limitations of Hello World examples

In some languages, it is not a particularly useful way to demonstrate the key benefit of using that particular language. Functional programming languages like Haskell, OCaml, F# and the Lisp family often substitute a mathematical problem like calculation of factorials in place of Hello World examples.

Consider a language like Clojure, a Lisp-derived dynamic language on the Java platform. Learning how to write Hello World is of less interest to a Clojure programmer than learning how to do a task that is not trivially easy to accomplish in Java, the language many Clojure programmers are initially familiar with.

Similarly, languages designed primarily for running concurrent, high-performance services (like Erlang, Scala etc.) are not best served by showing Hello World examples, and so many prefer to show how to construct concurrently operating, multi-threaded services like HTTP servers.

Browser-based JavaScript is another example of a language not best served by Hello World examples: these are often implemented using document.write, which is not considered a good technique anymore.


External links

The Hello World Collection in more than 300 programming languages