Want to write some code? Get away from your computer!

I’ve recently realised something. The best place to write code isn’t in front of your computer, with your compiler, IDE and tools. The best place to write code is far, far away from any of these tools – somewhere where you can think properly. For a language with which you are fairly familiar, the mechanics of translating the program in your mind to a program that the compiler can compile (or the interpreter can interpret) is fairly easy – it’s coming up with that program in your mind which is hard.

The other day I was on a train journey. I had my laptop, but no internet. Unfortunately I was using a commercial programming language (IDL, as it happens) for which I need to use my university’s site license. As I didn’t have access to the internet, I couldn’t get hold of the site license, so couldn’t run the compiler and IDE. Say what you like about commercial programming languages which require expensive licenses, but it stopped me from actually writing code in my editor with the compiler. And…guess what…it actually made me think!

I guess this post is somewhat along the lines of Does Visual Studio rot the mind? and the following quote:

One of the best lessons I learnt from my first boss was: “when your code doesn’t behave as expected, don’t use the debugger, think.”

That is what being away from your compiler forces you to do. It’s very easy to slip into the mindset of:

  1. Write a bit of (fairly bad) code
  2. Compile and run
  3. Test with a poorly chosen test case
  4. Find it doesn’t work
  5. Make small change to the code on the off-chance that it might solve the problem
  6. Repeat…

Of course this leads to code in the end that is ill-understood by the programmer, probably fairly buggy and not well tested.

Being away from the computer forces you to run through all of the thoughts in your head – which tends to take longer than getting a computer to compile and run your code (for small code bases at least…). So you don’t tend to make tiny changes and re-run things, you tend to actually think about what the code is doing. Until I did this on the train the other day, I hadn’t actually run a piece of code on paper (that is, written down columns for each of the variables and worked out what each value will be at each stage in the program) since my Computing A-Level exam!

In the case of the code I was writing the other day, I managed to produce some high quality, fast, bug-free code by writing it in long-hand on a piece of paper, thinking about it, gradually typing up bits of it, thinking some more, and then after a long time trying it in the compiler. The code (which was some region-growing image segmentation code which involved lots of recursion) was eventually copied from my piece of paper to my IDE, compiled (with only one syntax error – impressive I think) and ran correctly first time (and completed all of the tests that I had also devised on paper).

Job well done, I think, and a useful piece of advice, I hope.

This entry was posted in Lessons learnt from..., Programming.
Bookmark the permalink.
Follow any comments here with the RSS feed for this post.
Post a comment or leave a trackback: Trackback URL.

