Imagine you work for a small lean software company. You know the future competitiveness of the company is in having a good reusable code base to draw upon. It’s going to be very important to manage the company’s re-use policy to ensure you deliver today, at the same time as providing a back-bone for the future.
想象一下,你为一家小型精益软件公司工作。您知道公司未来的竞争力在于拥有良好的可重用代码库。管理公司的再利用政策以确保您今天的交付,同时为未来提供支持,这将是非常重要的。
In my mind there are two reasons to write re-usable code in business; 1) To share within the company to improve speed and efficiency in the future 2) To publish on the web and other people will help improve the code (crowd-sourcing in a sense).
在我看来,在业务中编写可重用代码有两个原因; 1)在公司内共享以提高未来的速度和效率2)在网络上发布和其他人将有助于改进代码(从某种意义上说是众包)。
Developers should always apply common sense to re-use of course. But to get a handle on this from a management perspective I want some overall code-reuse guidelines to ensure we are competitive now and in the future. These guidelines should encourage the developer to ask “Is my code a Candidate for Re-use?”. What should these guidelines say?
开发人员应该始终运用常识来重复使用。但是为了从管理角度处理这个问题,我想要一些整体的代码重用指南,以确保我们现在和将来都具有竞争力。这些指南应鼓励开发人员询问“我的代码是否为重用候选人?”。这些指导方针应该说什么?
My initial thoughts: It’s not worth writing re-usable code at the lowest levels (e.g. I have some in-line code which adds a “’s” to the end of a string), there would be far too much of this code to even sift through and find that someone has already done it. It’s also not worth writing re-usable code at the top-most level i.e. the application because your customer reporting application would end up being genericised into a SQL client – useless to most users.
我最初的想法:在最低级别编写可重用的代码是不值得的(例如,我有一些内联代码在字符串的末尾添加了一个“s”),这个代码的代码太多了。甚至筛选,发现有人已经做过了。在最顶层(即应用程序)编写可重用代码也是不值得的,因为您的客户报告应用程序最终会被通用化为SQL客户端 - 对大多数用户来说是无用的。
Main barriers to re-usable code: You can’t re-use it unless you know it exists; Trust – It’s been done but do you trust it?; Initial time taken to make the code generic/re-usable (and to document it).
可重复使用代码的主要障碍:除非您知道它存在,否则不能重复使用它;信任 - 它已经完成,但你相信吗?使代码通用/可重用(并记录)的初始时间。
7 个解决方案
#1
You can spend a long time trying to make something reusable, without anyone reusing it. So I usually follow the maxim that I only make something reusable when it's going to be reused (there are a few exceptions that will stand out).
您可以花很长时间尝试重复使用某些内容,而无需重复使用它。因此,我通常遵循这样的格言,即只有在重复使用时才能重复使用(有一些例外情况会突出)。
Often it's only when you come to reuse something that your client says "I want it to do the same, except..." or similar. It's only at that point that you understand which part of your reusable code is reusable, and what needs to be parameterised (e.g. via strategy patterns or similar)
通常情况下,只有当你来重复使用客户所说的“我希望它做同样的事情,除了......”或类似的东西时。只有在这一点上,您才能了解可重用代码的哪一部分是可重用的,以及需要参数化的内容(例如,通过策略模式或类似方法)
Consequently I don't tend to regard code as reusable unless it's really been reused :-)
因此,我不倾向于将代码视为可重用的,除非它真的被重用:-)
#2
I think the better idea is to never make code reusable.
我认为更好的想法是永远不要让代码可重用。
Instead, when you find two pieces of code that are very similar, refactor them - pull the common code out and leave the differences in. Rerun your unit tests, and when they succeed, you're done.
相反,当你发现两段非常相似的代码时,重构它们 - 将公共代码拉出来并留下差异。重新运行你的单元测试,当它们成功时,你就完成了。
You did have unit tests, right?
你确实有单元测试,对吧?
#3
In Germany, we say: The truth lies in the middle
在德国,我们说:真相在于中间
You marked two extremes here, but they are a good start. When you are to low-level, you will win nothing. Your reusable code should be worth the effort. When it does something, a mid-class programmer can implement in 3-7 lines or in 1-3 minutes, it might not be worth it, unless it is really, really needed often!
你在这里标出了两个极端,但它们是一个好的开始。当你处于低级别时,你将一无所获。您的可重用代码应该值得付出努力。当它做某事时,一个中产阶级程序员可以在3-7行或1-3分钟内实现,它可能不值得,除非它真的,真的经常需要!
The other extreme is the generic SQL client. Of course, the reuse should not lay any burden on the user. That is a definitive no-no!
另一个极端是通用SQL客户端。当然,重用不应该给用户带来任何负担。这是一个明确的禁忌!
In my opinion, you should think about your project and then have a careful watch, what parts could be needed in multiple situations. These are candidates for reuse. But there are also other factors, you should check the candidates against, before you make the code reusable:
在我看来,你应该考虑你的项目,然后仔细观察,在多种情况下可能需要哪些部分。这些是重用的候选者。但是在您重复使用代码之前,还有其他因素,您应该检查候选者:
- Will the extra effort (see below) be worth it? (3-7 liners!)
- Does it lay extra burden on reusers and/or users?
- How often will it be reused (estimated)
- Can I decide now? (You might not have enough experience right now -- then better delay it and implement some use-cases as standalone, before making it reusable)
- Can I really generalize all the details that much, that I can have one single code-line? Special cases can be the death of reuse ...
额外的努力(见下文)是否值得? (3-7个衬里!)
是否会给重用者和/或用户带来额外负担?
它的使用频率(估计)
我现在可以决定吗? (您现在可能没有足够的经验 - 然后更好地延迟它并将其作为独立实现一些用例,然后再使其可重用)
我能否真正概括所有细节,我可以拥有一个代码行吗?特殊情况可能是重复使用的死亡......
You might find further factors. I wanted to give some adhoc examples.
您可能会发现更多因素。我想举几个例子。
I think, "Think first" is the best rule of thumb for reuse ... and of course reuse needs much experience.
我认为,“先思考”是重用的最佳经验法则......当然,重用需要很多经验。
Also it needs extra effort:
它还需要额外的努力:
That is a really main point, many people forget. Reuse does not come free! You have to pay for it.
这是一个非常重要的观点,很多人都忘了。重用不是免费的!你必须付钱。
You have extra costs for:
您需要支付额外费用:
- Extra guessing, how to make it really universal
- Extra-Asking all the potential consumers
- Extra-Documenting, since the consumers will only use it, when it really is simple to use
- Extra-Advertising, since potential consumers must know, that there exists something reusable and that is worthwhile to reuse.
额外的猜测,如何让它真正普及
额外询问所有潜在消费者
Extra-Documenting,因为消费者只会使用它,当它真的很容易使用时
由于潜在消费者必须知道,因此存在可重复使用且值得重复使用的额外广告。
Also you have to establish a reuse-culture, what is not easy, since it goes against the fealings of plenty developers. All developers think that only them have found the holy-grail and only their code is good at all. So many people will be offended and resist reusing code. The resistence can be either open but also hidden to the bosses (which might be the worst). Also the management must be aware of reuse. Without management backup, you will not have a substantial reuse-culture in your company.
此外,你必须建立一个重用文化,这是不容易的,因为它违背了大量开发人员的成功。所有开发人员都认为只有他们才能找到圣杯,只有他们的代码才是好的。这么多人会被冒犯并拒绝重用代码。抵抗可以是开放的,也可以隐藏给老板(这可能是最糟糕的)。管理层也必须意识到重用。如果没有管理备份,您的公司将无法获得实质性的重用文化。
So, there is a price-tag attached to it. But it is worthwile, when you manage to really pay the price!
所以,附有价格标签。但是,当你真的付出代价时,它是值得的!
#4
Only make general code reusable. A function that only appends an s last in a string will not be of value except where it is already used, but a function that can add any one or more characters to the end of a string would be useful for other uses too.
只能使通用代码可重用。只在字符串中附加s last的函数除了已经使用的函数之外没有任何价值,但是一个可以在字符串末尾添加任何一个或多个字符的函数对其他用途也很有用。
Basic functionality; if you have your own functions and types for lists, trees, sockets and/or file handling, all these can be useful in the shared libraries.
基本功能;如果你有自己的列表,树,套接字和/或文件处理的函数和类型,那么所有这些在共享库中都很有用。
Also, you can comment on all functions and types and use a system like Doxygen (or Javadoc) and then automatically generate the documentation, which would make it searchable even outside an IDE and presented in a somewhat nice way.
此外,您可以评论所有函数和类型,并使用像Doxygen(或Javadoc)这样的系统,然后自动生成文档,这使得它甚至可以在IDE之外进行搜索,并以一种不太好的方式呈现。
#5
All well-written code is a candidate for re-use.
所有编写良好的代码都是重用的候选者。
If you take the time to make code generic and documented, not only can you re-use the code in another project, others will actually look at your code. This will greatly improve the probability of anyone finding bugs/quirks before your users do.
如果你花时间使代码通用并记录在案,那么你不仅可以在另一个项目中重用代码,其他人实际上会查看你的代码。这将极大地提高任何人在用户之前发现错误/怪癖的可能性。
The main thing is to make a good distinction where code should be. To take the 'add an "s" to a string' example - this could be code that is put somewhere in a strings-util library along with the 'add an "h" to a string' and 'add a "b" to a string' functions. When you see those three functions together, you'll probably get the idea of making a more generic 'add any character to a string' function, thus making the code even more reusable - you can also add the letter 'r' to a string now!
主要的是在代码应该是一个很好的区别。要把'添加's“带到一个字符串'的例子中 - 这可能是代码放在strings-util库中,同时'添加'h”到字符串'和'添加“b”到一个字符串'的功能。当你看到这三个函数在一起时,你可能会想到一个更通用的“为字符串添加任何字符”函数,从而使代码更加可重用 - 你也可以在字符串中添加字母'r'现在!
The only way that you are going to spot the fact that you are appending characters to a string all the time is to make sure these functions live next to each other - otherwise everyone will have the same functions hidden somewhere in the code.
您要发现将字符追加到字符串的唯一方法是确保这些函数彼此相邻 - 否则每个人都会在代码中的某处隐藏相同的函数。
These kinds of util collections/classes/whatever contain the low-level pieces of code - they are generic, and don't seem to hold any relevance to a specific project.
这些类型的util集合/类/包含低级代码片段 - 它们是通用的,并且似乎与特定项目没有任何关联。
The higher-end of the scale should also be treated as reusable code. Say for instance you have a customer with a great new idea, like adding images on a website. Nobody else needs this, so you go ahead and add the tag specifically for this client. Two weeks later, you have another client who asks you for the exact same thing.
比例的高端也应被视为可重复使用的代码。比如说你有一个有很好新想法的顾客,比如在网站上添加图片。没有其他人需要这个,所以你继续为这个客户专门添加标签。两周后,你有另一个客户问你完全相同的事情。
What usually happens in a situation like this is that the extra code for your first client gets copied into the project of the second client - just because it looks like it is the fastest way to get things working. What is actually happening, is that the maintanability of the code is degraded. You now have the same piece of code in two places, with the same bugs. I think we all know this leads to problems in the future.
在这种情况下通常会发生的情况是,您的第一个客户端的额外代码被复制到第二个客户端的项目中 - 只是因为它看起来是最快速的工作方式。实际发生的是,代码的可维护性降低了。您现在在两个地方拥有相同的代码,具有相同的错误。我想我们都知道这会导致将来出现问题。
If the example was written for reusability, you can use it again in the second project, saving time and effort. Also, the added features that your next client asks are probably something you can offer the first client as an upgrade - (see, you can set the height and width now, woohoo!)
如果该示例是为可重用性而编写的,则可以在第二个项目中再次使用它,从而节省时间和精力。此外,您的下一个客户端要求的附加功能可能是您可以提供第一个客户端作为升级 - (请参阅,您现在可以设置高度和宽度,哇!)
As for knowing that code exists, that is a problem that will always remain there. I think the fastest way to spread this knowledge is to make sure developers don't develop on their own - pair programming is a good example of this. This way, whenever something is written, at least two people will know about it. If you regularly mix up the pairs, the knowledge will spread through the company without any extra effort.
至于知道代码存在,这是一个永远存在的问题。我认为传播这些知识的最快方法是确保开发人员不自己开发 - 结对编程就是一个很好的例子。这样,每当写完东西时,至少有两个人会知道它。如果您经常混淆对,那么知识将通过公司传播而无需任何额外的努力。
#6
I would reuse and continually support/refactor:
我会重用并不断支持/重构:
- all libraries that do a specific task well
- clients to a specific service, as long as the service doesn't dramatically change
- the business layer/model, as long as the business cases are not thrown away
- the web/desktop interface, as long as it can still serve it's function well
所有能够完成特定任务的图书馆
客户到特定服务,只要服务没有显着变化
业务层/模型,只要业务案例不被丢弃
网络/桌面界面,只要它仍然可以很好地服务它的功能
I would throw away (delete from scm) and rewrite from scratch:
我会扔掉(从scm中删除)并从头开始重写:
- any library that is poorly written; that tries to do several tasks and does them all badly
- a client to a service when the service is completely rewritten, changed with a different technology (database changed with web service)
- the business layer/model when it no longer serves anything
- the interface when the client wants major changes, or when switching to a different framework
任何写得不好的图书馆;试图完成几项任务并完成所有任务
服务完全重写后,服务的客户端,使用不同的技术进行更改(使用Web服务更改数据库)
当业务层/模型不再提供任何服务时
客户端想要进行重大更改时,或切换到其他框架时的接口
#7
I tend to build reusable libraries only when I'm sure that I'll need the functionality at least one other time, and that the time taken to make the code into a stand-alone library is less than the time taken to rebuild or copy code in. Furthermore, the library being created must solve exactly one problem, which prevents me from building giant balls of code that are too wide in their scope to be of use.
我倾向于只在我确定至少在其他时间需要这个功能时构建可重用的库,并且将代码放入独立库所花费的时间少于重建或复制所需的时间此外,正在创建的库必须解决一个问题,这使我无法构建范围太广而无法使用的巨大代码球。
A recent example of this was a plugin designed to provide an interface between an app and the Protx payment system. I's something that solves one problem, and has been used in several different projects so far.
最近的一个例子是一个插件,旨在提供应用程序和Protx支付系统之间的接口。我解决了一个问题,到目前为止已经在几个不同的项目中使用过。
#1
You can spend a long time trying to make something reusable, without anyone reusing it. So I usually follow the maxim that I only make something reusable when it's going to be reused (there are a few exceptions that will stand out).
您可以花很长时间尝试重复使用某些内容,而无需重复使用它。因此,我通常遵循这样的格言,即只有在重复使用时才能重复使用(有一些例外情况会突出)。
Often it's only when you come to reuse something that your client says "I want it to do the same, except..." or similar. It's only at that point that you understand which part of your reusable code is reusable, and what needs to be parameterised (e.g. via strategy patterns or similar)
通常情况下,只有当你来重复使用客户所说的“我希望它做同样的事情,除了......”或类似的东西时。只有在这一点上,您才能了解可重用代码的哪一部分是可重用的,以及需要参数化的内容(例如,通过策略模式或类似方法)
Consequently I don't tend to regard code as reusable unless it's really been reused :-)
因此,我不倾向于将代码视为可重用的,除非它真的被重用:-)
#2
I think the better idea is to never make code reusable.
我认为更好的想法是永远不要让代码可重用。
Instead, when you find two pieces of code that are very similar, refactor them - pull the common code out and leave the differences in. Rerun your unit tests, and when they succeed, you're done.
相反,当你发现两段非常相似的代码时,重构它们 - 将公共代码拉出来并留下差异。重新运行你的单元测试,当它们成功时,你就完成了。
You did have unit tests, right?
你确实有单元测试,对吧?
#3
In Germany, we say: The truth lies in the middle
在德国,我们说:真相在于中间
You marked two extremes here, but they are a good start. When you are to low-level, you will win nothing. Your reusable code should be worth the effort. When it does something, a mid-class programmer can implement in 3-7 lines or in 1-3 minutes, it might not be worth it, unless it is really, really needed often!
你在这里标出了两个极端,但它们是一个好的开始。当你处于低级别时,你将一无所获。您的可重用代码应该值得付出努力。当它做某事时,一个中产阶级程序员可以在3-7行或1-3分钟内实现,它可能不值得,除非它真的,真的经常需要!
The other extreme is the generic SQL client. Of course, the reuse should not lay any burden on the user. That is a definitive no-no!
另一个极端是通用SQL客户端。当然,重用不应该给用户带来任何负担。这是一个明确的禁忌!
In my opinion, you should think about your project and then have a careful watch, what parts could be needed in multiple situations. These are candidates for reuse. But there are also other factors, you should check the candidates against, before you make the code reusable:
在我看来,你应该考虑你的项目,然后仔细观察,在多种情况下可能需要哪些部分。这些是重用的候选者。但是在您重复使用代码之前,还有其他因素,您应该检查候选者:
- Will the extra effort (see below) be worth it? (3-7 liners!)
- Does it lay extra burden on reusers and/or users?
- How often will it be reused (estimated)
- Can I decide now? (You might not have enough experience right now -- then better delay it and implement some use-cases as standalone, before making it reusable)
- Can I really generalize all the details that much, that I can have one single code-line? Special cases can be the death of reuse ...
额外的努力(见下文)是否值得? (3-7个衬里!)
是否会给重用者和/或用户带来额外负担?
它的使用频率(估计)
我现在可以决定吗? (您现在可能没有足够的经验 - 然后更好地延迟它并将其作为独立实现一些用例,然后再使其可重用)
我能否真正概括所有细节,我可以拥有一个代码行吗?特殊情况可能是重复使用的死亡......
You might find further factors. I wanted to give some adhoc examples.
您可能会发现更多因素。我想举几个例子。
I think, "Think first" is the best rule of thumb for reuse ... and of course reuse needs much experience.
我认为,“先思考”是重用的最佳经验法则......当然,重用需要很多经验。
Also it needs extra effort:
它还需要额外的努力:
That is a really main point, many people forget. Reuse does not come free! You have to pay for it.
这是一个非常重要的观点,很多人都忘了。重用不是免费的!你必须付钱。
You have extra costs for:
您需要支付额外费用:
- Extra guessing, how to make it really universal
- Extra-Asking all the potential consumers
- Extra-Documenting, since the consumers will only use it, when it really is simple to use
- Extra-Advertising, since potential consumers must know, that there exists something reusable and that is worthwhile to reuse.
额外的猜测,如何让它真正普及
额外询问所有潜在消费者
Extra-Documenting,因为消费者只会使用它,当它真的很容易使用时
由于潜在消费者必须知道,因此存在可重复使用且值得重复使用的额外广告。
Also you have to establish a reuse-culture, what is not easy, since it goes against the fealings of plenty developers. All developers think that only them have found the holy-grail and only their code is good at all. So many people will be offended and resist reusing code. The resistence can be either open but also hidden to the bosses (which might be the worst). Also the management must be aware of reuse. Without management backup, you will not have a substantial reuse-culture in your company.
此外,你必须建立一个重用文化,这是不容易的,因为它违背了大量开发人员的成功。所有开发人员都认为只有他们才能找到圣杯,只有他们的代码才是好的。这么多人会被冒犯并拒绝重用代码。抵抗可以是开放的,也可以隐藏给老板(这可能是最糟糕的)。管理层也必须意识到重用。如果没有管理备份,您的公司将无法获得实质性的重用文化。
So, there is a price-tag attached to it. But it is worthwile, when you manage to really pay the price!
所以,附有价格标签。但是,当你真的付出代价时,它是值得的!
#4
Only make general code reusable. A function that only appends an s last in a string will not be of value except where it is already used, but a function that can add any one or more characters to the end of a string would be useful for other uses too.
只能使通用代码可重用。只在字符串中附加s last的函数除了已经使用的函数之外没有任何价值,但是一个可以在字符串末尾添加任何一个或多个字符的函数对其他用途也很有用。
Basic functionality; if you have your own functions and types for lists, trees, sockets and/or file handling, all these can be useful in the shared libraries.
基本功能;如果你有自己的列表,树,套接字和/或文件处理的函数和类型,那么所有这些在共享库中都很有用。
Also, you can comment on all functions and types and use a system like Doxygen (or Javadoc) and then automatically generate the documentation, which would make it searchable even outside an IDE and presented in a somewhat nice way.
此外,您可以评论所有函数和类型,并使用像Doxygen(或Javadoc)这样的系统,然后自动生成文档,这使得它甚至可以在IDE之外进行搜索,并以一种不太好的方式呈现。
#5
All well-written code is a candidate for re-use.
所有编写良好的代码都是重用的候选者。
If you take the time to make code generic and documented, not only can you re-use the code in another project, others will actually look at your code. This will greatly improve the probability of anyone finding bugs/quirks before your users do.
如果你花时间使代码通用并记录在案,那么你不仅可以在另一个项目中重用代码,其他人实际上会查看你的代码。这将极大地提高任何人在用户之前发现错误/怪癖的可能性。
The main thing is to make a good distinction where code should be. To take the 'add an "s" to a string' example - this could be code that is put somewhere in a strings-util library along with the 'add an "h" to a string' and 'add a "b" to a string' functions. When you see those three functions together, you'll probably get the idea of making a more generic 'add any character to a string' function, thus making the code even more reusable - you can also add the letter 'r' to a string now!
主要的是在代码应该是一个很好的区别。要把'添加's“带到一个字符串'的例子中 - 这可能是代码放在strings-util库中,同时'添加'h”到字符串'和'添加“b”到一个字符串'的功能。当你看到这三个函数在一起时,你可能会想到一个更通用的“为字符串添加任何字符”函数,从而使代码更加可重用 - 你也可以在字符串中添加字母'r'现在!
The only way that you are going to spot the fact that you are appending characters to a string all the time is to make sure these functions live next to each other - otherwise everyone will have the same functions hidden somewhere in the code.
您要发现将字符追加到字符串的唯一方法是确保这些函数彼此相邻 - 否则每个人都会在代码中的某处隐藏相同的函数。
These kinds of util collections/classes/whatever contain the low-level pieces of code - they are generic, and don't seem to hold any relevance to a specific project.
这些类型的util集合/类/包含低级代码片段 - 它们是通用的,并且似乎与特定项目没有任何关联。
The higher-end of the scale should also be treated as reusable code. Say for instance you have a customer with a great new idea, like adding images on a website. Nobody else needs this, so you go ahead and add the tag specifically for this client. Two weeks later, you have another client who asks you for the exact same thing.
比例的高端也应被视为可重复使用的代码。比如说你有一个有很好新想法的顾客,比如在网站上添加图片。没有其他人需要这个,所以你继续为这个客户专门添加标签。两周后,你有另一个客户问你完全相同的事情。
What usually happens in a situation like this is that the extra code for your first client gets copied into the project of the second client - just because it looks like it is the fastest way to get things working. What is actually happening, is that the maintanability of the code is degraded. You now have the same piece of code in two places, with the same bugs. I think we all know this leads to problems in the future.
在这种情况下通常会发生的情况是,您的第一个客户端的额外代码被复制到第二个客户端的项目中 - 只是因为它看起来是最快速的工作方式。实际发生的是,代码的可维护性降低了。您现在在两个地方拥有相同的代码,具有相同的错误。我想我们都知道这会导致将来出现问题。
If the example was written for reusability, you can use it again in the second project, saving time and effort. Also, the added features that your next client asks are probably something you can offer the first client as an upgrade - (see, you can set the height and width now, woohoo!)
如果该示例是为可重用性而编写的,则可以在第二个项目中再次使用它,从而节省时间和精力。此外,您的下一个客户端要求的附加功能可能是您可以提供第一个客户端作为升级 - (请参阅,您现在可以设置高度和宽度,哇!)
As for knowing that code exists, that is a problem that will always remain there. I think the fastest way to spread this knowledge is to make sure developers don't develop on their own - pair programming is a good example of this. This way, whenever something is written, at least two people will know about it. If you regularly mix up the pairs, the knowledge will spread through the company without any extra effort.
至于知道代码存在,这是一个永远存在的问题。我认为传播这些知识的最快方法是确保开发人员不自己开发 - 结对编程就是一个很好的例子。这样,每当写完东西时,至少有两个人会知道它。如果您经常混淆对,那么知识将通过公司传播而无需任何额外的努力。
#6
I would reuse and continually support/refactor:
我会重用并不断支持/重构:
- all libraries that do a specific task well
- clients to a specific service, as long as the service doesn't dramatically change
- the business layer/model, as long as the business cases are not thrown away
- the web/desktop interface, as long as it can still serve it's function well
所有能够完成特定任务的图书馆
客户到特定服务,只要服务没有显着变化
业务层/模型,只要业务案例不被丢弃
网络/桌面界面,只要它仍然可以很好地服务它的功能
I would throw away (delete from scm) and rewrite from scratch:
我会扔掉(从scm中删除)并从头开始重写:
- any library that is poorly written; that tries to do several tasks and does them all badly
- a client to a service when the service is completely rewritten, changed with a different technology (database changed with web service)
- the business layer/model when it no longer serves anything
- the interface when the client wants major changes, or when switching to a different framework
任何写得不好的图书馆;试图完成几项任务并完成所有任务
服务完全重写后,服务的客户端,使用不同的技术进行更改(使用Web服务更改数据库)
当业务层/模型不再提供任何服务时
客户端想要进行重大更改时,或切换到其他框架时的接口
#7
I tend to build reusable libraries only when I'm sure that I'll need the functionality at least one other time, and that the time taken to make the code into a stand-alone library is less than the time taken to rebuild or copy code in. Furthermore, the library being created must solve exactly one problem, which prevents me from building giant balls of code that are too wide in their scope to be of use.
我倾向于只在我确定至少在其他时间需要这个功能时构建可重用的库,并且将代码放入独立库所花费的时间少于重建或复制所需的时间此外,正在创建的库必须解决一个问题,这使我无法构建范围太广而无法使用的巨大代码球。
A recent example of this was a plugin designed to provide an interface between an app and the Protx payment system. I's something that solves one problem, and has been used in several different projects so far.
最近的一个例子是一个插件,旨在提供应用程序和Protx支付系统之间的接口。我解决了一个问题,到目前为止已经在几个不同的项目中使用过。