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

47 comments

  1. My submission by nharmon · · Score: 1, Funny

    10 for I = 1 to 10
    20 Print "all your base are belong to us"
    30 Next I

    1. Re:My submission by bobbyjack · · Score: 1

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

      With a limit of 500 lines and 80 columns? Yeah, whatever.

    2. Re:My submission by secretsquirel · · Score: 1

      10 Print "Prog to gain enormous wealth in 3 lines!"
      20 ????????
      30 Profit = outputfromline20

  2. DeCSS by ZioCantante · · Score: 5, Informative
  3. Slashcode by scumbucket · · Score: 2, Funny

    Can Slash be included in this? Surely there are 500 great lines in it SOMEWHERE.........

    --
    CMDRTACO CHECK YOUR EMAIL!
  4. 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 Anonymous Coward · · Score: 0

      They didn't ask for a program and an essay. So there you go, flunked :)

    2. Re:All-time most-useful open-source program by Otter · · Score: 1
      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. ;-)

      I don't have a Mac in front of me, but doesn't the default creation of projects in Project Builder give you Hello World in Objective C or Java?

    3. 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.
    4. Re:All-time most-useful open-source program by TomorrowPlusX · · Score: 2, Interesting

      Pretty much yes; but the thing is Cocoa programming isn't something you pick up by reading API docs. Cocoa programming is *different*, and until something makes you grok it, it will be baffling.

      I'd written Win32, BeOS, GTK, Qt and Java AWT/Swing apps, so I figured Cocoa would be just a matter of adaptation, since the above systems were all ( with the exception of Win32 ) basically the same, just with slightly different semantics.

      I was shocked to realize that Cocoa is its own thing, and is completely and utterly different ( albeit, it shares some basic ideas like "views" and "events" ).

      But I bought a few books, did the tutorials, and then whammo it all made sense. My eyes were opened, and I understood.

      --

      lorem ipsum, dolor sit amet
    5. Re:All-time most-useful open-source program by Anonymous Coward · · Score: 0

      "Sticking feathers up your butt does not make you a chicken"
      -Tyler Durden

      The same goes for being able to code "Hello, World!"

    6. Re:All-time most-useful open-source program by jc42 · · Score: 1

      Heh, heh; yeah.

      But just presenting the "Hello, world!\n" program would probably just get a "Huh?" response from most readers. If you're going to stick your neck out and propose something so apparently trivial, you'd better also present a good argument justifying such a proposal, by explaining the problem being solved and why this program solves it.

      In this case, it's sorta fun to explain why a trivial program is more significant than all the non-trivial approaches that you usually see to handling this problem.

      --
      Those who do study history are doomed to stand helplessly by while everyone else repeats it.
    7. Re:All-time most-useful open-source program by Anonymous Coward · · Score: 0

      Unless of course you used NeXT boxes back in the day.. then everything *ELSE* looks really weird and bloated.

      It's pretty amazing how advanced the NeXT system was, it did everything so elegantly and used design patterns before they were in vogue (interesting how a lot of NeXT stuff is used as examples in the GoF patterns book).

      Too bad it never really became popular. Objective C was ahead of its time but it's showing its age these days. Apple should pick up Ruby as a rapid development language for the Cocoa frameworks, Ruby is today's elegant language that is right at home on the Mac.

    8. Re:All-time most-useful open-source program by TomorrowPlusX · · Score: 1

      I always saw them in the math department, and a friend of mine who worked at NIST was always raving about them. I wish I could have used them, as I would have spent less time wishing something beautiful existed, as it already did. My work in college kept me on macs and irix.

      Objective-C is great, and I write in it every day, but sadly, for my work I find C++ better suited. So be it, I can at least write my GUIs in Objective-C.

      And, as you mention ruby, there's an article on Oreillynet today about RubyCocoa. I've printed it to read on the train home tonight.

      --

      lorem ipsum, dolor sit amet
    9. 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.

    10. Re:All-time most-useful open-source program by jc42 · · Score: 4, Interesting

      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.

      And you really should call exit(0), rather than using return. A sensible system will use the return value of main() as the exit status, but there have been systems (both unix and non-unix) where this doesn't happen.

      To be truly paranoid, I might note that I've seen cases where exit() returned an error, and I had to add return(0) to handle that "can't happen" case.

      It's amazing how many things can go wrong. I've long liked the theory that programming is a kind of computer game. When your program does its job correctly, you get a point. When something in the system can find a way to misinterpret what your code said so that it goes berserk, the system's designers get a point.

      This is one of the more challenging games in existence. But we get paid well to play it.

      --
      Those who do study history are doomed to stand helplessly by while everyone else repeats it.
    11. Re:All-time most-useful open-source program by Anonymous Coward · · Score: 3, Funny

      > In the original "C bible", Kernigan & Ritchie gave us the program:
      >
      > main() {
      > printf("Hello, world!\n");
      > }

      Unfortunately, a real hello world in C (http://ftp.gnu.org/gnu/hello/) is too large for this competition.

    12. Re:All-time most-useful open-source program by cpeterso · · Score: 1


      On which platforms does exit() return an error? I thought exit() returned void. And you should not should not return 0 or 1 from main(). You should return EXIT_SUCCESS or EXIT_FAILURE.


      #include /* for EXIT_SUCCESS and EXIT_FAILURE */
      #include /* for printf() */

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

    13. Re:All-time most-useful open-source program by E_elven · · Score: 1

      'Used patterns before they were en vogue'? That's the point of patterns: they're formal descriptions of different software engineering solutions to common scenarios.

      --
      Marxist evolution is just N generations away!
    14. 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.
    15. Re:All-time most-useful open-source program by jc42 · · Score: 1

      Interesting? Where's the "funny" moderation here?

      Nearly 20 years ago, RMS wrote a nice parody of what the AC was talking about. See his man(1) page for the GNUecho command.

      Needless to say, GNUecho's source would also be far too big for this contest.

      Now would someone please add a "funny" mod to the parent?

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

      On which platforms does exit() return an error? I thought exit() returned void.

      Well, I don't rightly recall; it's been a few years. And, of course, the man pages all tell you that exit() and _exit() don't return. In my experience, you shouldn't believe this. I've seen it happen too many times, and muttering "That can't happen" doesn't change things. When it does return, I have found that I can assign its value to an int variable. If the conditions are reproducible, I get the same return value from exit() each time, implying that the value may be meaningful. So on a few systems, exit() simply isn't implemented correctly. Griping doesn't fix it; paranoid programming does.

      You should return EXIT_SUCCESS or EXIT_FAILURE.

      Hey, I've actually seen this! Not often, granted.

      One problem with EXIT_FAILURE: How do you specify the exit status? Now, we both know that the actual status isn't always meaningful. But if you're working on an app that contains a flock of separate programs that call each other, it can be very useful to produce a meaningful exit status, so the parent has a clue about the failure. 8 bits isn't enough for all cases, of course, but it suffices in a surprisingly-large fraction of the cases. You can augment it with a stderr message in the remaining cases.

      Anyway, one of my ongoing gripes with a lot of unix software is that the exit status usually is just binary, so the parent process can't give many clues about why a subprocess died. The EXIT_SUCCESS and EXIT_FAILURE syms merely encourage people to write software that "doesn't work and doesn't tell me what's wrong". We need less of that, not more.

      --
      Those who do study history are doomed to stand helplessly by while everyone else repeats it.
    17. Re:All-time most-useful open-source program by excessive · · Score: 1
      The standard return type for "main" is an int.

      e.g.:

      int main(int argc, char *argv[])
      Borrowed from The online version of The C Book, second edition (Yeah, its a historical book but never mind) (You can tell how often I use exit and the return values from main... (Embedded systems, eh?))

      Also, a quick look at part of the DJGPP FAQ should help.

      Finally, the exit stuff from the same source, suggests EXIT_SUCCESS and EXIT_FAILURE for portability (Non POSIX systems, for example) and that some systems will truncate the return value to 8 bits (0 to 255) for example.

      exit and return should really do the same thing when they're in main (Assuming they're not within a locally declared function!) but compilers have bugs just like other software.

      The reason UNIX software returns a pass or a fail is more to fit in with other systems, I think. You could sit and define errors all day and some systems would still define all errors as 1 and all non-errors as 0. Besides, where do you stop with the errors? And then you have to convince the people writing the software to adopt them. Sometimes its hard enough to get them to give a pass or a fail...

      Anyway, I suppose this is a little offtopic.

  5. What determines the "best"? by Metasquares · · Score: 1

    Best is an ambiguous word. Are they talking about code quality, readability, usefulness, adherence to the open source definition, ...?

    1. Re:What determines the "best"? by growlydog · · Score: 1

      I think the point of the exercise is to show the viability of Open Source as a new platform (lol @ 'new'). So I think that "best" means to write the best program. I don't think the judges are going to be comparing code to see who has the best formatting or whatnot, but rather, what the finished product looks like. Thats how I would judge this contest. When its over, I want to say "DAMN! You wrote THAT in ONLY 500 lines of code???" Kind of like the old 64k demos people used to write all the time.

      --
      my sig was dubm so i took it out.
    2. 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.

    3. Re:What determines the "best"? by ClosedSource · · Score: 1

      Well, for those that believe LOC is a productivity measure, this will prove that Open Source developers are not as productive.

      Seriously though, wouldn't it be better to drop the 500 line gimmick and just solicit the best work? It's not as if code size is going to tip the balance from closed to open source.

    4. Re:What determines the "best"? by Nevyn · · Score: 1

      Seriously though, wouldn't it be better to drop the 500 line gimmick and just solicit the best work? It's not as if code size is going to tip the balance from closed to open source.

      I assume it's a practical matter. I can look at an entire program in 500 lines of code and come to a conclusion within a short amount of time. If given 15,000 lines on the other hand I'd simply have to miss bits.

      --
      ustr: Managed string API with ave. 44% overhead over strdup(), for 0-20B
    5. Re:What determines the "best"? by ClosedSource · · Score: 1

      Why do you have to look at the code at all to find out which application is best? Is this a code review or a contest?

    6. Re:What determines the "best"? by dtfinch · · Score: 1

      There are a lot of 4k demos too, most of them quite good. The first I saw closely resembled the game Descent.

      I wrote an asteroids clone in javascript that's roughly 500 lines, but I wasn't aiming for small size. It uses hundreds of divs for rendering. Best viewed in IE or a very recent FireFox, as older Mozillas have scalability/performance problems with it.

  6. Mail::Sendmail by jonadab · · Score: 3, Interesting

    Mail::Sendmail is technically 807 lines, but over 400 lines of that is
    documentation (POD) after the __END__ of the actual program code; if you
    just count the code itself, it's 388 lines.

    Oh, and unlike a lot of modules, it's got almost no dependencies: you've
    gotta have a network connection, and Perl, and that's it.

    And the interface is very convenient to work with.

    --
    Cut that out, or I will ship you to Norilsk in a box.
  7. The best one-line open source program by Snaapy · · Score: 4, Funny

    Whatever we can come up with, Perl programmers do it with a single line.

    1. Re:The best one-line open source program by Anonymous Coward · · Score: 0

      See perlgolf

  8. Need to make the first public function static by ufnoise · · Score: 1
    db.h:32: warning: `class SQLiteDB' only defines private constructors and has no friends

    This can be a spurious warning that I had to do a lot of searching for on google groups to debug my own code. It wasn't really documented that the first public: function listed needs to be static. I haven't seen the code you mention, but I assume a static function would be used to instantiate this object. Later versions of g++ (3.3.2) appear to be able to recognize a static function exists somewhere in the public: section, even if not the first.

  9. 500 Lines of What? by RAMMS+EIN · · Score: 2, Insightful

    What are the further constraints on the code? Any restriction of what languages to use? Or what libraries to use with them?

    --
    Please correct me if I got my facts wrong.
  10. syncmail by khanyisa · · Score: 1
    syncmail is less than 500 lines, and is used by loads of people all over the world ...

    nice example of an open source project as its a piece of infrastructure that links other things...

  11. Much to learn, grasshopper by monoi · · Score: 1
    BBC Computer 32K

    Watford Electronics DFS 1.44

    BASIC

    >10 Print "Prog to gain enormous wealth in 3 lines!"
    >20 ????????
    >30 Profit = outputfromline20
    >RUN

    Mistake at line 10
    >_
  12. This is too easy! by Anonymous Coward · · Score: 0

    500 lines of great open source code! I can do that!

    10 FOR X=1 TO 500
    20 PRINT "GREAT OPEN SOURCE CODE"
    30 NEXT X

    Now, where do I collect my cheque?

    --
    AC