What Can You Build in 600 Lines of Code?

January 24, 2008

Joseph Cooney reminds us that, in January 2005, 37signals went live with a product they built in 579 lines of code:

You read that right, not 60,000 or 600,000 but instead a commercial project written in less than 600 lines of Ruby code. When I first saw this number I was incredulous -- I've written stored procedures that are longer than that. My current project has more lines of configuration than that. I've even written console apps in notepad, and compiled from the command line with more lines than that, because I thought they were so small they didn't need a whole .sln and .proj file, and yet here is 37signals going live with a product that is just 579 lines of Ruby.

As noted in the Rails blog, the original product launch was covered on Ruby language creator Matz' blog in his native Japanese. Surprisingly, the relevant facts are still readable:

matz makes notes of ta-da list and Rails

Of course, a simple lines of code number isn't the entire story-- they actually built the entire Rails framework first to support building small apps like ta-da list. None of the required Rails framework code, nor any of the the necessary stylesheets, JavaScript, HTML, and so forth, are included in that number. Still, I agree with Joseph: it's an impressive achievement, and it can lead to some interesting thought experiments:

I have a few interesting product ideas from time to time. What is the absolute minimum amount of code I could write that would make those ideas work? If I'm prepared to operate within the constraints of the platform (whatever that is) how much effort would that save me? How many more "interesting ideas" could I turn into working products if I was prepared to follow these constraints? How many more cool/useful things could you build if you promised yourself that each one would only be 600 lines of code?

What can you build in 600 lines of code? Think of it as an exercise in minimalism. Does your preferred language or environment allow you the freedom to create something interesting and useful with that constraint in place?

Posted by Jeff Atwood
188 Comments

Here, let me post my 600 lines of code in the comments to your post!

And you thought the FizzBuzz post was bad :)

BradC on January 24, 2008 3:35 AM

