你的代码写的很臭

来源:互联网 发布:绝地求生显卡驱动优化 编辑:程序博客网 时间:2024/06/09 20:46
Your Code Sucks
你的代码写的很臭
       A very good friend of mine is in the midst of an avalanche of work. He has a lot of open contracts, and has been abandoned by a fellow developer that was helping him with his workload. So, with three huge clients breathing down his neck he has been working non stop for weeks now.
    我的一个好朋友最近正面对如山崩海啸般的工作量.他现在还有许多没有完成的合同(open contracts),以前帮他工作的开发人员也离他而去.现在,因为三个跟追命鬼(clients breathing down his neck)似的客户,他已经几周都没有好好休息了.

       One client contacted him about the iPad application he is building for them, he let him know "I paid another developer to look at your code, he says it really sucks."
    他为一个客户开发了一个ipad应用,而这个客户却告诉他"我掏钱让另一个开发者看了你的代码,他说这代码很臭."

   When he told me this story, I had to chuckle a bit, and think of all the times I had decided that other people's code sucked. When I first started out, and I looked at code that definitely sucked hard, I scrapped it, and started from scratch in a way I knew was way better. As I matured I looked back and realized that what I had destroyed was a well accepted design pattern, and what I created was a mess of a mess pattern.
    当他告诉我这个事的时候,我笑了笑.我想起了我自己曾经判定别人的代码很糟糕的时候.当我第一次看那些确实很糟糕的代码的时候,我删改了源代码,换上了我认为好一些的.当我成熟一些的时候,再回头看看我才认识到我删除的正是一些很可读性很好的设计模式,我自己加上去的反而是很一片很糟糕的模式.

Lesson learned.
    很有教育意义的一节课.

      After some growth I encountered code that I thought sucked ever so often. At this point I wasn't decimating things all together, I would find specific parts of code that I found intolorable and rewrite it. About 9 times out of 10, when I got more than halfway there I'd run into an issue that made me say "Ooooh, that's why they did it that way" and revert it or use the same "sucky" logic with my syntax.
    后来,即使我再遇到很臭的代码,我也不会大规模的删除它们,而是找到那些我实在难以忍受的部分然后重写.十次中有九次,当我完成了一半多的时候,我总得说一句"哦,这就是他们为什么要这样写"然后我会恢复代码,或者用同样很臭的语法来完成它.

     Now that I am a little more seasoned, I can tell you with all confidence that I never look at a solution that someone else created and say "Oh, this code sucks." I know that there really is no quick way to tell if code is good or bad without understanding the entire solution. Sure, sometimes things can look sloppy, or poorly done, or undocumented (in my case, not self documenting), however, you never know what was going through the head of the developer that wrote it. More often than not there is a reason why they have done things this way, and there is no hard and fast way to tell what the context is without being elbow deep in it.
    现在我有了一些经验,我可以自信地告诉你们我绝不会看着别人的方案说"这很臭".因为我知道,在没有理解整个方案前,没有什么方法能很快地判断出代码是好是坏.确实,有的时候,那些代码看起来很糟,或者似乎都无法完成,再或者就没有注释(我是说,没有自我注释),此时你根本不知道开发者心中是怎么想的.更多的时候你不知道他们如此做的原因是什么.同时,在深入研究之前,也没有什么简单快速的方法来了判定上下文环境.

    So, when I hear that someone has looked at someone else's code base and determined that it sucked I smile and remember what it was like to be so new and sure of myself. So sure that I was an amazing developer, and that I knew what was best in every problematic situation. I miss that swagger, but I appreciate what I have learned, and that is the only person's code that sucks is my own, and the reason why it sucks is I just haven't learned how to make it better yet.

    所以,当我听说某人看着某人的源代码说这很糟糕的时候,我就笑了也想起了当年那个有点自信且幼稚的我.我相信自己是个天才的开发者,我知道所有问题的最好的解决方法.我想念当时的骄傲,同时我也感谢我所学的,那就是唯一糟糕的代码就是你自己写的代码,而代码糟糕的原因就是我还没有找到更好的办法.


参考翻译

http://user.qzone.qq.com/289065406/blog/1354547129#!app=2&via=QZ.HashRefresh&pos=1354547129


英文地址
http://www.girldeveloper.com/2010/07/your-code-sucks.html




原创粉丝点击