Jump to content

Talk:"Hello, World!" program/Archive 1

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Wernher (talk | contribs) at 21:38, 10 February 2004 (reply to myself re (sub)sections: Assembly languages). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

"To run:" recipes unneccessary

Should all this "to run:" crap really be in the 'Hello world program' article? We don't seriously expect everybody to have a GNU/Linux system with complete development environment installed. --Jizzbug

Hello world tradition (BCPL)

The tradition of using "Hello world!" as the test message was probably started by its use as an example program in the book The C Programming Language, by Brian Kernighan and Dennis Ritchie.

I think so too, but somone (not me!) on the BCPL page claims it started in BCPL. --drj
(ext lk) http://cm.bell-labs.com/cm/cs/who/dmr/bintro.html
In 1997, Dennis Ritchie says: 'so far as Brian and I can remember, the Tutorial contains the first instance of a "Hello, world" program.' The Tutorial in question is (ext lk) http://cm.bell-labs.com/cm/cs/who/dmr/btut.html . It is for the B programming language, and was published internally at Bell Labs in January 1973. The program could be even older (the Unix people had switched to C for almost everything by then; the heyday of B on Unix was perhaps 1970-71). But January 1973 is the earliest surviving evidence. This is a few years before "The C Programming Language" book, and obviously a precursor to it, since the same people are involved.
It would be interesting to hear more details of the BCPL claim. BCPL is the main inspiration for B, so it is possible someone doing B had seen the hello world in BCPL and "translated" it. Ritchie and Kernighan 24 years later would not necessarily remember this. On the other hand, it is possible some later reporter heard that hello world was invented in B and misreported this as BCPL. We need more details of the BCPL claim, preferably including a date.

Java Swing example

The Java Swing example is excessively long. It should only be a half-dozen lines longer than the console example. Ed Poor

Good point. I'll put up a more reasonable one. The other option is to not have a GUI one at all, but I'll probabl lose that argument. --LDC

"Evolution of a Programmer" joke

Would it be terribly off topic to include all the "Hello world!" examples from the old Evolution of a Programmer joke, possibly as a subpage? I don't want to go to the trouble of looking it up and copying it if it's just going to get deleted as off-topic.

It's really not on topic, so someone will likely remove it. --Stephen Gilbert

Java GUI example

The "Java GUI" example seems excessively long. Did someone put that in there on purpose, to make the point that Java is a verbose language? I put in a 5-line Java applet example in rebuttal, if that was their purpose. -- Ed Poor

I put that one in, and for the same reason: whoever put in the original "Java GUI" example put in one that was three times as long, made it look like Java GUI programming is a real mess. I shortened it down to the current version, which really is about as small as you can get a standalone Java GUI appication. Of course applets can be even smaller, because they aren't standalone--they depend on an enclosing application. --Lee Daniel Crocker
I took out the following, because it's not a Hello, world program. No one would use code as long and complex as this to test whether their compiler is working. Java always comes with the Appletviewer, which would run the 5-line program I supplied. Java program are rarely stanalone, in that they require the JVM to run. Likewise a VB program requires 6 MB or more of runtime DLLs and EXEs to run, and all Windows GUI programs require the Windows API to run. Ed Poor
I'm putting it back, because your exlanation here is mostly wrong. Most JVMs /do not/ come with "appletviewer": Sun's do, but there are lots of others that don't (For example, I use GCJ, a Java native compiler, that doesn't). Also, "Hello world" programs are frequently used to test more than just basic compilers, but also libraries and APIs: it is quite common to test a communications library by sending a "Hello world" message, or test a GUI library

by drawing a "Hello window". This program really is a good example of GUI programming in Java, and is far simpler than a GUI program would be using many C libraries. It might look better compared to something like a Windows GUI "Hello world", or a GNOME "Hello world". Maybe those could go into a separate section?

Yes, thanks. Thus the selfish Java meme propagates itself. Ed Poor

Brainfuck example

