开发一次性代码的好策略? [英] Good strategies for developing throwaway code?

查看:107
本文介绍了开发一次性代码的好策略?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常编写一次性代码(在研究环境中)-例如,探索科学特性或过程的算法或模型.这些实验"中有许多是一次性的,但有时我发现我需要稍后再使用.例如,我刚刚发掘了7年前写的用于字符串匹配的代码(由于其他优先级而停止),但现在对于同事的项目很有价值.看了一下(我真的写出了这种难以理解的代码吗?)我意识到,当我重新启动项目"时,我可以做一些事情来帮助我(实验"仍然是一个更好的词).较早的实验行得通",但我知道当时我没有时间重构,因为我的工作重点放在其他地方.

I frequently write throwaway code (in a research environment) - for example to explore an algorithm or a model for a scientific property or process. Many of these "experiments" are one-off but sometimes I find that I need to use a few later. For example I have just unearthed code for string matching I wrote 7 years ago (stopped because of other priorities) but which is now valuable for a coworker's project. Having looked at it (did I really write such impenetrable code?) I realise there are some things I could have done then to help me when I restarted the "project" ("experiment" is still a better word). The earlier experiment "worked" but I know that at the time I would not have had time to refactor as my priorities lay elsewhere.

哪些方法可以使此类工作被挖掘并重新使用,具有成本效益?

What approaches are cost-effective in enabling such work to be dug up and re-used?

编辑:由于存在超出实际来源本身的问题,我已经回答了自己的问题(如下).

EDIT: I have answered my own question (below) because there are issues beyond the actual source itself.

推荐答案

我不同意所有回答写评论"的答案.提供此功能是因为代码本身无法理解.

I disagree with all of the answers saying "write comments". That's being offered as a catch-all for the code itself not being understandable.

获取 代码完成 (Steve McConnell,第二版).如果您首先学习了编写可维护代码的技术,那将不会花费您更多的时间,并且以后您可以以更少的麻烦返回工作.

Get yourself a copy of Code Complete (Steve McConnell, 2nd edition). If you learn the techniques of writing maintainable code in the first place, it won't take you more time, and you will be able to return to your work later with less trouble.

您想要哪个:

  • 带有注释的密码?
  • 大多数没有代码就可以吗?

我非常喜欢后者,因为在未注释密码的情况下,OK代码更易于理解,而注释是原始开发人员可能犯错误的另一个地方.该代码可能是越野车,但绝不是错误.

I strongly prefer the latter, as the OK code is easier to understand in the situations where the cryptic code was uncommented, and comments are another place that the original developer can make mistakes. The code may be buggy, but it's never wrong.

一旦您对代码完成感到满意,我建议您

Once you're comfortable with Code Complete, I'd recommend The Pragmatic Programmer, as it gives slightly higher-level software-development advice.

这篇关于开发一次性代码的好策略?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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