FizzBuzz in 600 lines or less... Kinda like "Hello World!" in less than one line of code. (In other words... don't bother, please.)

Good food for thought on writing concise and useful code. The key here is also NOT to turn in it into an exersize in obfuscation.

Thanks for this little tidbit!

John Baughman on January 24, 2008 3:54 AM

Maybe I'll go through some C app I've got, and remove the newline character from all lines that don't start with #.

Then again, maybe not.

Joshua on January 24, 2008 4:01 AM

What can't i write in one line of code and a little bit of insanity and an overused scrollbar?

Darren Kopp on January 24, 2008 4:12 AM

with 600 line of code,
I can wipe out your hard drive
and fill it with useless junk
Isn't that a lot for 600 line only ?
Frankly, if the point is to discuss which
programmer langage is more concise than other,
I would have expected a more instructive article.
And no, Ruby on Rail doesn't look yet attrictive to me.

mehdi on January 24, 2008 4:27 AM

Well, I wrote a small webapp in PHP-SQLite for the library i work in that manages the entire movie loan process in less than 400 lines, XHTML+CSS included. Ok, it's far from those web-two-dot-zero features, but it does the job... :)

Camillo B on January 24, 2008 4:27 AM

I remember someone writing a demo reversi game in ASP where the user played against the computer. I believe it was about 142 lines of total code HTML and VBscript.

Lee on January 24, 2008 4:28 AM

I'm sure Larry Wall could have written that in 600 characters of Perl

maeghith on January 24, 2008 4:31 AM

#include "WordKiller.hpp"
int main()
{
WordKiller theApp(;
return theApp.run();
};

600 lines of Ruby? Try something ten times as good as Word, in just 6 lines of C++ (or 2, if you remove unnecessary breaks.)

Oh, yes, the WordKiller.dll "framework" will be a little larger, but what the hey. Noone else ever considers the "framework" size when harping on about their one-liners, so I


More seriously, here's what I can write in 600 lines of legitimate code: a product that 50 thousand other developers could duplicate in a weekend. I could "write a product" but building a business would require something more, and not just in terms of code size.

If you have 579 lines of code plus a great deal more code that you're discreetly ignoring, then you might have something non-trivial.

Bob on January 24, 2008 4:32 AM

oops, I forgot I was referring to the 37 signals product.

And to add: XDDDDD

maeghith on January 24, 2008 4:33 AM

I once wrote a (horizontal) star scroller in 19 bytes. Switch to mode 13h, create random stars and make a loop that moves them. In 19 bytes. I'm still so proud of that :)

J. Stoever on January 24, 2008 4:38 AM

Heh - I be it could be done as a APL one-liner - but no one would be able to read it, and figure it out

KG2V on January 24, 2008 4:44 AM

Is something they don't charge for considered commercial? It's a fairly trivial program, like Bob pointed out, one a competent programmer could probably code in around a weekend. (http://railsrumble.com/)

It is certainly nice that something useful can be created in this time frame, though.

Brennan on January 24, 2008 4:50 AM

As a user of BaseCamp, I've delt with the short comings -- such as no Spell Check or HTML edit view. But all-in-all, for the basic $10 a month plan it is worth the money.

Me on January 24, 2008 4:51 AM

As a rails developer, I would like to say that that is 600 lines of code they actually wrote. A frozen rails 2.0.2 has 171,098 lines of code. Just didn't want to have anyone misled.

blazes816 on January 24, 2008 5:01 AM

I don't know about writing less than 600 lines of code but I'm sure this should serve as good example to application and framework developers that writing short and clear code shall be possible. How many APIs have we used that required us to do so much for so little (hello Java ;) ) ? How many applications were bloated with thousands of lines of code that could be reduced to half the count just by cutting on patterns and fancy "we'll make it reusable because someone might think of wishing to reuse it" code ?

Alex on January 24, 2008 5:05 AM

Tell me, does javascript count as loc? I can't read chinese, so it's hard to tell if it's just lines of ruby? Anyone care to translate?

I watched Joe Stagner write an AJAX todo list in 20min. What can you write in 20 min? http://download.microsoft.com/download/0/f/6/0f651a0f-6f2b-4497-b061-e1b2825e22e0/MSAJAX-ToDoList.wmv

Apparently all I can write in 20 min is a useless blog comment.

20min on January 24, 2008 5:15 AM

Here is PhotoShop in 7 lines of code.

#include "Photoshop.h"

int main(int argc, char **argv)
{
Photoshop *app = new Photoshop();
app-Run();

return EXIT_SUCCESS;
}

smallstepforman on January 24, 2008 5:24 AM

www.bigbadjim.info:6060 has less than 600 lines of code. It is not complete, but what it is works.

I was not trying to be terse.

jim on January 24, 2008 5:34 AM

I would have to say that some of the most impressive code in terms of size to functionality are Steve Gibson's Window's programs written in assembly. http://www.grc.com/smgassembly.htm


If you have an old Windows machine, this was the most amazing screen saver program, in 200K! http://www.grc.com/chroma.htm

Steve on January 24, 2008 5:45 AM

@Darren we'll you can't write anything in Python for sure :)

Anyways one practice I do have is to write any module for a larger app to have less than 500 lines. It's not that hard but whenever I see a module that has more lines than that I reanalyze and break it into smaller more focused sub-modules

BoredGuyAtWork on January 24, 2008 5:48 AM

I wrote a python and pygame-based blackjack GUI game in just over 600 lines of code... I'm entering it in a contest, then I'm gonna open source it and release it.

Allan on January 24, 2008 5:52 AM

Since I'm fluent in Japanese, I'll translate for those that are wondering what the post says:
"
Well its a cooperative TODO application. Haven't used one myself, but I've been hearing lately that they can be very useful.
However what's really interesting is that this web app was written in Ruby On Rails, and it's just 579 lines long.
Maybe I should learn some Rails too.
"

BoredGuyAtWork on January 24, 2008 5:57 AM

My friend built a multi-million dollar web app in 2,000 lines of ruby code (including unit tests). Makes me feel kinda of ashamed of my passion in C#.

I hope BOO become more popular.

buddydvd on January 24, 2008 5:57 AM

@mehdi

dd can do that for you in 1 line

darko on January 24, 2008 6:06 AM

I think conciseness is important, but how about another constraint to this thought experiment?

Challenge:

After writing your 600 lines of code, you come up with something additional that the code should do. Then, hand it off to a fellow programmer and have them add it successfully without your help.

If you can do that, _and_ you don't fuse your brain into a smoldering bio-mass in the process, I think you just rose to the rank of Sensei-Coder :)

Thomas Borzecki on January 24, 2008 6:10 AM

I am proud of www.bigbadjim.info:6060. I have worked almost five hours on it. It is an exercise in keeping things simple. It has 504 lines of code so far, and does work.

It would be a todo list if I put "TODO" in big type at the top

jim on January 24, 2008 6:18 AM

XMonad, a window manager, was at one point less than 600 lines of haskell. Now it's around 1000, I think.

mgsloan on January 24, 2008 6:23 AM

Remember HyperCard? I wrote a lot of HyperCard applications in less that a hundred lines of code: Payroll systems, accounting systems, inventory, games, demos, etc. I started using Hypercard as a application prototyping tool, but the apps came out so nicely, I simply used the prototype as the program. Whole applications could be written in a couple of days.

My favorite was called "Stack2Text" which would dump a Hypercard stack into text script that could recreate the entire HyperCard stack again. It was a way to transfer HyperCard stacks over text only BBS systems.

HyperCard was the primary reason why people upgraded their Macs to 4Mg of memory (Remember that this is in the days most PCs still had only 640K). Hypercard needed a full Meg of memory to work.

Apple lost interest in Hypercard almost the day they released it. Hypercard languished for years. It never got much further than bitmapped black and white graphics.

David W. on January 24, 2008 6:34 AM

i wrote a php script to take info from the URL that was submitted by my friends WiFi app, to draw out a graph in a PNG image. the script is only about 250 lines

phil on January 24, 2008 6:37 AM

I build my new website using Django (python framework) in 632 lines of code, with 674 lines of html templates. This doesn't include the hacked javascript I used, nor the settings files. Pretty good though, and it's getting full of features.

http://www.shuttercal.com

Dan on January 24, 2008 6:51 AM

I wrote a weather service provider (http://forecaster.ws) in about 100 lines, and a blogging tool (http://www.subwindow.com) in about 60.

600 lines is kind of a lot =)

Erik Peterson on January 24, 2008 6:52 AM

The (Python) code for DecentURL.com was about 350 lines when I first launched it. It stabilized at about 500 lines after I'd added a few features. Now I've added some "premium services", but it's still only 900 lines.

Ben Hoyt on January 24, 2008 6:53 AM

I wrote a python web application that measures a given URL from various geographic locations using an accelerated path and a non-accelerated one and presents the difference using a Flash UI all done in roughly 360 lines of code. Its useful for my sales folks to demontsrate the value of a an Application Delivery Netwotk.

Paddy on January 24, 2008 6:58 AM

using MySuperAwesomePrewrittenFramework;

public class TadaList
{
myFramework.Scaffold();
}

This is why I'm not impressed at all with rails and line count. When you move 90% of the functionality into the MVC engine, all you really need to do is whip up a handful of views and a few controllers.

Sure, MVC is a nice architecture, but rails didn't even MVC, they just made it popular.

BTW, you could create Tadalist almost entirely in ASPX markup without writing a line of code, doesn't mean you should.

Jonathan Holland on January 24, 2008 6:58 AM

even == event.

Jonathan Holland on January 24, 2008 7:00 AM

@Other Pythons Users,
I love python, don't use it everyday, but my comment about you can't do it in Python to Darren, was that you can't write an app in one absurdly long one line of Code when using Python, which I think is a good feature as it forces code to be reasonably readable.
And in the one line code camp, I would hope that all real Javascript apps out there would be compressed into a single horrible loooooong line of code, so they don't waste my bandwidth. I guess that means it's necesarry to write a useful app in 1 line of JavaScript code :)

