TheJach.com

Jach's personal blog

(Largely containing a mind-dump to myselves: past, present, and future)
Current favorite quote: "Supposedly smart people are weirdly ignorant of Bayes' Rule." William B Vogt, 2010

1000 Lines

For today's installment of arbitrary thresholds, I bring you this one: before you can even consider yourself a novice in a programming language, capable of doing something useful and capable of offering critique for or against it, you need to have programmed at least 1000 lines of code in that language. If this seems obvious to you, with perhaps uncertainty of whether it's 1000 or 800 or 2000, feel free to quit reading. The rest of the post is devoted to bringing up a few possible objections and hand-waving them away because they don't matter.

First up: lines of code is a horrible metric! Yes, for measuring programmer productivity. But for determining whether you're a n00b or not, I don't think so. If you discover a way to shave off 300 lines of verbose code, replacing it with 10 lines, assume an expert in the language would have seen that immediately. In any case, you win 310 lines in your goal to 1000.

Next up: all programming languages are not equal, what might take 1000 lines of Java might only take 30 lines of Lisp. This is true, and that's why Java is the Enterprise Standard and Lisp is not. It's easier to become a novice in Java than it is for Lisp, regardless of prior programming background. A Lisp "hello world" gives you 1 line in your quest, Java's gives you 5.

Next up is a variant of the last objection. Some programming languages allow you to write your program on a single line. Lisp is one of them, there are others. (You could argue C and C++ if you look at the preprocessed output.) This objection doesn't matter, because few programmers actually program that way. Time is spent in a REPL (with each command incrementing your counter to 1000) and discoveries are made and a program is composed in a line-delimited fashion of some sort. Let's look at a concrete example:



In this video, the author creates a Game of Life simulation with APL in about 30 commands. There's a 1-liner floating around somewhere. This Game of Life implementation in Java is about 600 lines of code. By the time you're done with the APL one and the Java one, you'll still know hardly anything about APL (good luck reading other APL programs!) but you'll be able to dive in fairly successfully into most other Java programs.

Programmers build things with lines regardless of the language.

Lastly: isn't this just copying Malcolm Gladwell's 10,000 hours rule? No, because his rule is for expertise in anything, my rule is for becoming a novice in any programming language. Furthermore, in software at least, 10 novices does not make an expert, so don't think expertise is just a little over 9000 lines away when you start approaching your first 1000. (It may be, of course, but expertise in programming is better defined by the 10 year rule or Gladwell's 10,000 hours than by lines of code. Lines of code is for becoming a novice.)

Even in verbose languages like Java, you can still do a lot in a couple hundred lines. I didn't really look much at the source in the link I posted, it's probably a lot grander in UI and features than the APL counterpart. I like the 1000 number because it fits my own experience in several languages. Interesting projects that aren't just fragile toys take at least a couple hundred lines or so. With the 1000 threshold, it's another way of saying "implement several projects", but includes the option for implementing a big project. 1000 lines of Python is a fun game with multiple levels, you'll learn a lot along the way.

Implementing a big project as part of your 1000 lines also gives you a small taste for how well the language scales for even bigger projects. Of course, a 1000 line project is going to look a lot different than a million line project, I bet there are plenty of people who would scoff at the quaintness of "1000 lines" and my previous adjective of "big" (I kind of do too having worked on portions of a million line project), but at 1000 lines you get hints of what the differences to one million are going to be whereas under 300 it's just a script-size project that easily fits completely in even the head of a novice. (This isn't to say you can't have monolithic files containing thousands of lines, but that's also an interesting language feature to consider: is forced file modulation necessary?)

I stress the importance of novice in my threshold. 1000 lines of Clojure doesn't make you a Clojure expert, it makes you a novice and will teach you many lessons experts understand intuitively. Less than 1000 lines, you're still a n00b. You can't become a Clojure expert without first passing through the stages of novice and intermediate, but to even become a novice you have to do work. Expertise is more illusive in obtaining it.


Posted on 2012-04-18 by Jach

Tags: philosophy, programming

Permalink: https://www.thejach.com/view/id/249

Trackback URL: https://www.thejach.com/view/2012/4/1000_lines

Back to the top

Back to the first comment

Comment using the form below

(Only if you want to be notified of further responses, never displayed.)

Your Comment:

LaTeX allowed in comments, use $$\$\$...\$\$$$ to wrap inline and $$[math]...[/math]$$ to wrap blocks.