I just replaced the brainfuck example with a more concise one written by Urban Müller, who made brainfuck. -Daniel.

C example mess-up

Jizzbug messed up the hello world C program about a month ago - he removed the return statement (required in classic ANSI C) and the return type of main (required in C99 / ANSI 2000). I have corrected this, but he also modified the programs for several other languages, and may well have damaged these too; it would be useful if people who know these languages could check that all is well. --Zundark 18:10 Feb 5, 2003 (UTC)

Shell script interpreter call

I wonder if it's a good think to keep the comment calling the interpreter (like #!/usr/local/bin/perl). It's specifically unix and there is a way to run the program without this comment. Ericd 23:54 Apr 25, 2003 (UTC)

I think they should be removed. --Zundark 08:34 Apr 26, 2003 (UTC)

Hello world string tradition

From the Wiki article:

"the tradition of using "Hello, world!" as the test message
 was probably started by its use as an example program in
 the book The C Programming Language, by Brian Kernighan
 and Dennis Ritchie."

If you actually look at what that book published, you find not "Hello, world!" but "hello, world" . Why do we use the modified form in this Wiki article? - Bevo 12:33, 17 Aug 2003 (UTC)

SQL example

Is this not valid SQL?:

SELECT 'Hello, world!' AS Greeting;

It works at least in PostgreSQL and mySQL, and avoids the creation and destruction of an unnecessary table. --FOo 12:57, 5 Sep 2003 (UTC)

Embedded literal strings

There is presently a long rant on this page about how all the example programs have embedded text and this is bad practice because such strings cannot be automatically replaced by translations into the user's native language. This is factually inaccurate (some environments allow translation of embedded strings, others do not) and non-NPOV (whether not string separation is good practice is controversial, but it's presented here as universally agreed).

I tried to rework the rant into a brief mention of the issue and a cross reference to Internationalization, where the topic chould be discussed more evenly and at length, but I cannot make it brief without making it unclear. And I'm wondering whether this is an appropriate place to mention this at all. The more I think about it, the more totally offtopic this seems. Thoughts?

Zack 06:19, 10 Sep 2003 (UTC)


Well said, Zack. It would be hard to work that other topic in appropriately with this topic.
I killed it. Zack

GTK / Windows API examples

Is the GTK exemple serious ?

Ericd 08:57, 13 Sep 2003 (UTC)
It's not the canonical GUI "hello world" program in my book, but tastes may differ. (The way I learned it, a GUI "hello world" is supposed to pop up a window showing that text, and obey the standard quit commands for that GUI -- it may or may not have a quit pushbutton too.)
Zack 04:16, 14 Sep 2003 (UTC)
The standard "hello world" app for the Windows API that I've seen is similar also. According to Petzold (via [1]): "The original hello-world program in the Windows 1.0 SDK was a bit of a scandal. HELLO.C was about 150 lines long, and the HELLO.RC resource script had another 20 or so more lines... Veteran C programmers often curled up in horror or laughter when encountering the Windows hello-world program". I have a textbook with a Windows API hello-world spread over 3 source files plus a header file -- one for WinMain and the message loop, one for initialising the class and the window, and one for the paint procedure. The program creates a proper overlapped window, with "Hello world" in the client area. Using MessageBox() really is cheating. -- Tim Starling 04:42, Sep 14, 2003 (UTC)
Is this good? After seeing your comment I was going to put it in, but I was afraid someone would change it right back...
   #include <windows.h>
   LRESULT CALLBACK WindowProcedure(HWND, UINT, WPARAM, LPARAM);
   char szClassName[] = "MainWnd";
   HINSTANCE hInstance;
   int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
   {
     HWND hwnd;
     MSG msg;
     WNDCLASSEX wincl;
     hInstance = hInst;

     wincl.cbSize = sizeof(WNDCLASSEX);
     wincl.cbClsExtra = 0;
     wincl.cbWndExtra = 0;
     wincl.style = 0;
     wincl.hInstance = hInstance;
     wincl.lpszClassName = szClassName;
     wincl.lpszMenuName = NULL; //No menu
     wincl.lpfnWndProc = WindowProcedure;
     wincl.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1); //Color of the window
     wincl.hIcon = LoadIcon(NULL, IDI_APPLICATION); //EXE icon
     wincl.hIconSm = LoadIcon(NULL, IDI_APPLICATION); //Small program icon
     wincl.hCursor = LoadCursor(NULL, IDC_ARROW); //Cursor

     if (!RegisterClassEx(&wincl))
           return 0;
     hwnd = CreateWindowEx(0, //No extended window styles
           szClassName, //Class name
           "", //Window caption
           WS_OVERLAPPEDWINDOW & ~WS_MAXIMIZEBOX,
           CW_USEDEFAULT, CW_USEDEFAULT, //Let Windows decide the left and top positions of the window
           120, 60, //Width and height of the window,
           NULL, NULL, hInstance, NULL);
     //Make the window visible on the screen
     ShowWindow(hwnd, nCmdShow);

     //Run the message loop
     while (GetMessage(&msg, NULL, 0, 0))
     {
           TranslateMessage(&msg);
           DispatchMessage(&msg);
     }
     return msg.wParam;
   }
   LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
   {
     switch (message)
     {
     case WM_CREATE:
           CreateWindow("STATIC", "Hello, world!", WS_CHILD | SS_NOTIFY | SS_SIMPLE | WS_VISIBLE, 15, 10, 80, 20, hwnd, NULL, hInstance, NULL);
           break;
     case WM_DESTROY:
           PostQuitMessage(0);
           break;
     default:
           return DefWindowProc(hwnd, message, wParam, lParam);
     }
     return 0;
   }