BoredGuyAtWork on January 24, 2008 7:15 AM

nitpick: event==invent

BG on January 24, 2008 7:26 AM

I wrote a Weewar notifier in AutoIt in ~250 lines of code. I tried writing it in c# but I gave up after about 2000 lines of code and over 18kb of different source files.

Craig Woodward on January 24, 2008 7:27 AM

This 256 byte intro (yes BYTES) is impressive: http://pouet.net/prod.php?which=3397

A 4KB intro with graphics and music, for example, http://pouet.net/prod.php?which=16373 , is also impressive.

A todo list with a HUGE framework in 600 lines of code? Not so much. I would call it "cute".

M on January 24, 2008 7:53 AM

If you think 600 lines of code is small, then you clearly are not a perl programmer.

Of course, if we start counting characters (or punctuation) I might be in trouble.

JohnV on January 24, 2008 8:19 AM

I just did Conways game of life in just over 200 lines of code: http://www.gumuz.nl/blog/lifegame-2d/

Python with Pyglet, OpenGL (consider those my rails ;)

gumuz on January 24, 2008 8:38 AM

Ruby on rails is fine for small simple sites; but when you start adding logic then you have to start coding.

It also makes assumptions about the database that are against convention, ie: naming tables in plural form.

If you want to talk about impressive, how about a raytracer written completely in ONE line of Linq?

