什么时候最好更改代码以符合标准?

发布于 2024-07-13 09:08:34 字数 647 浏览 7 评论 0原文

我最近负责调试两个不同的程序,它们最终至少需要共享一个 XML 解析脚本。 一个是用 PureMVC 编写的,另一个是从头开始构建的。 虽然最初从头开始编写是有意义的(它节省了大量内存,但内存问题已得到解决)。

移植非 PureMVC 应用程序将花费大量时间和精力,这并不需要使用,但它将使文档和代码共享变得更容易。 它还将降低整体学习曲线。 考虑到这一点:

1. 在考虑是否最好将事物转移到一个标准时应该考虑什么?


(相关说明)

有些代码有点奇怪。 由于解释应用程序必须将命令从一种语法转换为另一种语法,因此拥有解释器对象是有意义的。 因为需要与外部环境进行通信,所以让一个对象与环境交互更有意义,并且为此专门与解释器打交道。

实际上,创建了一个反单例模式。 该对象只会与解释器交互,仅此而已。 如果另一个类的成员尝试调用其公共方法之一,该对象将引发异常。

有更好的方法可以实现这一点,但这确实有点奇怪。 有更标准的方法可以完成同样的事情,尽管它们通常涉及创建非常大的类或类文件。 我能找到的唯一符合标准的解决方案将涉及当前所需的尽可能多的评论和解释,甚至更多。 考虑到这一点:

2. 如果某些代码很古怪,但很有效,那么是否最好对其进行更改以使其不那么古怪,即使它变得更加笨拙?

I have recently been put in charge of debugging two different programs which will eventually need to share an XML parsing script, at the minimum. One was written with PureMVC, and another was built from scratch. While it made sence, originally, to write the one from scratch (it saved a good deal of memory, but the memory problems have since been resolved).

Porting the non-PureMVC application will take a good deal of time and effort which does not need to be used, but it will make documentation and code-sharing easier. It will also lower the overall learning curve. With that in mind:

1. What should be taken into account when considering whether it is best to move things to one standard?


(On a related note)

Some of the code is a little odd. Because the interpreting App had to convert commands from one syntax to another, it made sense to have an interpreter Object. Because there needed to be communication with the external environment, it made more sense to have one object interact with the environment, and for that to deal with the interpreter exclusively.

Effectively, an anti-Singleton was created. The object would only interface with the interpreter, and that's it. If a member of another class were to try to call one of its public methods, the object would raise an Exception.

There are better ways to accomplish this, but it is definitely a bit odd. There are more standard means of accomplishing the same thing, though they often involve the creation of classes or class files which are extraordinarily large. The only solution which I could find that was standards compliant would involve as much commenting and explanation as is currently required, if not more. Considering this:

2. If some code is quirky, but effective, is it better to change it to make it less quirky, even if it is made a more unwieldy?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

痞味浪人 2024-07-20 09:08:34

在我看来,这种类型的重构通常不会被纳入日程安排中,只能在有额外时间的情况下进行。

通常,运输代码的标准是它是否有效,不一定是最好的代码解决方案

因此,在回答您的问题时,当我有时间时,我会尝试进行重构。 首要任务仍然是生成一段功能性代码。

In my opinion this type of refactoring is often not considered in schedules and can only be done when there is extra time.

More often than not, the criterion for shipping code is if it works, not necessarily if it's the best possible code solution.

So in answer to your question, I try and refactor when I have time to do so. Priority One still remains to produce a functional piece of code.

清风疏影 2024-07-20 09:08:34

需要考虑的事项:

  • 它是否按原样工作?

正如高威吉安所说,这是许多商店的唯一标准。 然而,在我看来,同样重要的是:

  • 将要维护它的程序员有多熟练? 他们遇到过非标准代码吗? 将他们学习它的时间成本(包括延迟点发布的成本)与您重构它的时间成本进行比较。

如果您正在维护它,那么请考虑:

  • 在代码库的预期生命周期(例如,从现在到重写整个代码之间的时间),处理非标准代码会花费您多少时间?

这很难猜测,但考虑到许多代码库的寿命远远超过了其原作者设想的有用性。 (Y2K 有人吗?)我逐渐形成了一种感觉,即什么时候值得重构,什么时候不值得,主要是因为经常犯“不”的错误,然后后悔。

Things to take into account:

  • Does it work as-is?

As Galwegian notes, this is the only criterion in many shops. However, IMO just as important is:

  • How skilled are the programmers who are going to maintain it? Have they ever encountered nonstandard code? Compare the cost of their time to learn it (including the cost of delayed dot releases) to the cost of your time to refactor it.

If you're maintaining it, then instead consider:

  • How much time will dealing with the nonstandard code cost you over the intended lifecycle of the codebase (e.g., the time between now and when the whole thing is rewritten)?

That's hard to guess, but consider that many codebases FAR outlive the usefulness envisioned by their original authors. (Y2K anyone?) I've gradually developed a sense of when a refactoring is worthwhile and when it's not, mostly by erring on the side of "not" too often and regretting it later.

怎会甘心 2024-07-20 09:08:34

仅当您无论如何都需要进行更改时才更改它。 但减少古怪总是一个好的目标。 花在特定软件上的大部分时间都花在维护上,因此如果您可以采取一些措施来简化维护工作,那么您将减少花在该代码上的总时间。 尽管如此,如果某些东西正在运行并且不需要任何修改,就不要对其进行更改。

Only change it if you need to be making changes anyway. But less quirky is always a good goal. Most of the time spent on a particular piece of software is in maintenance, so if you can do something to make that easier, you'll be reducing the overall time spent on that piece of code. Nonetheless, don't change something if it's working and doesn't need any modifications.

玩世 2024-07-20 09:08:34

如果你有时间,现在就去。 如果你没有时间并且可以避免的话,稍后再说。

If you have time, now. If you don't have time and it can be avoided, later.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文