- Evil saltine 05:29, 14 Sep 2003 (UTC)

Why does that create two windows? Or am I confused? I don't know Windows GUI programming at all. Would a programmer really write all that, or would they use a higher level "toolkit" library to do the grunt work?
Anyhow, I wonder if there should be a separate page for GUI hello world programs. They do tend to be much longer than the simple "print text" variety, and are not really examples of programming in a given language. They are instead examples of programming to a given API (which may or may not imply a language; Tk for instance can be used from several different languages).
Zack 17:32, 14 Sep 2003 (UTC)
One "window" is the actual window, and the other is the text. That's the way it would probably be written... but I don't know for sure.
Evil saltine 21:02, 14 Sep 2003 (UTC)
In my experience, a toolkit is usually used (although they're not called toolkits). Microsoft's MFC is the most popular, although personally I'm more familiar with VCL. Both are basically wrappers, they don't provide significant functionality like GTK does. Yes, there are two windows: one overlapped parent window and a static text child window. MS Windows programmers have a different definition of the word "window" to ordinary people: controls such as buttons, text boxes, etc. are actually child windows. The hello world program I was referring to didn't create two windows like that, it just used TextOut in response to WM_PAINT. -- Tim Starling 07:51, Sep 15, 2003 (UTC)

More (sub)sections suggested

I suggest we create a (sub)section "Script languages", and perhaps others, to make the article a little more navigable. I'll work on this if no one else does and not too many strongly discourage it. --Wernher 06:22, 17 Dec 2003 (UTC)

Hmmm, let me try to squeeze in another line in this heated discussion. :-) To tidy up the article I also suggest "Assembly languages" to be a section instead of it being a subsection under Line-oriented languages. No protests => 'do it'. --Wernher 21:38, 10 Feb 2004 (UTC)

PostScript example variant

Postscript: Hello world with shadow.

(Hello world)
/Times-Roman findfont setfont 300 50 moveto [0 100 -100 0 0 0] concat /X
{gsave .01 setlinewidth dup stringwidth pop .2 add dup neg exch 0 0 -1 4
-1 roll 0 0 1 rlineto rlineto rlineto rlineto stroke grestore .1 .2 rmoveto
dup show} def gsave [1 0 2 -.8 0 0] concat .8 setgray X grestore X showpage