代码应该简短/简洁吗? [英] Should code be short/concise?

查看:112
本文介绍了代码应该简短/简洁吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编写数学证明时,一个目标是继续压缩证明.证明变得更加优雅,但不一定更具可读性.压缩可以消除不必要的字符和冗长,从而更好地理解.

When writing a mathematical proof, one goal is to continue compressing the proof. The proof gets more elegant but not necessarily more readable. Compression translates to better understanding, as you weed out unnecessary characters and verbosity.

我经常听到开发人员说您应该使代码占用空间尽可能小.这可以非常迅速地产生不可读的代码.在数学中,这不是问题,因为该练习纯粹是学术性的.但是,在时间就是金钱的生产代码中,让人们试图弄清楚一些非常简洁的代码在做什么似乎没有多大意义.要获得更详细的代码,您将获得可读性和节省.

I often hear developers say you should make your code foot print as small as possible. This can very quickly yield unreadable code. In mathematics, it isn't such an issue since the exercise is purely academic. However, in production code where time is money, having people try to figure out what some very concise code is doing doesn't seem to make much sense. For a little more verbose code, you get readability and savings.

什么时候停止压缩软件代码?

At what point do you stop compressing software code?

推荐答案

我试图达到冗长的程度,在此程度下,我的程序语句读起来就像任何程序员都可以理解的句子.这确实意味着要大量重构我的代码,使之成为一个故事的所有小片段,因此每个动作都将在一个单独的方法中进行描述(甚至更进一步的层次可能是到另一个类).

I try to reach a level of verbosity where my program statements read like a sentence any programmer could understand. This does mean heavily refactoring my code such that it's all short pieces of a story, so each action would be described in a separate method (an even further level might be to another class).

意思是我不会因为能用更少的字符数而减少字符数.这就是代码高尔夫球比赛的目的.

Meaning I would not reduce my number of characters just because it can be expressed in fewer. That's what code-golf competitions are for.

这篇关于代码应该简短/简洁吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