http://tirania.org/blog/archive/2007/Nov-16.html

Andrew on January 24, 2008 8:50 AM

Yep.The Rials looks like a magic in productivity:)But an interesting news: Have you ever tried "web2py" ? In my opinion it's the best pythonic Rials! It's productivity... unimaginable :)

vahid on January 24, 2008 10:11 AM

Ruby on Rails uses a lot of code generation. Comparing it with other programs written in other languages brings up a lot of questions. Both the verbosity of the language has to be taken into consideration as well as the underlying libraries.

Take for example Java. It's got a lot of libraries that one can use. Making a desktop application would just mean that one has to use the SWING library.

Compare that to Common Lisp. Common Lisp can do the same thing that Java does, and probably even more, but are the libraries that one can use, or does one have to write everything?

One can even write a desktop application Brainf*ck, but the understanding the source code would probably require omniscience.

Jonathan Paul Madrid Abaca on January 24, 2008 10:31 AM

*in BrainF*ck

Sorry for my bad English.

Jonathan Paul Madrid Abaca on January 24, 2008 10:33 AM

I assume we're not talking about 'tricks' where you're just running external code, plugging together existing components, or having 8000 char+ lines.

So, given that:
Full applications? No.
Incredibly useful utilities? Absolutely.
Gadgets / Widgets / Plugins? Sure

Depends on what your definition of an application is I suppose.

Total lines of code is, and has always been, a poor measure of effort required. Sure, they might have legitimately only needed to bang out 579 lines - but if it took them longer to get to that point, it all becomes redundant.

That said, I'm all for expending less effort for more productivity, and if they're getting great results through rails - good on 'em!

Will Hughes on January 24, 2008 11:01 AM

You can do some really cool user interface stuff in C#.NET with WPF and Expression Blend (XAML user interface descriptions). Do all the data binding of .NET objects to XAML elements. Using other .NET 3.5 frameworks like WCF, you could probably create a networked photo sharing application in less than 100 lines of C# code.

There's a lot to be said for well-designed, productive frameworks and environments that don't make you reinvent the wheel every time you need a GUI app or a web app or a data structure or whatever.

Brendan Dowling on January 24, 2008 11:15 AM

Do not count lines of code.

This is not a programming language issue, but its about the available libraries that support it.
It is obvious, you know it, but you do not mention it. Why?

Nikos on January 24, 2008 11:24 AM

"you can't write an app in one absurdly long one line of Code when using Python"

Of course you can:

exec "absurdly long one\nline with embedded\nnewlines"

Pythoneer on January 24, 2008 11:34 AM

i could solve fizzbuzz.

Scott Elkin on January 24, 2008 11:38 AM

I'm not that impressed really...

You could do single, double and circular single and circular double linked list implementations in under 100 lines of standard c99 so you'd have at least 500 lines of space left to use them. That's a whole lot of possibilities, I bet it includes tetris! and many more puzzle games.

Now imagine what you could do with 600 lines of c# or objective-c, the sky is the limit!

The little detail that it's a web app makes it sound a bit more impressive, but then, that's exactly what Ruby was designed for.

So no... not really impressed.

kris on January 24, 2008 11:41 AM

