Great Habits of Programmer(程序员的好习惯)

原文出处:https://github.com/benjycui/benjycui.github.io/issues/1

Most of you heard about Refactoring: Improving the Design of Existing Code, which is written by Kent Beck. And some of you may know that Kent Beck said:
绝大多数的人都听说过Kent Beck写的《重构:改进现有代码的设计》,并且可能有人也知道他说过:

I’m not a great programmer; I’m just a good programmer with great habits.
我并不是一个伟大的程序员,而仅仅只是一个拥有好习惯的不错的程序员

But what are those great habits? Kent Beck had provide some in his book. Also, you can find others through searching engine.Actually, maybe searching engine is the reason that you are reading this article. but for me, the following habits are what I have learned from my classmates and colleagues. It is useful for me. So, I share them to you and hope that these habits make you a better programmer.
那么这些好习惯是什么呢?Kent Beck在他的书中提供了一些举例,并且你也可以通过搜索引擎找到更多。或许你现在正在读的这篇文章就是通过搜索引擎搜索的结果。对我来说,我的很多好习惯的形成都是来自于我的同学以及同事。这对我来说很有用。因此,我想把它们分享出来并且希望这些好习惯可以帮助你成为一个更好的程序员。

Create indexes instead of reciting while reading books and so on

看书的时候,做一些有效的索引或标记来替代边看边记忆内容的方式


It is exciting or tiring for programmers that they have to learn thousands of new technologies in order to catch up with the development of industry (especially for front-end engineers). Programmers are cleaver enough to learn new technologies, but most of them do not have enough time, for their lives have been occupied by countless meetings and requirements. And then, this trick is to help programmers save time and learn new technology quickly.
对于程序员来说,令人兴奋或者感到疲惫的原因在于他们必须要学习大量的新技术才能赶上工业化不断发展的进度(尤其是前端工程师)。程序员虽然在学习新技术上足够的聪明,但是大部分人并没有充裕的时间,他们的生活中要不停的忙于无数的会议以及需求。所以,这个习惯的目的就是为了帮助程序员节约时间并且更加快速的学习新的技术。

Let’s see…
让我们来试试

Create indexes => Just remember how to find the answer for a specific question.
建立索引 =》目的是为了记住如何找到一个特殊问题的答案。

So, this trick means that remember how to find the answer for a question instead of storing the answer in your head.
所以,这个习惯的目的在于记住如何定位到一个问题的答案在哪里而不是在脑子里记住这些答案。

Take jQuery for example. It is possible to remember all the APIs of jQuery, but difficult. Actually, it is unnecessary for most of programmers to remember all the APIs of a library. What we should do is that scan those APIs and know what they can do. In another word, we do not need to know how to do with those APIs. Because we know that we can open http://api.jquery.com/ and search, anytime.
我们用jQuery来举例。也许我们可以记住jQuery中所有的API,但这是非常困难的。实际上,对于绝大多数程序员来说,记住所有的API是没有必要的。我们应该做的是浏览这些API并且知道它们都是用来做什么的。也就是说,我们并不需要知道如何处理这些API。因为我们知道我们可以打开http://api.jquery.com/并且随时搜索那些API

Also, it is unnecessary to remember all the tricks in Refactoring. We read this book, and knew some tricks which make our code better. When need to know how to do that, we can just consult this book.
同样的,在重构中我们也不必要记住所有的技巧。我们阅读这本书并且知道一些可以使得我们代码更加优雅的实现方式。当我们需要知道需要如何做的时候,我们就可以通过这本书来查找。

Reorganize what you had learned

整理出你需要学习的内容


Knowledge is not breadcrumbs that are unordered and uncorrelated. So, we need to reorganize what we had learned from books and bugs and so on.
知识并不是杂乱无章的面包屑。所以,我们需要从书和漏洞中整理出我们需要学习的内容

But how to do?
那么我们要如何做呢?

It depends on you . As for me, writing blogs is the answer. When writing blogs, I must review what I had learned. If something makes me puzzled, I will search on the Internet or ask others. Actually, I learn more while writing a blog.
这取决于你。对于我而言,写博客就是答案。当我在写博客的时候,我必须要复习我所学过的内容,如果有一些知识令我感到困惑,我会在浏览器上寻找答案或者询问别人。实际上,当我在写博客的时候我会学到更多的东西。

Also, sharing what you had learned to others is another answer. Your audiences will throw questions at you. And you have to reorganize what you had learn in order to make everything clear.
同样的,向别人分享你学到的东西是另一种答案。你的听众会向你抛出问题。并且为了使得你能清楚的解答这些问题,你必须要重新整理那些你已经学过的知识。

Read unit test and source code

阅读单元测试和源代码


A well-designed document is the best gift for a programmer, for this document will help programmers start quickly, and provide answers for most of questions. But the real world is not utopia, some libraries’ documents are in a mess. What is worse, some libraries do not have any document.
对于程序员来说,一个美观的技术文档就是最好的礼物。因为这个文档将会帮助程序员更快的学习,并且对于大部分的问题都提供了合理的答案。但是现实并不如想象中那么美好,一些库的文档是杂乱无章的。然而更糟糕的是,有些库甚至没有说明文档

So, don’t be afraid of codes that are written by others, even if there is no comment. Anyway, it is the only way to understand a library without document. And read unit test is still a good choice, for it shows what the author expects this library to do or not to do.
所以,不要害怕那些别人写的代码,甚至那些没有任何注释的代码。毕竟源代码是理解那些没有任何技术文档的库的唯一的途径,并且阅读单元测试是一个不错的选择,因为它展示了作者希望这个库能做什么和不能做什么。

But…
但是

What if…
假设…

There is no unit test!
它并没有任何单元测试!

Read source code of the library, and try to guess what it is designed to do from the implementation. Or, just find a well-documented library, if you can.
阅读库的源代码,并且从执行的情况来猜测这个库被设计出来是做什么的。或者,只找那些有好的文档的库。

Think twice before coding

在编码之前多思考一下


You can code at home, at table, at … But you can not code at will. Coding is rigorous for your code will have a great effect on customers and your annual bonus.
你可以在家里编码,可以在餐桌上编码,在…但是你并不能随意地编码。编码是严格的,因为你的代码将对你的客户和你的年终奖产生很大的影响。

As for me, think twice means that ask myself some questions. For example:
对于我而言,多思考一次意味着问我自己一些问题,比如:

What do I expect this program to do?
我期望这段程序做什么?

How does current version work?
当前版本如何工作?

Why do I choose this solution? Is there a better solution?
我为什么选择这种解决方式?有更好的解决办法吗?

Ask yourself all the questions that you care about.
问自己所有你关心的问题。

Look at $$$, think twice before coding, or thrice for important things should be repeated thrice 😃.
看看$$$,在编码之前多思考一下,或者重要的东西应该重复三次。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值