这是用户在 2024-10-26 11:06 为 https://johnresig.com/blog/write-code-every-day/ 保存的双语快照页面,由 沉浸式翻译 提供双语支持。了解如何保存?

Write Code Every Day

Last fall, work on my coding side projects came to a head: I wasn’t making adequate progress and I couldn’t find a way to get more done without sacrificing my ability to do effective work at Khan Academy.
去年秋天,我的编码项目工作达到了紧要关头:我没有取得足够的进展,而且我找不到一种方法可以在不牺牲我在可汗学院有效工作的能力的情况下完成更多工作。

There were a few major problems with how I was working on my side projects. I was primarily working on them during the weekends and sometimes in the evenings during the week. This is a strategy that does not work well for me, as it turns out. I was burdened with an incredible amount of stress to try and complete as much high quality work as possible during the weekend (and if I was unable to it felt like a failure). This was a problem as there’s no guarantee that every weekend will be free – nor that I’ll want to program all day for two days (removing any chance of relaxation or doing anything fun).
我在开展副业项目时遇到了一些重大问题。我主要在周末和有时在一周的晚上进行这些工作。事实证明,这种策略对我来说效果不佳。我承受着巨大的压力,试图在周末尽可能多地完成高质量的工作(如果我做不到,那感觉就像是失败)。这是一个问题,因为不能保证每个周末都是免费的 - 也不保证我会想在两天内全天进行编程(消除任何放松或做任何有趣的事情的机会)。

There’s also the issue that a week between working on some code is a long time, it’s very easy to forget what you were working on or what you left off on (even if you keep notes). Not to mention if you miss a weekend you end up with a two week gap as a result. That massive multi-week context switch can be deadly (I’ve had many side projects die due to attention starvation like that).
还有一个问题是,编写某些代码之间的一周时间很长,很容易忘记你正在做什么或你没有做什么(即使你做了笔记)。更不用说如果你错过了一个周末,最终就会有两周的时间间隔。这种持续数周的大规模上下文切换可能是致命的(我有很多副项目因为这样的注意力匮乏而终止)。

Inspired by the incredible work that Jennifer Dewalt completed last year, in which she taught herself programming by building 180 web sites in 180 days, I felt compelled to try a similar tactic: working on my side projects every single day.
Jennifer Dewalt去年完成的令人难以置信的工作(她通过在 180 天内构建 180 个网站来自学编程)受到启发,我觉得有必要尝试类似的策略:每天都致力于我的业余项目。

Illustration by Steven Resig

I decided to set a couple rules for myself:

  1. I must write code every day. I can write docs, or blog posts, or other things but it must be in addition to the code that I write.
    我必须每天写代码。我可以编写文档、博客文章或其他内容,但它必须是在我编写的代码之外。
  2. It must be useful code. No tweaking indentation, no code re-formatting, and if at all possible no refactoring. (All these things are permitted, but not as the exclusive work of the day.)
    它一定是有用的代码。无需调整缩进,无需重新格式化代码,并且如果可能的话也无需重构。 (所有这些事情都是允许的,但不能作为当天的独家工作。)
  3. All code must be written before midnight.
    所有代码必须在午夜之前编写。
  4. The code must be Open Source and up on Github.
    代码必须是开源的并且在 Github 上发布。

Some of these rules were arbitrary. The code doesn’t technically need to be written before midnight of the day of but I wanted to avoid staying up too late writing sloppy code. Neither does the code have to be Open Source or up on Github. This just forced me to be more mindful of the code that I was writing (thinking about reusability and deciding to create modules earlier in the process).
其中一些规则是任意的。从技术上讲,代码不需要在当天午夜之前编写,但我想避免熬夜编写草率的代码。代码也不必是开源的或在 Github 上发布。这迫使我更加注意我正在编写的代码(考虑可重用性并决定在此过程的早期创建模块)。

Thus far I’ve been very successful, I’m nearing 20 weeks of consecutive work. I wanted to write about it as it’s completely changed how I code and has had a substantial impact upon my life and psyche.
到目前为止,我非常成功,连续工作已经接近 20 周了。我想写下它,因为它彻底改变了我的编码方式,并对我的生活和心理产生了重大影响。

