Slashdot Mirror


Sought: 500 Great Lines Of Open Source Code

The editorial staff of the Open Source Annual 2005 writes "Be part of the Open Source Annual 2005 and enter our hacker contest for the best 500-line open source program. The best program will be printed in next year's issue of the book. Following lasts year's huge success with our Open Source Annual, a mostly German reader concerned with the various aspects of open source, we are currently busy compiling the second edition of the annual which will be released next March for the CeBIT 2005 in Hannover. Aside from articles on subjects like economics, law and open innovation, to name but a few, we plan to print the source code of an open source software program." (Read more below.) "Any OSS program whose source code is no more than 500 lines of 80 characters may enter the competition. Anything that tickles your fancy, from online pong games to 'OpenGotchis,' may be submitted until October 15 to winner@ig.cs.tu-berlin.de. Make sure to document your code within the file submitted. You may also want to add a couple of explanatory lines should you so wish.

An online vote will be held this December on our website Think-Ahead.org. Not only will the winner's code make it into the book but he shall also receive a copy of both the 2004 and the 2005 annual."

6 of 47 comments (clear)

  1. DeCSS by ZioCantante · · Score: 5, Informative
  2. All-time most-useful open-source program by jc42 · · Score: 3, Informative

    In the original "C bible", Kernigan & Ritchie gave us the program:

    main() {
    printf("Hello, world!\n");
    }

    This is one of the most significant programs of all time, and I've used it repeatedly (in many languages) when working on either a new system, or one that is exhibiting baffling misbehaviors. As K&R pointed out, when you get this program to run, you have solved many of the most significant problems in getting any program to run:

    1. You've managed to run an editor and create a file. (And that file is in a format that the compiler can read; a non-trivial problem on some systems. ;-)

    2. You've figured out how to run the compiler, feed it a source file, and link the output with the appropriate system library.

    3. You've successfully told the system to run the compiled program, and also successfully got its output in a form that you can read it.

    The advantage to this program is that it does all the above, and nothing else. So if it doesn't work, there's no confusion trying to figure out what in the program is screwed up. It's clear that you have a problem with the basic mechanics of creating a working program, and the problem isn't in your code.

    I've also had some fun arguing that "Except for a few missing features, we have our program, and it works. Now what features do we need to add?" I've also been disappointed when nobody points out that the above program does have one significant bug that should be fixed first.

    An interesting variant that I've presented in several projects that dealt with GUIs: A tcl/tk (wish) version of this is:

    button .h -text "Hello" -command {puts "Hello!"}
    pack .h

    If tcl and tk are installed correctly, feeding this to the wish command will pop up a little window with a button labelled "Hello". When you click on it, it writes "Hello!" to the window where you ran the program.

    It's interesting to challenge the developers to produce a program that does nothing but this, in whatever language the project leaders have decreed. It's amazing how much code this usually takes, and how long it takes to get it to work correctly.

    I've seen many attempts to do this on Windows, generally with much grief and weeks of effort, with utterly different code resulting on nearly every new release. And after a year, I still haven't learned how to do this with Apple's GUI on OSX. (Of course, the usual explanation is that I'm an 1D10T. ;-)

    Actually, I usually do a somewhat longer wish example:

    button .h -text Hello -command {puts "Hello!"}
    button .x -text Quit -command exit
    pack .h .x

    This solves the problem that with some GUIs, using the "X" widget on the window border destroys the window but doesn't tell the app to exit.

    --
    Those who do study history are doomed to stand helplessly by while everyone else repeats it.
    1. Re:All-time most-useful open-source program by SandSpider · · Score: 2, Informative

      No, it creates a blank window that you can move, resize, close, etc, but it displays no text. In order to display the text, you'd have to either rename the window, put a text controller into the window and modify the properties of that, or display a dialog with the text of your choice. The easiest is to change the text of the window.

      If he's just playing around, it's not surprising that he's having trouble. XCode and Cocoa are extremely easy to learn and use, but you actually have to do a bit of work to learn to use them. I would suggest looking at this article from O'Reilly on the subject. It's a basic text editor, which is more complex than Hello World, but should get him in the right direction.

      =Brian

      --
      There is nothing so good that someone, somewhere, will not hate it.
    2. Re:All-time most-useful open-source program by ByteSlicer · · Score: 2, Informative

      I've also been disappointed when nobody points out that the above program does have one significant bug that should be fixed first.

      Well, you should add the line "#include <stdio.h>" at the top. Also your main() function should return an int, although most C compilers will let you get away with that.

    3. Re:All-time most-useful open-source program by aridhol · · Score: 2, Informative
      Actually, there's nothing in the program that requires stdio.h, though of course it's good form to #include it for when someone wants to add features to the program.
      Actually, printf() is a variadic function (int printf(const char *fmt, ...)), which does require stdio.h.
      --
      I can't say that I don't give a fuck. I've just run out of fuck to give.
  3. Re:What determines the "best"? by mindhaze · · Score: 3, Informative

    An online vote will be held this December on our website

    They're talking about which program people voted for the most.