XForms is quite good for writing short web applications. If I remove the empty lines, inline instances, comments and some static XHTML, I'm down to 487 lines for a data entry system currently in production. This features adding, editing, and removing data in three forms separated into tabs, validation against other XML files (with helps, hints, and alerts), file upload / deletion, navigation between data items and a collapsible log displaying all the entered items with the current one highlighted.

Victor on January 25, 2008 1:01 AM

I felt the need to help you, because you are so right and because many of the people who commented didn't get it. See the full post here: http://my.opera.com/alex_boly/blog/2008/01/25/writing-less-code-is-good-for-your

Briefly the idea is:

The more lines of code your software has, the greater the number of bugs.
The more lines of code your software has, the longer it takes to solve one bug.
So writing less code helps you write good software.

Alexandru Bolboaca-Diaconu on January 25, 2008 1:09 AM

Who said this code wasn't complex though? It could be 579 lines of code that are all 1000 characters long!

Honestly.. who cares how many lines of code an application is? As long as it fufills it's requirements and it's easy to maintain, that's all that matters. Not some c0ck-measuring contest to see how small you can get the source files!

James on January 25, 2008 1:13 AM

Well, not sure if it counts, but if I'd persevered it COULD have become a commercial application:

I wrote my own (VERY clunky!) word processor in Z80 assembly language for the TRS-80 in about 1980, I guess. It must have been in less than 16K bytes, probably quite a bit less, because that's all the memory my computer had. But it worked pretty well - I wrote most of a novel on it.

I remember the TRS-80 had a chess program that fitted into less than 4K of memory. Played pretty bad chess, but it did work.

David on January 25, 2008 1:23 AM

The creators of the darkbasic language (thegamecreators.com) regularly hold a competition where the entries have to form a working 3d computer game within 20 lines of code. Due to the level of functionality you can achieve with such a high level command set, this is not only feasable, but results in some great games.
However, due to each command being of such a high level of functionality, each takes a long time to execute. I think many programmers don't think about the execution complexity due to being so focused on the uncompiled code and how that looks.
It is a great practice to avoid using 20 lines instead of the 5 you actually need. I recently rewrote a class method at work and removed 50% of its code. This lobotomised code not only fixed the problem, but ran faster (no surprise there). That said, if the system had been properly designed at the beginning, that class would never have been needed.
Measure twice, cut once.

Steve Blake on January 25, 2008 1:23 AM

"Honestly.. who cares how many lines of code an application is? As long as it fufills it's requirements and it's easy to maintain, that's all that matters. Not some c0ck-measuring contest to see how small you can get the source files!"

Exactly!

All the "Oh boy, someone wrote a 600 liner which represents does cool. I should drop what I'm doing and do what that guy's using!" moaning... some people should simply take a step back and think about what they're doing. Hint: programming isn't about typing text in an editor.

People are too focussed on operating tools (e.g. a language, editor, ide). The tool isn't important, it's what you do with them and more importantly WHY you're using these tools.

The more of these same-themed blogposts are posted on this blog, the less motivated I am to read them.

Frans Bouma on January 25, 2008 1:29 AM

I've just published an internal Excel app with 832 lines of VBA code.

I think that's not bad, even though it could probably be done in less.

GUI Junkie on January 25, 2008 2:06 AM

I wrote a solunar tables calculator that performs astronomical calculations to return sun rise/set/transit, moon rise/set/transit/underfoot times, moon phase, major and minor solunar periods and some other cool stuff. The php version fits in about 700 lines including commments. The c version fits in about 800 including comments.

Doug on January 25, 2008 2:14 AM

Making it a goal to limit an application to a specific number of lines of code is, by definition, a coding horror!

Josh Stodola on January 25, 2008 2:31 AM

Please consider pointing to software that can count "lines of code" for different languages esp. PHP

Kishore Balakrishnan on January 25, 2008 2:41 AM

I remember when they used to have 1K programming contests. Your source code had to be 1K or less. Some people did some pretty creative things.

slapout on January 25, 2008 3:05 AM

guess it sorta depends on what language your talking. 600 lines of assembly barely buys you anything. someday we're all gonna be out of a job because any monkey can build software by snapping legos together :-(

jminadeo on January 25, 2008 3:29 AM

Im pretty sure that with 600 lines of code I can do some Hello World.

