不良编程文化

来源:互联网 发布:小型服务器用linux 编辑:程序博客网 时间:2024/04/29 05:30
 
Code culture problem
05 September 2013

"This is shit" my coworker exclaims as we browse some code looking for a particularly unpleasant bug. "Hmm" I reply.

Such accusations, and likewise similar sentiments, are being heard around offices with increasing frequency. And the saddest part is, the code is usually not particularly shit. What does that even mean? Could it have been done better? Of course! Most code could be better, and given infinite time and resources would have been. Sure there is some bad code around, we've all seen it, hell we've all written it, but that isn't even the issue here.

The issue is one of having a "this is shit" culture.

It is a culture that I am seeing become more and more common in the web community. Continuing the example above, when I asked my coworker to explain himself, explain why is the code shit, I couldn't get a straight answer.

"It just is, look at it" he replied puffing himself up further and further, his brow furrowing as if I must be half-witted for not being able to comprehend the amount of shit that is the code. And you know what? I start to feel half-witted. I can barely stop myself from scoffing along with him and extrapolating on just how smelly and brown this code we are looking at really is.

Before I go on, I realize this story doesn't paint my coworker in the best light. So let us fix that. He's a great guy. Honestly one of the nicest people I have ever met. He is friendly, has a family he loves to talk about, runs marathons, helpful, smart, etc etc.. Another thing about him: he is a relatively new developer. He is still learning the basics, and this is nothing to be ashamed of, we have all been there at one point. I happen to find myself there on a weekly basis and I've been doing this for some time now. So why would the first instinct of a nice, smart guy who is working on his first large web project be to accuse some code of actually being shit in disguise before even trying to understand it?

Rule of life: the shit flows downward.

This problem is not isolated to just newer developers. Many smart people act the same way. You can be an amazing, seasoned developer and still have a negative affect on your team and project by behaving in such a manner. Even more so because the newer members look to you as a source of knowledge and experience. And the more people who embrace the "this is shit" culture, the easier it becomes acceptable and even desired. Soon developers are revered not for contributing to the project, but for putting down other's contributions to the project. The most vocal and negative developer soon becomes the most respected developer. Everyone suffers, the project suffers, and a few people get to pat themselves on the back and feel great about themselves for being so full of shit.

So why do we do it?

No one wants to feel stupid, and no one wants to feel inferior or bad at their job. Once a "this is shit" culture starts to spread one of the only ways to make sure that you are on top is to put down others. In the end it is a culture that values negativity rather than focus on solutions.

So what is the solution to this particular problem? Stop it. Don't blurt out negative assessments of others code for no reason, and with no understanding. There are ways to bring up issues with the code base that are not mean spirited. If there is some smelly code out there, look for ways to make it better. Start by understanding the code, and then find ways to improve upon it. If you start to notice a negativity trend in your own projects, don't adhere. If someone says to you "this code is shit" ask them why, and then go through and work on making it better. Talk to the person who wrote the code originally, perhaps there is a reason why they did it that way. Work with your teammates not against them.

Next time I notice a suspicious smell wafting from my monitor, I'm going to turn to my coworker and ask, "How can we improve this?" Because, lets face it, sometimes code is shit, but that doesn't mean we have to be too.


不良编程文化


“这代码真垃圾”,当我们翻查一些代码寻找一个特别讨厌的bug时,同事大声这样说。“是吗”,我回答到。

像这样的谴责,以及其它一些类似的话,在办公室里经常会听到,而且频率在增加。而最令人不安的是,这代码并不是特别的糟糕。我这话是什么意思?不能把它们写的更好吗?当然!大多数的代码都有改善的空间——只要有足够的时间和资源。垃圾代码确实有,我们都看得见,而且都是我们自己写的,但这并不是问题。

问题是我们有一个不良的“这代码真垃圾”文化。

这是一种我感觉在web开发社区中越来越常见的文化。接着上面的例子,我请同事解释一下,解释为什么这代码很垃圾,我得不到一个直接的答复。

“这还不垃圾,你看这代码”,他回答说,那种趾高气扬我需要仰头才能看到他,紧邹的眉头就好象是说,如果不能看出这代码有多烂,那就是个傻子。结果你知道怎么着?我开始感觉有点傻了。我差点就忍不住开始跟着他一起嘲笑,认定这代码真的有多烂,多糟糕。

在我继续下面的内容之前,我发现上面的内容并没有在最好的光线下描绘我的同事。所以,让我弥补一下。他是个非常好的小伙。坦白的说,他是我见过的最和善的小伙之一。他友善,有一个他很爱的家庭,他跑马拉松,乐于助人,聪明,等等等等。还有一点要说明:他是一个经验不多的新手。他还在学一些基础的开发知识。这没什么好羞愧的,我们都经历过这个阶段。那么,为什么这样一个友善、聪明的小伙,在他参与的第一个大型web项目上,他的第一反应就是去指责一些代码很垃圾?——他甚至还没有真正的去理解它。

生活规律:垃圾往下倒。

这个问题并不单独出现在程序员新手中。很多精明人士都有这习惯。你也许是一个奇才,一个久经考验的程序员,但如果有这样一种习惯,整个团队和项目都会受到负面影响。因为新手们把你当作知识和经验的源泉。越多的人拥抱这种“这代码真垃圾”文化,这种文化就会越被认可,越成为模仿的对象。很快,程序员开始变的不是积极在项目上出力,而是去贬低别人在项目上的贡献。最大嘴、最反面的程序员很快就成了最受尊敬的人。所有人都受折磨,项目受影响,而一部分人却能得到赞美,为到处都是垃圾而感到心满意足。

我们应该怎么做?

没有人想显得愚蠢,没有人想自己的工作被认为劣质。一旦“这代码真垃圾”文化开始传播,唯一能确保自己在别人之上的办法就是贬低别人。最终,这变成了一种负能量,而不是想着去解决问题。

那么,对这样的一种特殊现象有什么解决方法?阻止它。不要不加思索的否定别人的代码——在没有原因、没有理解的情况下。有很多的方式可以处理那些看起来有问题的代码。如果发现代码中有异味,想办法改进它。从理解这些代码开始,在此基础上修正。如果你发现项目中有一些不良风气,不要跟随。如果有人对你说“这代码真垃圾”,问他为什么,然后了解查明,去做一些事情让它变的不垃圾。向最初写这些代码的人了解,也许他们这样写代码是有原因的。帮助他们,而不是诋毁他们。

下一次,当我发现从显示器里飘出可疑的异味时,我会转身问我的同事,“我们如何改进这段代码?”因为,我们要面对它们,有时候代码会很垃圾,但这不意味着我们也去变成垃圾。

英文原文地址:http://www.fraustollc.com/blog/shit_code/

中文翻译地址:http://www.aqee.net/code-culture-problem/

原创粉丝点击