With this in mind a number of interesting things happened as a result of this change in habit:

Minimum viable code. I was forced to write code for no less than 30 minutes a day. (It’s really hard to write meaningful code in less time, especially after remembering where you left off the day before.) Some week days I work a little bit more (usually no more than an hour) and on weekends I’m sometimes able to work a full day.
最小可行代码。我被迫每天写代码不少于30分钟。 (在更短的时间内编写有意义的代码确实很困难,尤其是在记住前一天离开的地方之后。)有些工作日我工作得更多一些(通常不超过一个小时),而在周末我有时能够工作一整天。

Code as habit. It’s important to note that that I don’t particularly care about the outward perception of the above Github chart. I think that’s the most important take away from this experiment: this is about a change that you’re making in your life for yourself not a change that you’re making to satisfy someone else’s perception of your work. The same goes for any form of dieting or exercise: if you don’t care about improving yourself then you’ll never actually succeed.
编码作为习惯。需要注意的是,我并不特别关心上述 Github 图表的外在感知。我认为这是这个实验最重要的收获:这是你为自己的生活所做的改变,而不是为了满足别人对你工作的看法而做出的改变。这同样适用于任何形式的节食或锻炼:如果你不关心提高自己,那么你永远不会真正成功。

Battling anxiety. Prior to starting this experiment I would frequently feel a high level of anxiety over not having completed “enough” work or made “enough” progress (both of which are relatively unquantifiable as my side projects had no specific deadlines). I realized that the feeling of making progress is just as important as making actual progress. This was an eye-opener. Once I started to make consistent progress every day the anxiety started to melt away. I felt at peace with the amount of work that I was getting done and I no longer had the over-bearing desire to frantically get any work done.
对抗焦虑。在开始这个实验之前,我经常会因为没有完成“足够”的工作或取得“足够”的进展而感到高度焦虑(这两者都是相对无法量化的,因为我的副项目没有具体的截止日期)。我意识到取得进步的感觉与取得实际进步同样重要。这真是令人大开眼界。一旦我开始每天取得持续的进步,焦虑就开始消失。我对自己要做的大量工作感到平静,不再有疯狂地完成任何工作的强烈欲望。

Weekends. Getting work done on weekends use to be absolutely critical towards making forward momentum (as they were, typically, the only time in which I got significant side project coding done). That’s not so much the case now – and that’s a good thing. Building up a weeks-worth of expectations about what I should accomplish during the weekend only ended up leaving me disappointed. I was rarely able to complete all the work that I wanted and it forced me to reject other weekend activities that I enjoyed (eating dim sum, visiting museums, going to the park, spending time with my partner, etc.) in favor of getting more work done. I strongly feel that while side projects are really important they should not be to the exclusion of life in general.
周末。在周末完成工作对于取得前进的动力绝对至关重要(因为通常这是我完成重要副项目编码的唯一时间)。现在情况已不再如此——这是一件好事。对周末应该完成的事情建立了一周的期望,结果却让我感到失望。我很少能够完成我想要的所有工作,这迫使我拒绝我喜欢的其他周末活动(吃点心、参观博物馆、去公园、与我的伴侣共度时光等),以支持获得完成更多工作。我强烈地感觉到,虽然副业项目确实很重要,但它们不应该排除在一般生活之外。

Background processing. An interesting side effect of writing side project code every day is that your current task is frequently running in the back of your mind. Thus when I go for a walk, or take a shower, or any of the other non-brain-using activities I participate in, I’m thinking about what I’m going to be coding later and finding a good way to solve that problem. This did not happen when I was working on the code once a week, or every other week. Instead that time was consumed thinking about some other task or, usually, replaced with anxiety over not getting any side project work done.
后台处理。每天编写副项目代码的一个有趣的副作用是,您当前的任务经常在您的脑海中运行。因此,当我去散步、洗澡或参加任何其他非用脑活动时,我会思考稍后要编码的内容,并找到解决该问题的好方法问题。当我每周或每隔一周编写一次代码时,这种情况不会发生。相反,这些时间被花在思考其他任务上,或者通常被因没有完成任何副项目工作而焦虑所取代。