Almost sure!

Caxaria on January 25, 2008 3:55 AM

Pah, using frameworks and libraries is cheating.

Heck, I made a fullscreen Polish flag in DEBUG.COM in 19 *bytes*. Beat that, 37signals!

Mark on January 25, 2008 3:58 AM

to be fair ive written quite a lot of lil apps here and there that do very useful things in under 600 lines of code - to be honest though, 600 is quite a lot and is a dependant and language and style

fusi on January 25, 2008 4:05 AM

Pfffstsss.. I can write an full featured webshop with ERP system integration in 2 lines:

system = FullFeaturedWebShopWithERPIntegration(:webenabled = true)
system.processRequest(CGIRequest::instance)

yeah - its THAT simple and ONLY 2 farging lines people... ;-)

Lars Borup Jensen on January 25, 2008 4:09 AM

Why not 666 lines of code ? /sarcasm :)

TrXtR, yeah farbrausch(www.farbrausch.de) are cool, check out the debris demo from 2007: http://pouet.net/prod.php?which=30244.

Anyway, what 37signals has done is smart and elegant, but not very impressive. But the goal was ofcause to show how elegant the rails framework is. As always use(+create) the right tool for the job.

As a programmer you should be more impressed with the algorithms and impress the boss, costumer, etc. with the programming statements.

/P

Peter Palludan on January 25, 2008 4:28 AM

"Pfffstsss.. I can write an full featured webshop with ERP system integration in 2 lines:

system = FullFeaturedWebShopWithERPIntegration(:webenabled = true)
system.processRequest(CGIRequest::instance)"

And what else can you do with that? Nothing. People have done a wide range of things with RoR, one of these being a Todo list in 600 lines. It's a demonstration of the completeness and flexibility of RoR.

That said, it might only be 600 lines but it misses out a lot:
http://rifers.org/blogs/gbevin/2005/3/18/blabla_tada_in_java

[ICR] on January 25, 2008 4:35 AM

Back in the 90s there was a competition to write the nibbles (snake) game in a minimalistic way. I was somewhere 48 bytes as I remember, the winner was somewhere 37 bytes. that was a pure assembly fun.

n' on January 25, 2008 5:05 AM

I remember the days when part of the programmer's job was to write code that was as efficient as possible simply due to memory restrictions. The days leading to 2G memory and TByte harddrives have nurtured a generation of lazy and inefficient programmers.

PaulG. on January 25, 2008 5:06 AM

Hey Now Jeff,
Make everyone think 600 line what could we do. I like the screen shot too, I never knew I could read Japanese until today.
Coding Horror Fan,
Catto

Catto on January 25, 2008 5:20 AM

#include "masterlib.h"

int main(void)
{
/* some functions defined in "masterlib.h", dont forget to link it */
stop_the_wars_in_the_world();
find_cure_for_cancer();
end_poverty();
make_justice();
/* TODO: maybe call adjust_my_bank_account(); after these... */

return EXIT_SUCCESS;
}

mr_hugo on January 25, 2008 5:27 AM

I can build Hello World in under 600 lines of code

Billkamm on January 25, 2008 5:52 AM

Yeah, but...it's just Ta-Da List.

Not to crack on Ta-Da List; it's cool, but it's basically just a little thing that manipulates checkboxes, isn't it?

Evan on January 25, 2008 5:53 AM

hmm, how would you make a _solid_ computer game in that much code? it seems to me that without a _lot_ of pre-existing code (frameworks, libraries, etc.), that's going to take much more effort.

dilbert on January 25, 2008 5:55 AM

"600 Lines"
If it's only lines of code that were typed by a developer not including the framework, configuration and generated code then 600 seems a lot, there are ways of producing functioning code without little if any "lines of code".

Eoin Prout on January 25, 2008 5:56 AM

I've been hearing a lot about Ruby On Rails lately, mostly FUD. I also read an amusing article about Rails developers calling themselves "rock star coders" and creating that online persona. I'm tempted to learn Ruby On Rails but I've heard that it is "the rails way or the highway" and it forces you to design the database to meet its requirements and does not allow any SQL hacks to solve problems. It sounds like one of those frameworks that promises to save you time until you need to do something slightly unconventional and then you need elaborate hacks. Even ASP.NET is guilty of that but it is flexible enough to meet most needs.

