[译]改善编程的七个习惯
This short entry was also published on my personal website
这篇短文发布在我的个人网站上
I have been reading some good books on forming habits recently. After digesting these, my mind started drifting further and I started thinking what my current habits are. Some of them are applicable to life in general, some relate only to work. Without surprise, some of them happen to be strongly related to programming, which I think might be a good thing to share.
我阅读了很多关于培养习惯的优质书籍。读完之后,我就开始想啊想,想什么呢?当然是我自己平时的习惯啦。其中一些生活方面的习惯,另一些是工作相关的。作为程序猿,跟工作相关的当然就是指编程方面的习惯咯,我觉得可以分享给大家共勉。
Uncontrolled auto save. This one has been accompanying me for ages. Even though many modern IDEs do not even require saving a file, I am relentlessly squeezing “Ctrl + S” combination to its last…drop. If I recall correctly, I am doing it thoughtlessly every time I stop typing. Weird but it actually saved my day more times than it caused a smirk on my colleagues faces.
第一个习惯:没事保存一下
这是我很早就培养出来的习惯了,即使现在很多高级的IDE甚至都不需要保存文件了,我还是要自己按Ctrl+S组合键保存,除非这两个键被我按爆了。每次敲完最后一下停顿的时候,想都不想”啪”的一下保存了再说。看着是有点奇怪,甚至身边的同事看了还会偷笑,笑你妹啊,你根本不知道这一招救了我多少次(哼╭(╯^╰)╮),等什么时候断电死机了你就该苦了;
Some devs tend to say being in “the zone” is like being in Nirvana or finally reaching the Valhalla. The way I see it is more like Berserk mode. It is great for some time but then you should take a break to recover. So basically short zone bursts are great for performance but make sure you take regular stops. Being in a zone for too long can actually numb your senses and make your mind more vulnerable to get stuck in a loop. (no pun intended!)
第二个习惯:张弛有度
有些开发人员喜欢一刻不停的码字,码的飘飘欲仙,放佛身处极乐世界或者到达了瓦尔哈拉殿堂(注:挪威神话中奥丁神接待战死者英灵的殿堂)。照我看来,这也太疯了。持续一小段时间专心码字当然是极好的,但是每隔一段时间一定要停下来让你的精气神恢复到最佳状态。短时间爆发一下,确实能出好活,但是一定要定期休息啊老铁。爆发时间长了,你的感官会麻木,你的脑子会僵死,你的人可能就走进了死胡同原地打转了。
Make sure you kill all the sources of disturbance. When I work on something really important I will turn my phone off, avoid social medias or any medias in general with a slight exception for music. Apply everything in healthy limits though. If you have got kids and need to focus, locking them up in a basement might sound appealing but it is not really a good solution in longer term.
第三个习惯:排除干扰
确保你身边没有任何可以干扰你的东西。当我开始进行非常重要的工作的时候,我会把我的手机弄到飞行模式,放上音乐,避免自己被社交媒体干扰。确保自己健康得到保障。如果你有孩子需要看着的话,把他们关到地下室去?开玩笑,这可不是个长久有效的好办法。
Always try to start with an end in your mind. Some people say the power of visualisation is priceless. It helps me determining realistic list of goals for today and eventually leads to reducing or removing frustration and disappointment at the end of the day. So anytime you work on something, make sure you know exactly what is it that you want to create. It might sound obvious but it is really one of those steps being skipped way too often.
第四个习惯 知道你在干嘛
永远记得开始之前估计一下结果。正如一些人说:可视化的力量是无价的。它有助于我确定今天要做的目标,减少甚至避免日后的沮丧、失望。所以当你要干一件事的时候,确保你自己清楚你在干啥,最终会产出什么。听上去很理所当然的样子,但是很多人就是会忽视它。
One good habit for me is regular training. Even though going to the gym is another great habit, in this case I am more worried about one’s actual programming skills. I enjoy solving occasional programming exercises in order to keep my saw sharp all the time. It might not pay your bills but will definitely pay back in future.
第五个习惯 训练编程技巧
我有一个好习惯,没事就锻个练。我在这里指的是锻炼一个人的编程技巧,当然咯,去健身房锻炼身体也算是一个好习惯。偶尔我会给自己整个编程的题目,解题让我很爽,同时能让我的头脑保持活力。虽然提升自己的编程水平目前来看是捞不着钱,但日后肯定会给你丰厚的回报。
One of my most recent ones is trying to start writing any code from forming some test cases. This one is sort of related to one of my earlier points as it helps me seeing my destination before starting. It obviously makes the end result safer but as a bonus it often helps designing and documenting the code. I am actually surprised so few developers can appreciate this point of view.
第六个习惯 测试用例
我最近长干的一件事,那就是在写代码之前先把测试用例整出来。就像第四个习惯说的那样,这么做可以帮我提前知道我想要我的代码实现怎样的功能。很明显,测试用例可以让代码更安全,同时也有助于记录代码设计过程和文档记录。你看好处这么多,别的程序员咋就是想不到这么干呢。
Another fresh one for me which is to avoid “future programming”. Start small and grow later. In my earlier days while coding anything I wanted to make it perfect from the very first day, cover all the possible edge cases and almost prepare it for my descendants to use. With time I realised it often leads to overcomplicated codebase, high time consumption and in most cases my program is doing everything and nothing at the same time!
第七个习惯 避免“未来式编程”
这是个我最近学会的一点。啥叫未来式编程,就是一开始就往大了设计。而正道应该是从一个小的项目开始,慢慢把它做大。以前我年轻的时候不懂事,写代码就想要写出来就很完美,考虑所有的边界条件,给以后所有的扩展留好位置。随着时间的推移,我慢慢发现我之前在代码库里写的都是啥啊,这么复杂的一大坨,耗时又那么长。大部分情况下,我的代码干了所有的事情,其实也啥都没干成。
So here, take any of these for yourself if you feel like it. These I have found insanely useful on my programming path but forming them is not an overnight change. The best and only way to implement a habit in your life is to just start using it and it will settle down before you realise.
Ah, do not forget to let me know about other habits that worked for you!
最后,觉得什么习惯好你们就挑什么哈。这些习惯我觉得对于编程都很好用,但没有什么习惯是一日而就的。最好的培养习惯的现在就开始尝试,不知不觉就掌握了。
要是有什么习惯对你们有用,别忘了给我留言哦(https://dev.to/binarforge/seven-useful-programming-habits)。
本文作者 : 小凡
原文链接 : https://16bh.github.io/2017/07/19/translate-seven-userfun-programming-habits/
版权声明 : 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明出处!