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:
- Write a bit of (fairly bad) code
- Compile and run
- Test with a poorly chosen test case
- Find it doesn’t work
- Make small change to the code on the off-chance that it might solve the problem
- 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.
If you found this post useful, please consider buying me a coffee.
This post originally appeared on Robin's Blog.
Categorised as: Lessons learnt from..., Programming
I am guilty of using the paper and pencil to brainerate some code blocks.
Funny thing–I had a similar experience with the same language and came up with the same conclusion.
maybe you need one of those pens that do OCR? livescribe or something.
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.
Saying Computers Science is all about Computers is akin to saying Astrology is all about telescope. (dijkstra said that)
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.
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 :/
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!
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 😛
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
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.
[…] 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 […]
По-моему єто клиника.
теÑтировать код в уме…
[…] æ¥æº:Robin’s blog 我最近想明白了一些事情。最好的写程åºçš„地方ä¸æ˜¯åœ¨ä½ 的计算机å‰ï¼Œä¸æ˜¯ä½¿ç”¨ä½ 的编译器ã€IDE或其它一些工具。这最好的地方是一个远离这些工具的场所 —— 是æŸä¸ªèƒ½è®©ä½ 认真的æ€è€ƒçš„åœ°æ–¹ã€‚å¯¹äºŽä¸€ä¸ªä½ å¾ˆç†Ÿæ‚‰çš„ç¼–ç¨‹è¯è¨€ï¼Œä½ å¾ˆå®¹æ˜“æŠŠä½ è„‘å里已ç»æž„æ€å¥½çš„程åºè½¬æ¢æˆç¼–译器/解释器å¯ä»¥ç¼–译/è§£é‡Šçš„ç¨‹åº â€”â€” 难就难在如何在脑å里先把程åºç¼–好。 […]
[…] 转自Robin’s blog […]
[…] æ¥æº:Robin’s blog 我最近想明白了一些事情。最好的写程åºçš„地方ä¸æ˜¯åœ¨ä½ 的计算机å‰ï¼Œä¸æ˜¯ä½¿ç”¨ä½ 的编译器ã€IDE或其它一些工具。这最好的地方是一个远离这些工具的场所 —— 是æŸä¸ªèƒ½è®©ä½ 认真的æ€è€ƒçš„åœ°æ–¹ã€‚å¯¹äºŽä¸€ä¸ªä½ å¾ˆç†Ÿæ‚‰çš„ç¼–ç¨‹è¯è¨€ï¼Œä½ å¾ˆå®¹æ˜“æŠŠä½ è„‘å里已ç»æž„æ€å¥½çš„程åºè½¬æ¢æˆç¼–译器/解释器å¯ä»¥ç¼–译/è§£é‡Šçš„ç¨‹åº â€”â€” 难就难在如何在脑å里先把程åºç¼–好。 […]
[…] æ–°é—»æ¥æº:Robin’s blog 我最近想明白了一些事情。最好的写程åºçš„地方ä¸æ˜¯åœ¨ä½ 的计算机å‰ï¼Œä¸æ˜¯ä½¿ç”¨ä½ 的编译器ã€IDE或其它一些工具。这最好的地方是一个远离这些工具的场所 —— 是æŸä¸ªèƒ½è®©ä½ 认真的æ€è€ƒçš„åœ°æ–¹ã€‚å¯¹äºŽä¸€ä¸ªä½ å¾ˆç†Ÿæ‚‰çš„ç¼–ç¨‹è¯è¨€ï¼Œä½ å¾ˆå®¹æ˜“æŠŠä½ è„‘å里已ç»æž„æ€å¥½çš„程åºè½¬æ¢æˆç¼–译器/解释器å¯ä»¥ç¼–译/è§£é‡Šçš„ç¨‹åº â€”â€” 难就难在如何在脑å里先把程åºç¼–好。 […]
[…] Robin’s blog […]
[…] Want to write some code? Get away from your computer! […]
[…] 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 […]
[…] Want to write some code? Get away from your computer! […]
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.
“when your code doesn’t behave as expected, don’t use the debugger, think.â€
… or ask your Dad.
[…] 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 […]
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.
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
[…] 本文是从 Want to write some code? Get away from your computer! è¿™ç¯‡æ–‡ç« ç¿»è¯‘è€Œæ¥ã€‚ […]
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.
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.
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.
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.
amazing post, you write some code and hope that it works, and when it does work, you don’t revisit why it works.
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.
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.
I totally agree with you, I used to write code 1.Write a bit of (fairly bad) code
2.Compile and run…. It works almost every time. But later I always found that I don’t really understand the how it works.
[…] 英文原文:Want to write some code? Get away from your computer! 翻译作者:html5tricks – 蒋丽丽 […]
[…] 原文:Want to write some code? Get away from your computer! […]