Robert S. Robbins on January 25, 2008 5:59 AM

Yeah, Ill have to pile on with the other Perl-heads. I have written a lot of programs with less than 500 lines of code. And many of them did more than just make a to-do list. Is't a to-do list kind of a CompSci 201 homework example?

But I do like their fancy-dancy fading highlight bars and super big Myopia fontface on that site.

Chubber on January 25, 2008 6:10 AM

I recently picked up RoR, and let me tell you the installation alone was a pain in the ass. It is definitely quick as far as development time goes, but seems to be more of a fast solution for designers with little knowledge of programming.

It is interesting if nothing else, and definitely worth taking a look at.

Matt on January 25, 2008 6:16 AM

In college a friend and I would have friendly competitions to see who could write a C program to accomplish some simple task in the fewest characters. We'd then get together and compare our results and work together or further winnowing the character count.

Here's one of our results:

main(){int a=256,i,p[a],k;for(i=0;ia;p[i++]=1); for(i=2;ia;i++)if(p[i]){printf("%d ",i); for(k=i*2;ka;k+=i)p[k]=0;}}

I don't recall what this does. But I invite anyone to compile it and give it a whirl.

Scott Mitchell on January 25, 2008 6:29 AM

I'm with KG2V on this one. The old joke is that someone who really knew what they were doing could write an entire OS in one line of APL.

Mostly this points out what a crappy metric "Lines of code" is when comparing different languages. Since I don't know all that much about Ruby, other than that it is a fairly high-level language, the assumption is going to be that the application was sticking to things that could be naturally expressed in Ruby (or its libraries) easily.

So no, not horribly impressed.

T.E.D. on January 25, 2008 6:41 AM

You can actually use semicolons in Python to put multiple lines on one line like this:

print 'Line 1'; print 'Line 2'; print 'Line 3'; print 'Put as many lines as you want separated by semicolons!'

I've tested this and it works.

Valdemar on January 25, 2008 6:51 AM

80Micro (a magazine for the TRS-80 from days-gone-by) had a couple of 'One Liner' basic contests. Write a one line program, 254 bytes (less two for the line number and space) was the goal.

I believe there were hundreds of excellent programs submitted. I wrote a one line text adventure (very simple!) and a downhill skiing game, and had bytes left over.

No loading a huge library, only running in the constraints of the programming language as it came (no external libraries) or anything.

Now, I know that is not the point of this post. The point, that many have overlooked or become obsessed with proving wrong, was:

WHAT KIND OF APPLICATIONS AND HOW MANY COULD YOU CRANK OUT WITH A COMPLETE FRAMEWORK AT YOUR DISPOSAL?

Sorry for the AOL-speak, but sometimes you have to yell to be heard over the chest-thumping...

Frankly, with frameworks like the CodeIgniter PHP framework, things DO get really easy.

rustyvz on January 25, 2008 7:02 AM

Hmm.. I could easily build a bot in python that writes Jeff Atwood blog articles very convincingly. Oh wait--six *hundred* lines? Well! I guess I could build ten bots!


from random import choice
article = ''
while len(article) 1000:
article += choice(choice(randomDevBlogQuotes()),choice(randomImages()),choice(linksToMyOwnArticles))

Sean on January 25, 2008 7:16 AM

I wrote a weblog application with rss and atom feeds in 430 lines of code (including CSS) running on Django. Though it was my first django app and I likely could add some functionality and still do it in less code now.

rev_matt_y on January 25, 2008 7:17 AM

Scott Mitchell: they call that "code golf."

http://codegolf.com/

Sean on January 25, 2008 7:17 AM

Here is a page of 'one-liners' written in Carl Sassenrath's (AmigaOS kernel dude) REBOL language:

http://www.rebol.com/oneliners.html

It's amazing how much you can get out of a single line of code when hundreds/thousands/millions of _other_ lines of code are being executed.

Zip on January 25, 2008 7:47 AM

Fuck Ruby.

Yes, you can program everything in 8 lines.