23 Comments

  1. Skhan
    Posted March 19, 2011 at 10:16 pm | Permalink

    I am guilty of using the paper and pencil to brainerate some code blocks.

  2. MZ
    Posted March 19, 2011 at 11:06 pm | Permalink

    Funny thing–I had a similar experience with the same language and came up with the same conclusion.

  3. john
    Posted March 20, 2011 at 12:02 am | Permalink

    maybe you need one of those pens that do OCR? livescribe or something.

  4. Posted March 20, 2011 at 12:41 am | Permalink

    Great post. I think the pragmatic programmers call that bad process “programming by coincidence”. You write some code and hope that it works, and when it does work, you don’t revisit why it works.

    You’re definitely right. It gives a new meaning to think before you write.

  5. Doug
    Posted March 20, 2011 at 2:27 am | Permalink

    Saying Computers Science is all about Computers is akin to saying Astrology is all about telescope. (dijkstra said that)

  6. matt
    Posted March 20, 2011 at 2:51 am | Permalink

    I’ve been doing just this! It makes me look at the entire structure of the program differently simply because I’m seeing the code from a different angle.

  7. Posted March 20, 2011 at 3:40 am | Permalink

    Yea I agree completely, I pick up a pen & paper and try to write down code and this of the corner cases, it helps a lot!
    I use it as an excuse to write on paper too, which doesn’t happen very offten :/

  8. Posted March 20, 2011 at 6:39 am | Permalink

    I agree that the computer can get in the way of thinking, but equally when you do get back to the computer: Don’t be afraid to throw a few attempts away!

  9. Posted March 20, 2011 at 7:20 am | Permalink

    Good article, yes it does helps. I mostly do that when I am planning on writing a big thing, but I realize now I have to do it more often xD leave the computer :P

  10. Simon Hibbs
    Posted March 20, 2011 at 9:46 am | Permalink

    When I’ve got a tricky programming problem to solve, I try to force myself not to listen to podcasts and music on the train so that my mind is free to think about the problem. I love my iPhone, it’s a valuable tool and more than an entertainment device, but I worry that it reduces the quiet time I have available to just think.

    Simon Hibbs

  11. Jojomonkey
    Posted March 20, 2011 at 3:25 pm | Permalink

    Any good professor will tell you the same. I always start on paper for some of the reasons mentioned. It helps produce more efficient code as one on paper will want to write less and think more about the algos, patterns, etc of the program.

    Another piece of advice that I learned in college: all my friends used IDEs with intellisense while I stuck to my Vim. I later realized how intellisense made them crappier coders because when asked about the signature of a function, return codes, etc… they could never recall – esp during exams. For students, learning the hard way is best.

  12. Ya
    Posted March 30, 2011 at 4:37 pm | Permalink

    По-моему єто клиника.
    тестировать код в уме…

  13. Posted April 28, 2011 at 9:44 am | Permalink

    Great post. I think the pragmatic programmers call that bad process “programming by coincidence”. You write some code and hope that it works, and when it does work, you don’t revisit why it works.

  14. Martyn Wilson
    Posted April 29, 2011 at 10:01 am | Permalink

    “when your code doesn’t behave as expected, don’t use the debugger, think.”

    … or ask your Dad.

  15. Posted May 9, 2011 at 7:26 pm | Permalink

    Great idea ! Getting away from the computer is absolutely necessary somtimes, and going away for a while is just the thing you need to put your thoughts straight.

  16. Posted May 25, 2011 at 8:20 am | Permalink

    For me it’s most important thing that i have piece, whether i’m in front of computer or i’m just thinking about project

  17. Posted July 5, 2011 at 9:11 pm | Permalink

    Another piece of advice that I learned in college: all my friends used IDEs with intellisense while I stuck to my Vim. I later realized how intellisense made them crappier coders because when asked about the signature of a function, return codes, etc… they could never recall – esp during exams. For students, learning the hard way is best.

  18. Posted July 13, 2011 at 1:55 pm | Permalink

    Great idea ! Getting away from the computer is absolutely necessary somtimes, and going away for a while is just the thing you need to put your thoughts straight.

  19. Culturismo
    Posted July 17, 2011 at 8:17 pm | Permalink

    Another piece of advice that I learned in college: all my friends used IDEs with intellisense while I stuck to my Vim. I later realized how intellisense made them crappier coders because when asked about the signature of a function, return codes, etc… they could never recall – esp during exams. For students, learning the hard way is best.

  20. Posted July 21, 2011 at 12:51 am | Permalink

    Very interesting post. I’ve never tried to do this. The next time I use PHP, I’m going to pick up a pen & paper and try to write down code. Thanks for the idea.

  21. Posted July 22, 2011 at 10:35 pm | Permalink

    amazing post, you write some code and hope that it works, and when it does work, you don’t revisit why it works.

  22. Posted July 25, 2011 at 8:29 pm | Permalink

    Great website. When I’ve got a tricky programming problem to solve, I try to force myself not to listen to podcasts and music on the train so that my mind is free to think about the problem.

  23. Posted November 23, 2011 at 5:45 am | Permalink

    While I do agree that stepping away from the computer helps for getting started or when you’re stuck, I am more in line with people using CSS rather than Photoshop for prototyping. As the author wrote, converting thought to code is fairly easy, so by writing as I think, I free my mind from containing all the stuff I thought out already.

11 Trackbacks

  1. [...] brings me to this interesting article on the pros of writing code by hand on Robin’s Blog. about Soviet Hardball covers the new media arms race in digital design, technology, and [...]

  2. [...] 来源:Robin’s blog 我最近想明白了一些事情。最好的写程序的地方不是在你的计算机前,不是使用你的编译器、IDE或其它一些工具。这最好的地方是一个远离这些工具的场所 —— 是某个能让你认真的思考的地方。对于一个你很熟悉的编程语言,你很容易把你脑子里已经构思好的程序转换成编译器/解释器可以编译/解释的程序 —— 难就难在如何在脑子里先把程序编好。 [...]

  3. [...] 转自Robin’s blog [...]

  4. [...] 来源:Robin’s blog 我最近想明白了一些事情。最好的写程序的地方不是在你的计算机前,不是使用你的编译器、IDE或其它一些工具。这最好的地方是一个远离这些工具的场所 —— 是某个能让你认真的思考的地方。对于一个你很熟悉的编程语言,你很容易把你脑子里已经构思好的程序转换成编译器/解释器可以编译/解释的程序 —— 难就难在如何在脑子里先把程序编好。 [...]

  5. [...] 新闻来源:Robin’s blog 我最近想明白了一些事情。最好的写程序的地方不是在你的计算机前,不是使用你的编译器、IDE或其它一些工具。这最好的地方是一个远离这些工具的场所 —— 是某个能让你认真的思考的地方。对于一个你很熟悉的编程语言,你很容易把你脑子里已经构思好的程序转换成编译器/解释器可以编译/解释的程序 —— 难就难在如何在脑子里先把程序编好。 [...]

  6. [...] Robin’s blog [...]

  7. [...] Want to write some code? Get away from your computer! [...]

  8. By richestill.com on April 8, 2011 at 8:43 pm

    [...] News – Want to write some code? Get away from your computerMarch 21, 2011 – There is a link to: “Does Visual Studio rot the mind?’ where this [...]

  9. [...] Want to write some code? Get away from your computer! [...]

  10. [...] a friend pointed out to this excellent post by Robin Wilson which expresses a similar opinion. If you liked this post, you might be interested [...]

  11. [...] 本文是从 Want to write some code? Get away from your computer! 这篇文章翻译而来。 [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>