Context switch. There’s always going to be a context switch cost when resuming work on a side project. Unfortunately it’s extremely hard to resume thinking about a project after an entire week of working on another task. Daily work has been quite helpful in this regard as the time period between work is much shorter, making it easier to remember what I was working on.
上下文切换。当恢复一个副项目的工作时,总是会产生上下文切换成本。不幸的是,在完成另一项任务整整一周后,很难重新开始思考一个项目。日常工作在这方面非常有帮助,因为工作之间的时间间隔要短得多,让我更容易记住我在做什么。

Work balance. One of the most important aspects of this change was in simply learning how to better balance work/life/side project. Knowing that I was going to have to work on the project every single day I had to get better at balancing my time. If I was scheduled to go out in the evening, and not get back until late, then I would need to work on my side project early in the day, before starting my main Khan Academy work. Additionally if I hadn’t finished my work yet, and I was out late, then I’d hurry back home to finish it up (instead of missing a day). I should note that I’ve been finding that I have less time to spend on hobbies (such as woodblock printing) but that’s a reasonable tradeoff that I’ll need to live with.
工作平衡。这一变化最重要的方面之一就是简单地学习如何更好地平衡工作/生活/业余项目。知道我每天都必须完成这个项目,我必须更好地平衡我的时间。如果我计划晚上出去,直到很晚才回来,那么我需要在当天早些时候开始我的副项目,然后再开始我的可汗学院主要工作。另外,如果我还没有完成工作,并且出去晚了,那么我会赶紧回家完成工作(而不是错过一天)。我应该指出的是,我发现我花在爱好(例如木刻印刷)上的时间更少,但这是我需要忍受的合理权衡。

Outward perception. This has all had the added benefit of communicating this new habit externally. My partner understands that I have to finish this work every day, and thus activities sometimes have to be scheduled around it. It’s of considerable comfort to be able to say “Yes, we can go out/watch a movie/etc. but I have to get my coding in later” and have that be understood and taken into consideration.
外在的感知。这一切都带来了与外部交流这一新习惯的额外好处。我的伴侣知道我每天都必须完成这项工作,因此有时必须围绕它安排活动。能够说“是的,我们可以出去/看电影/等等”是相当令人安慰的。但我必须稍后再进行编码”,并让人们理解并考虑这一点。

How much code was written? I have a hard time believing how much code I’ve written over the past few months. I created a couple new web sites, re-wrote some frameworks, and created a ton of new node modules. I’ve written so much I sometimes forget the things I’ve made – work from even a few weeks prior seem like a distant memory. I’m extremely pleased with the amount of work that I’ve gotten done.
写了多少代码?我很难相信过去几个月我写了多少代码。我创建了几个新网站,重写了一些框架,并创建了大量新的节点模块。我写了太多东西,有时我会忘记我所做的事情——即使是几周前的工作也像是遥远的记忆。我对自己完成的工作量感到非常满意。

I consider this change in habit to be a massive success and hope to continue it for as long as I can. In the meantime I’ll do all that I can to recommend this tactic to others who wish to get substantial side project work done. Let me know if this technique does, or doesn’t, work for you – I’m very interested in hearing additional anecdotes!
我认为这种习惯的改变是巨大的成功,并希望尽可能长时间地继续下去。与此同时,我将尽我所能向其他希望完成大量副项目工作的人推荐这种策略。让我知道这个技巧是否适合你——我非常有兴趣听到更多的轶事!

Discuss this post on Hacker News.

Posted: April 10th, 2014


Subscribe for email updates

73 Comments (Show Comments)



Comments are closed.
Comments are automatically turned off two weeks after the original post. If you have a question concerning the content of this post, please feel free to contact me.


Secrets of the JavaScript Ninja

Secrets of the JS Ninja

Secret techniques of top JavaScript programmers. Published by Manning.

John Resig Twitter Updates

@jeresig / Mastodon

Infrequent, short, updates and links.