As long as they're websites. As long as you're only doing things supported by framework widgets.

Remember your magpie developer post? Sometimes I think you forget.

N on January 25, 2008 8:00 AM

Just ask Microsoft. You can write a useful application without any code at all.

Ryan Clare on January 25, 2008 8:10 AM

Just for fun we wrote http://lessmemories.com in 7 hours in 300 lines of code. In another 5 hours and 200 lines of code, we added the browser linkbar button and AIM integration (http://lessmemories.com/tools).

Steven Bristol on January 25, 2008 8:15 AM

i'm not particularly impressed for 600 lines of code. i imagine most of them come from the necessity of displaying the thing on a web page.

it seems to do some trivial data stuff... as a non web application written in VB6 or C++ this could be tiny. even with php and mysql generating html, i would wonder where 600 lines of code could come from... but i could imagine it growing that large. pages of php code always seem to come out twice as big as i initially expect... all the browser support and workarounds etc... bloats any website out. i'm sure i must be missing the point as these blog posts are most normally spot on.

concatenating lines of code is not cool though... its 'cheating' and its ugly and horrible to read. :)

the semi-colon delimits the end of the line as far as the language grammar and compiler cares. just because mutliple lines of code are mapped to one line number in the source file... doesn't make it one line of code. it just means you fit multiple lines of code on one line of a text file...

Jheriko on January 25, 2008 8:27 AM

Basic/VB provides colon ":" because it foolishly gives meaning to a whitespace character (return). Its the same principle though.

Jheriko on January 25, 2008 8:29 AM

I think Steve Jobs loaned 37signals his reality distortion field.

Travis Johnson on January 25, 2008 8:30 AM

The rebol scripting language is pretty darn good for writing useful programs in few LOC. Here's a simple image viewer with a GUI written in 30 lines. http://www.flippingsweet.com/viewer.html

Here are some more examples:
Online Forum
http://www.rebol.com/docs/cgi-bbs.html
Play a List of MP3's
http://www.rebol.com/docs/quick-start5.html
Web Thumbnail Gallery Creator
http://www.rebol.net/cookbook/recipes/0040.html
Server Monitor w/ GUI
http://www.rebol.net/cookbook/recipes/0061.html
Tiny Web Server
http://www.rebol.net/cookbook/recipes/0057.html

The URL-Open Perl script posted above would be 4 or 5 lines of code.

Edoc on January 25, 2008 8:32 AM

btw, a tool i made whilst bored at work: 262 lines of code. pops up a window which lists every window on the screen and lets you force one to be on top (except office windows for some bizarre microsoft reason no doubt). and its c++ which is notoriously verbose and includes all the extra space and comments i use to make it a bit more legible. compiled with dmc with two command line switched... no extras needed beyond the dlls that ship with windows.

three comments in a row... i need to cut back. :)

Jheriko on January 25, 2008 8:36 AM

I do embedded programming. One of the chips I worked on had 512 _bytes_ of Flash and 24 _bytes_ of RAM. (Not k - 512 or 24 _bytes_ )

In 100 lines, I've written VHF transmitter code that's used all over the world.

oops, must leave sick kid.

themagni on January 25, 2008 8:48 AM

The task list in OfficeZilla.com with group sharing (private and shared tasks), add, edit, delete with a little sloppy code duplication (need to get in and make it nice) plus html is 729 lines. I have not updated it in several years now, not sure what these guys are getting so excited about there 600 lines. It just isn't a big deal.

George SCott on January 25, 2008 8:50 AM

"Honestly.. who cares how many lines of code an application is? As long as it fufills it's requirements and it's easy to maintain, that's all that matters"

I'd echo that!

Programs that are too short approach obfuscation and are not maintainable. Programs that are too long tend not to be maintainable because they tend to have a lot of waste.

There is something special about code that is simple (not necessarily short), easy to maintain, easy to learn, and solves the most complex requirements.

I was reading your blog article "Getting the Interview Phone Screen Right" and really like the part about searching code for phone numbers and seeing what the solution would be. The simplest solution was doing a web search. That's 0 lines of code and solves the problem!

Dave Parslow on January 25, 2008 9:02 AM

More comments»

The comments to this entry are closed.