热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

我们放弃了代码重用的想法吗?-Havewegivenupontheideaofcodereuse?

Acoupleofyearsagothemediawasrifewithallsortsofarticlesonhowtheideaofcodereusewa

A couple of years ago the media was rife with all sorts of articles on how the idea of code reuse was a simple way to improve productivity and code quality.

几年前,媒体上充斥着关于代码重用思想如何成为提高生产力和代码质量的简单方法的各种文章。

From the blogs and sites I check on a regular basis it seems as though the idea of "code reuse" has gone out of fashion. Perhaps the 'code reuse' advocates have all joined the SOA crowd instead? :-)

从我定期检查的博客和网站看来,似乎“代码重用”的想法已经过时了。也许“代码重用”倡导者已经加入了SOA人群而已? :-)

Interestingly enough, when you search for 'code reuse' in Google the second result is titled:

有趣的是,当您在Google中搜索“代码重用”时,第二个结果标题为:

"Internal Code Reuse Considered Dangerous"!

“内部代码重用被视为危险”!

To me the idea of code reuse is just common sense, after all look at the success of the apache commons project!

对我来说,代码重用的想法只是常识,毕竟看看apache commons项目的成功!

What I want to know is:

我想知道的是:

  • Do you or your company try and reuse code?
  • 您或您的公司是否尝试重用代码?

  • If so how and at what level, i.e. low level api, components or shared business logic? How do you or your company reuse code?
  • 如果是这样,在什么级别,即低级API,组件或共享业务逻辑?您或您的公司如何重用代码?

  • Does it work?
  • 它有用吗?

Discuss?


I am fully aware that there are many open source libs available and that anyone who has used .NET or the Java has reused code in some form. That is common sense!

我完全清楚有许多可用的开源库,任何使用过.NET或Java的人都会以某种形式重用代码。这是常识!

I was referring more to code reuse within an organizations rather than across a community via a shared lib etc.

我更多地指的是组织内的代码重用,而不是通过共享库等社区中的代码重用。

I originally asked;

我最初问过;

  • Do you or your company try and reuse code?
  • 您或您的公司是否尝试重用代码?

  • If so how and at what level, i.e. low level api, components or shared business logic? How do you or your company reuse code?
  • 如果是这样,在什么级别,即低级API,组件或共享业务逻辑?您或您的公司如何重用代码?

From where I sit I see very few example of companies trying to reuse code internally?

从我所在的位置,我看到很少有公司试图在内部重用代码?

If you have a piece of code which could potentially be shared across a medium size organization how would you go about informing other members of the company that this lib/api/etc existed and could be of benefit?

如果您有一段可能在中型组织中共享的代码,您将如何通知该公司的其他成员这个lib / api / etc是否存在并且可能有益?

16 个解决方案

#1


9  

The title of the article you are referring to is misleading, and is actually a very good read. Code reuse is very beneficial, but there are downsides with everything. Basically, if I remember correctly, the gist of the article is that you are sealing the code in a black box and not revisiting it, so as the original developers leave you lose the knowledge. While I see the point, I don't necessarily agree with it - at least not to a "sky is falling" regard.

您所指的文章的标题具有误导性,实际上是一个非常好的阅读。代码重用非常有用,但一切都有缺点。基本上,如果我没记错的话,文章的要点是你将代码密封在一个黑盒子里而不是重新访问它,所以原来的开发人员会让你失去知识。虽然我明白了这一点,但我并不一定同意 - 至少不是“天空正在下降”。

We actually group code reuse into more than just reusable classes, we look at the entire enterprise. Things that are more like framework enhancement or address cross-cutting concerns are put into a development framework that all of our applications use (think things like pre- and post-validation, logging, etc.). We also have business logic that is applicable to more than one application, so those sort of things get moved to a BAL core that is accessible anywhere.

我们实际上将代码重用分组到不仅仅是可重用的类中,我们看一下整个企业。更像是框架增强或地址交叉问题的事情被放入我们所有应用程序使用的开发框架中(想想验证前后的内容,日志记录等)。我们还有适用于多个应用程序的业务逻辑,因此这些东西会被移动到可在任何地方访问的BAL核心。

I think that the important thing is not to promote things for reuse if they are not going to really be reused. They should be well documented, so that new developers can have a resource to help them come up to speed, as well. Chances are, if the knowledge isn't shared, the code will eventually be reinvented somewhere else and will lead to duplication if you are not rigorous in documentation and knowledge sharing.

我认为重要的是,如果它们不能真正被重用,就不能促进重用。它们应该有详细记录,以便新开发人员可以拥有一个资源来帮助他们加快速度。如果知识没有被共享,代码最终会在其他地方被重新发明,如果您在文档和知识共享方面不严谨,将导致重复。

#2


5  

We reuse code - in fact, our developers specifically write code that can be reused in other projects. This has paid off quite nicely - we're able to start new projects quickly, and we iteratively harden our core libraries.

我们重用代码 - 实际上,我们的开发人员专门编写可以在其他项目中重用的代码。这已经得到了很好的回报 - 我们能够快速启动新项目,并且我们反复强化我们的核心库。

But one can't just write code and expect it to be re-used; code reuse requires communication among team members and other users so people know what code is available, and how to use it.

但是,人们不能只编写代码并期望它被重用;代码重用需要团队成员和其他用户之间的通信,以便人们知道可用的代码以及如何使用它。

The following things are needed for code reuse to work effectively:

代码重用有效工作需要以下内容:

  • The code or library itself
  • 代码或库本身

  • Demand for the code across multiple projects or efforts
  • 跨多个项目或工作的代码需求

  • Communication of the code's features/capabilities
  • 通信代码的功能/能力

  • Instructions on how to use the code
  • 有关如何使用代码的说明

  • A commitment to maintaining and improving the code over time
  • 承诺随着时间的推移维护和改进代码

#3


3  

Code reuse is essential. I find that it also forces me to generalize as much as possible, also making code more adaptable to varying situations. Ideally, almost every lower level library you write should be able to adapt to a new set of requirements for a different application.

代码重用至关重要。我发现它也迫使我尽可能地概括,也使代码更适应不同的情况。理想情况下,您编写的几乎每个低级库都应该能够适应不同应用程序的一组新要求。

#4


2  

I think code reuse is being done through open source projects for the most part. Anything that can be reused or extended is being done via libraries. Java has an amazing number of open source libraries available for doing a large number of things. Compare that to C++, and how early on everything would have to be implemented from scratch using MFC or the Win32 API.

我认为代码重用大部分都是通过开源项目完成的。任何可以重复使用或扩展的东西都是通过库完成的。 Java拥有大量可用于执行大量操作的开源库。与C ++相比,使用MFC或Win32 API必须从头开始实现早期。

#5


1  

We reuse code.

我们重用代码。

On a small scale we try to avoid code duplication as much as posible. And we have a complete library with a lot of frequently used code.

在小范围内,我们尽量避免代码重复。我们有一个包含大量常用代码的完整库。

Normally code is developed for one application. And if it is generic enough, it is promoted to the library. This works excelent.

通常,代码是为一个应用程序开发的。如果它足够通用,它将被提升到库中。这非常有效。

#6


1  

The idea of code reuse is no longer a novel idea...hence the apparent lack of interest. But it is still very much a good idea. The entire .NET framework and the Java API are good examples of code reuse in action.

代码重用的想法不再是一个新颖的想法......因此显然缺乏兴趣。但它仍然是一个好主意。整个.NET框架和Java API都是代码重用的好例子。

We have grown accustomed to developing OO libraries of code for our projects and reusing them in other projects. Its a part of the natural life cycle of an idea. It is hotly debated for a while and then everyone accepts and there is no reason for further discussion.

我们已经习惯于为我们的项目开发OO代码库并在其他项目中重用它们。它是一个想法的自然生命周期的一部分。它有一段时间激烈争论,然后每个人都接受,没有理由进一步讨论。

#7


1  

Of course we reuse code.

当然我们重用代码。

There are a near infinite amount of packages, libraries and shared objects available for all languages, with whole communities of developers behing them supporting and updating.

所有语言都有无穷无尽的包,库和共享对象,整个开发人员社区都在支持和更新它们。

#8


1  

I think the lack of "media attention" is due to the fact that everyone is doing it, so it's no longer worth writing about. I don't hear as many people raising awareness of Object-Oriented Programming and Unit Testing as I used to either. Everyone is already aware of these concepts (whether they use them or not).

我认为缺乏“媒体关注”是因为每个人都在这样做,因此不再值得写。我没有听到像以前那样提高对面向对象编程和单元测试的认识的人。每个人都已经意识到这些概念(无论他们是否使用它们)。

#9


1  

Level of media attention to an issue has little to do with its importance, whether we're talking software development or politics! It's important to avoid wasting development effort by reinventing (or re-maintaining!) the wheel, but this is so well-known by now that an editor probably isn't going to get excited by another article on the subject.

媒体对某个问题的关注程度与其重要性无关,无论我们是在讨论软件开发还是政治问题!重要的是避免通过重新发明(或重新维护!)轮子来浪费开发工作,但现在众所周知,编辑可能不会对另一篇关于该主题的文章感到兴奋。

Rather than looking at the number of current articles and blog posts as a measure of importance (or urgency) look at the concepts and buzz-phrases that have become classics or entered the jargon (another form of reuse!) For example, Google for uses of the DRY acronym for good discussion on the many forms of redundancy that can be eliminated in software and development processes.

而不是将当前文章和博客文章的数量视为重要性(或紧迫性)的衡量标准,而是查看已经成为经典或进入行话的概念和嗡嗡声短语(另一种形式的重用!)例如,谷歌用于DRY首字母缩略词,可以很好地讨论在软件和开发过程中可以消除的多种冗余形式。

There's also a role for mature judgment regarding costs of reuse vs. where the benefits are achieved. Some writers advocate waiting to worry about reuse until a second or third use actually emerges, rather than spending effort to generalize bit of code the first time it is written.

对于重用成本与实现收益的成本,还有成熟判断的作用。一些作者主张等待重用,直到第二次或第三次使用实际出现,而不是在第一次编写代码时花费精力来概括代码。

#10


1  

My personal view, based on the practise in my company:

我的个人观点,基于我公司的实践:

  • Do you or your company try and reuse code?
  • 您或您的公司是否尝试重用代码?

Obviously, if we have another piece of code that already fits our needs we will reuse it. We don't go out of our way to use square pegs in round holes though.

显然,如果我们有另一段代码已经满足我们的需求,我们将重用它。我们不会尽力在圆孔中使用方形钉。

  • If so how and at what level, i.e. low level api, components or shared business logic? How do you or your company reuse code?
  • 如果是这样,在什么级别,即低级API,组件或共享业务逻辑?您或您的公司如何重用代码?

At every level. It is written into our coding standards that developers should always assume their code will be reused - even if in reality that is highly unlikely. See below

在每个级别。它写入我们的编码标准,开发人员应该始终假设他们的代码将被重用 - 即使实际上这是非常不可能的。见下文

If your OO model is good, your API probably reflects your business domain, so reusable classes probably equates to reusable business logic without additional effort.

如果您的OO模型很好,您的API可能反映了您的业务领域,因此可重用的类可能等同于可重用的业务逻辑而无需额外的努力。

For actual reuse, one key point is knowing what code is already available. We resolve this by having everything documented in a central location. We just need a little discipline to ensure that the documentation is up-to-date and searchable in a meaningful way.

对于实际重用,一个关键点是知道哪些代码已经可用。我们通过在中心位置记录所有内容来解决这个问题。我们只需要一点点纪律,以确保文档是最新的,并以有意义的方式进行搜索。

  • Does it work?
  • 它有用吗?

Yes, but not because of the potential or actual reuse! In reality, beyond a few core libraries and UI components, there isn't a large amount of reuse.

是的,但不是因为潜在的或实际的重用!实际上,除了一些核心库和UI组件之外,没有大量的重用。

In my personal opinion, the real value is in making the code reusable. In doing so, aside from a hopefully cleaner API, the code will (a) be documented sufficiently for another developer to use it without trawling the source code, and (b) it will also be replaceable. These points are a great benefit to on-going software maintenance.

在我个人看来,真正的价值在于使代码可重用。在这样做的时候,除了希望更干净的API之外,代码将(a)充分记录,以供其他开发人员使用它而无需拖网源代码,(b)它也可以替换。这些要点对正在进行的软件维护非常有益。

#11


0  

While I think code reuse is valuable, I can see where this sentiment is rooted. I've worked on a lot of projects where much extra care was taken to create re-usable code that was then never reused. Of course reuse is much preferable to duplicate code, but I have seen a lot of very extenisve object models created with the goal of using the objects across the enterprise in multiple projects (kind of the way the same service in SOA can be used in different apps) but have never seen the objects actually used more than once. Maybe I just haven't been part of organizations taking good advantage of the principle of reuse.

虽然我认为代码重用很有价值,但我可以看到这种情绪根深蒂固的地方。我已经参与了许多项目,在这些项目中,我们需要特别小心地创建可重用的代码,然后再从不重复使用。当然,重用比重复代码要好得多,但我已经看到了许多非常简单的对象模型,目的是在多个项目中使用整个企业中的对象(这种方式可以在不同的SOA中使用相同的服务)应用程序)但从未见过实际使用过多次的对象。也许我只是没有成为组织的一部分,充分利用了重用原则。

#12


0  

The two software projects I've worked on have both been long term development. One is about 10 years old, the other has been around for over 30 years, rewritten in a couple versions of Fortran along the way. Both make extensive reuse of code, but both rely very little on external tools or code libraries. DRY is a big mantra on the newer project, which is in C++ and lends itself more easily to doing that in practice.

我所研究的两个软件项目都是长期开发的。一个是大约10岁,另一个已经存在超过30年,沿途有几个版本的Fortran重写。两者都广泛地重用代码,但两者都很少依赖外部工具或代码库。 DRY是新项目的一个重要口号,它采用C ++,在实践中更容易实现。

#13


0  

Maybe the better question is when do we NOT reuse code these days? We are either in a state on building using someone elses observed "best practices" or prediscovered "design patterns" or just actually building on legacy code, libraries, or copying.

也许更好的问题是这些天我们什么时候不重用代码?我们要么处于建立状态,要么使用别人观察“最佳实践”或预先发现“设计模式”,要么实际构建遗留代码,库或复制。

It seems the degree to which code A is reused to make code B is often based around how much the ideas in code A taken to code B are abstracted into design patterns/idioms/books/fleeting thoughts/actual code/libraries. The hard part is in applying all those good ideas to your actual code.

似乎代码A被重复用于制作代码B的程度通常基于代码A中对代码B的想法被抽象为设计模式/习语/书籍/转瞬即逝的想法/实际代码/库的程度。困难的部分是将所有这些好主意应用到您的实际代码中。

Non-technical types get overzealous about the reuse thing. They don't understand why everything can't be copy-pasted. They don't understand why the greemelfarm needs a special adapter to communicate the same information that it used to to the old system to the new system, and that, unfortunately we can't change either due to a bazillion other reasons.

非技术类型对重用事物过于热心。他们不明白为什么一切都不能复制粘贴。他们不明白为什么greemelfarm需要一个特殊的适配器来将旧系统所用的相同信息传递给新系统,不幸的是,由于其他原因,我们无法改变。

I think techies have been reusing from day 1 in the same way musicians have been reusing from day 1. Its an ongoing organic evolution and sythesis that will keep ongoing.

我认为技术人员从第1天起就一直在重复使用,就像音乐家从第1天重复使用一样。它是一种持续的有机进化和合成,将继续存在。

#14


0  

Code reuse is an extremely important issue - where code is not reused, projects take longer and are harder for new team members to get into.
However, writing reusable code takes longer.

Personally, I try to write all my code in a reusable way, this takes longer, but it results in the fact that most of my code has become official infrastructures in my organization and that new projects based on these infrastructures take significantly less time.

The danger in reusing code, is if the reused code is not written as an infrastructure - in a general and encapsulated manner with as few as possible assumptions and as much as possible documentation and unit testing, that the code can end up doing unexpected things.
Also, if bugs are found and fixed, or features added, these changes are rarely returned to the source code, resulting in different versions of the reused code, that no one knows of or understands.

The solution is:
1. To design and write the code with not only one project in mind, but to think of future requirements and try to make the design flexible enough to cover them with minimal code change.
2. To enclose the code within libraries that are to be used as-is and not modified within using projects.
3. To allow users to view and modify the code of of the library withing its solution (not within the using project's solution).
4. To design future projects to be based on the existing infrastructures, making changes to the infrastructures as necessary.
5. To charge maintaining the infrastructure to all projects, thus keeping the infrastructure funded.

代码重用是一个非常重要的问题 - 代码不会被重用,项目需要更长时间并且新团队成员难以进入。但是,编写可重用代码需要更长时间。就个人而言,我尝试以可重用的方式编写所有代码,这需要更长时间,但这导致我的大部分代码已成为组织中的官方基础结构,并且基于这些基础结构的新项目所花费的时间要少得多。重用代码的危险在于,如果重用的代码不是作为基础结构编写的 - 以尽可能少的假设和尽可能多的文档和单元测试的通用和封装方式,代码最终会做出意想不到的事情。此外,如果发现并修复了错误或添加了功能,这些更改很少返回到源代码,导致重用代码的不同版本,没有人知道或理解。解决方案是:1。设计和编写代码时不仅要考虑一个项目,还要考虑未来的需求,并尝试使设计足够灵活,以最少的代码更改来覆盖它们。 2.将代码括在要按原样使用但未在使用项目中修改的库中。 3.允许用户使用其解决方案查看和修改库的代码(不在使用项目的解决方案中)。 4.设计基于现有基础设施的未来项目,根据需要对基础设施进行更改。 5.负责维护所有项目的基础设施,从而保持基础设施的资金。

#15


0  

Do you or your company try and reuse code? If so how and at what level, i.e. low level api, components or shared business logic? How do you or your company reuse code?

您或您的公司是否尝试重用代码?如果是这样,在什么级别,即低级API,组件或共享业务逻辑?您或您的公司如何重用代码?

I used to work in a codebase with uber code reuse, but it was difficult to maintain because the reused code was unstable. It was prone to design changes and deprecation in ways that cascaded to everything using it. Before that I worked in a codebase with no code reuse where the seniors actually encouraged copying and pasting as a way to reuse even application-specific code, so I got to see the two extremities and I have to say that one isn't necessarily much better than the other when taken to the extremes.

我曾经在代码库中使用超级代码重用,但由于重用的代码不稳定,因此难以维护。它倾向于设计更改和弃用的方式级联到使用它的一切。在此之前,我在代码库中工作,没有代码重用,老年人实际上鼓励复制和粘贴作为一种方法来重用甚至特定于应用程序的代码,所以我看到了两个极端,我不得不说一个不一定多在走向极端时比其他更好。

And I used to be an uber bottom-up kind of programmer. You ask me to build something specific and I end up building generalized tools. Then using those tools, I build more complex generalized tools, then start building DIP abstractions to express the design requirements for the lower-level tools, then I build even more complex tools and repeat, and at some point I start writing code that actually does what you want me to do. And as counter-productive as that sounded, I was pretty fast at it and could ship complex products in ways that really surprised people.

我曾经是一个自上而下的程序员。你让我建立一些特定的东西,我最终建立了通用工具。然后使用这些工具,我构建了更复杂的通用工具,然后开始构建DIP抽象来表达低级工具的设计要求,然后我构建更复杂的工具并重复,并且在某些时候我开始编写实际执行的代码你要我做什么。虽然听起来适得其反,但我的速度非常快,可能会以令人惊讶的方式运送复杂的产品。

Problem was the maintenance over the months, years! After I built layers and layers of these generalized libraries and reused the hell out of them, each one wanted to serve a much greater purpose than what you asked me to do. Each layer wanted to solve the world's hunger needs. So each one was very ambitious: a math library that wants to be amazing and solve the world's hunger needs. Then something built on top of the math library like a geometry library that wants to be amazing and solve the world's hunger needs. You know something's wrong when you're trying to ship a product but your mind is mulling over how well your uber-generalized geometry library works for rendering and modeling when you're supposed to be working on animation because the animation code you're working on needs a few new geometry functions.

问题是几个月,几年的维护!在我构建了这些通用库的层和层并重新使用它们之后,每个人都希望提供比你要求我做的更大的目的。每一层都想解决世界的饥饿需求。所以每个人都非常雄心勃勃:数学图书馆想要惊人并解决世界的饥饿需求。然后建立在数学库之上的东西就像几何图书馆一样,想要惊人并解决世界的饥饿需求。当你试图发布一个产品时,你知道出了什么问题,但是当你应该处理动画时,你的头脑正在考虑你的超级通用几何库如何用于渲染和建模,因为你正在使用动画代码on需要一些新的几何函数。

Balancing Everyone's Needs

平衡每个人的需求

I found in designing these uber-generalized libraries that I had to become obsessed with the needs of every single team member, and I had to learn how raytracing worked, how fluids dynamics worked, how the mesh engine worked, how inverse kinematics worked, how character animation worked, etc. etc. etc. I had to learn how to do pretty much everyone's job on the team because I was balancing all of their specific needs in the design of these uber generalized libraries I left behind while walking a tightrope balancing act of design compromises from all the code reuse (trying to make things better for Bob working on raytracing who is using one of the libraries but without hurting John too much who is working on physics who is also using it but without complicating the design of the library too much to make them both happy).

我发现在设计这些超级通用库时,我必须痴迷于每个团队成员的需求,我必须学习光线跟踪如何工作,流体动力学如何工作,网格引擎如何工作,反向运动学如何工作,如何我不得不学习如何在团队中完成每个人的工作,因为我在设计这些超级广义图书馆的同时平衡了他们在走钢丝平衡行为时留下的所有特定需求所有代码重用的设计妥协(试图让Bob更好地处理使用其中一个库的光线追踪,但不会伤害John过多的正在使用物理的人也在使用它,但没有使图书馆的设计复杂化太多让他们都开心了。

It got to a point where I was trying to parametrize bounding boxes with policy classes so that they could be stored either as center and half-size as one person wanted or min/max extents as someone else wanted, and the implementation was getting convoluted really fast trying to frantically keep up with everyone's needs.

它达到了我试图用策略类对参数化框进行参数化的程度,以便它们可以像一个人想要的那样存储为中心和半尺寸,或者像其他人想要的那样存储最小/最大范围,并且实现真的很复杂。快速尝试疯狂地跟上每个人的需求。

Design By Committee

委员会设计

And because each layer was trying to serve such a wide range of needs (much wider than we actually needed), they found many reasons to require design changes, sometimes by committee-requested designs (which are usually kind of gross). And then those design changes would cascade upwards and affect all the higher-level code using it, and maintenance of such code started to become a real PITA.

而且因为每一层都试图满足如此广泛的需求(比我们实际需要的要宽得多),他们发现需要改变设计的原因有很多,有时是委员会要求的设计(通常是粗略的)。然后,这些设计更改将向上级联并影响使用它的所有更高级别的代码,并且此类代码的维护开始成为真正的PITA。

I think you can potentially share more code in a like-minded team. Ours wasn't like-minded at all. These are not real names but I'd have Bill here who is a high-level GUI programmer and scripter who creates nice user-end designs but questionable code with lots of hacks, but it tends to be okay for that type of code. I got Bob here who is an old timer who has been programming since the punch card era who likes to write 10,000 line functions with gotos in them and still doesn't get the point of object-oriented programming. I got Joe here who is like a mathematical wizard but writes code no one else can understand and always make suggestions which are mathematically aligned but not necessarily so efficient from a computational standpoint. Then I got Mike here who is in outer space who wants us to port the software to iPhones and thinks we should all follow Apple's conventions and engineering standards.

我认为你可以在一个志同道合的团队中共享更多代码。我们根本没有像志同道合的那样。这些都不是真正的名字,但我在这里有Bill,他是一个高级GUI程序员和脚本编写者,他创建了很好的用户端设计,但是有很多黑客可疑的代码,但是对于那种类型的代码来说它往往是可以接受的。我让鲍勃在这里是一个老计时器,自从打卡时代以来一直在编程,他喜欢用里程碑编写10,000行函数,但仍然没有得到面向对象编程的观点。我在这里得到了乔,他就像一个数学向导但编写了其他人无法理解的代码,总是提出数学对齐的建议,但从计算的角度来看并不一定非常有效。然后我让Mike在这里,他们希望我们将软件移植到iPhone,并认为我们都应该遵循Apple的惯例和工程标准。

Trying to satisfy everyone's needs here while coming up with a decent design was, probably in retrospect, impossible. And in everyone trying to share each other's code, I think we became counter-productive. Each person was competent in an area but trying to come up with designs and standards which everyone is happy with just lead to all kinds of instability and slowed everyone down.

试图满足每个人的需求,同时提出一个体面的设计,可能是回想起来,不可能。在每个试图分享彼此代码的人中,我认为我们变得适得其反。每个人都有能力在一个地区,但试图提出每个人都满意的设计和标准,只会导致各种不稳定,并减慢每个人的速度。

Trade-Offs

So these days I've found the balance is to avoid code reuse for the lowest-level things. I use a top-down approach from the mid-level, perhaps (something not too far divorced from what you asked me to do), and build some independent library there which I can still do in a short amount of time, but the library doesn't intend to produce mini-libs that try to solve the world's hunger needs. Usually such libraries are a little more narrow in purpose than the lower-level ones (ex: a physics library as opposed to a generalized geometry-intersection library).

所以这些天我发现平衡是为了避免代码重用最低级别的东西。我可能会使用自上半场的自上而下的方法(与你要求我做的事情不太分离),并在那里建立一些我可以在短时间内完成的独立库,但是图书馆不打算生产试图解决世界饥饿需求的小型库。通常这些库的目的比较低级的库要窄一些(例如:物理库而不是广义几何交叉库)。

YMMV, but if there's anything I've learned over the years in the hardest ways possible, it's that there might be a balancing act and a point where we might want to deliberately avoid code reuse in a team setting at some granular level, abandoning some generality for the lowest-level code in favor of decoupling, having malleable code we can better shape to serve more specific rather than generalized needs, and so forth -- maybe even just letting everyone have a little more freedom to do things their own way. But of course all of this is with the aim of still producing a very reusable, generalized library, but the difference is that the library might not decompose into the teeniest generalized libraries, because I found that crossing a certain threshold and trying to make too many teeny, generalized libraries starts to actually become an extremely counter-productive endeavor in the long term -- not in the short term, but in the long run and broad scheme of things.

YMMV,但如果我多年来以最困难的方式学到了什么,那就是可能存在一种平衡行为,并且我们可能想要在一个细粒度级别的团队设置中故意避免代码重用,放弃一些最低级代码的一般性有利于解耦,具有可塑性代码我们可以更好地塑造以提供更具体而非一般化的需求,等等 - 甚至可以让每个人都有更多自由以自己的方式做事。但当然所有这一切都是为了仍然生成一个非常可重用的通用库,但不同之处在于库可能不会分解成最青睐的通用库,因为我发现超过某个阈值并试图制造太多从长远来看,从长远来看,广义的图书馆开始真正成为一种极其适得其反的努力。

If you have a piece of code which could potentially be shared across a medium size organization how would you go about informing other members of the company that this lib/api/etc existed and could be of benefit?

如果您有一段可能在中型组织中共享的代码,您将如何通知该公司的其他成员这个lib / api / etc是否存在并且可能有益?

I actually am more reluctant these days and find it more forgivable if colleagues do some redundant work because I would want to make sure that code does something fairly useful and non-trivial and is also really well-tested and designed before I try to share it with people and accumulate a bunch of dependencies to it. The design should have very, very few reasons to require any changes from that point onwards if I share it with the rest of the team.

这些天我实际上更不情愿,并且如果同事做了一些多余的工作,发现它更可原谅,因为我想确保代码做一些非常有用且非平凡的事情,并且在我尝试分享它之前也经过了充分的测试和设计与人共同积累一堆依赖。如果我与团队的其他成员分享,那么设计应该有很少的理由要求从那时起进行任何更改。

Otherwise it could cause more grief than it actually saves.

否则它可能比实际节省更多的悲伤。

I used to be so intolerant of redundancy (in code or efforts) because it appeared to translate to a product that was very buggy and explosive in memory use. But I zoomed in too much on redundancy as the key problem, when really the real problem was poor quality, hastily-written code, and a lack of solid testing. Well-tested, reliable, efficient code wouldn't suffer that problem to nearly as great of a degree even if some people duplicate, say, some math functions here and there.

我曾经如此容忍冗余(在代码或努力中),因为它似乎转化为在内存使用中非常错误和爆炸性的产品。但是我把冗余放大了太多关键问题,真正的问题是真正的问题是质量差,编写匆忙的代码,缺乏可靠的测试。经过充分测试,可靠,高效的代码不会遇到这个问题,即使有些人在某些地方复制了一些数学函数,也几乎没有这个问题。

One of the common sense things to look at and remember that I didn't at the time is how we don't mind some redundancy when we use a very solid third party library. Chances are that you guys use a third party library or two that has some redundant work with what your team is doing. But we don't mind in those cases because the third party library is great and well-tested. I recommend applying that same mindset to your own internal code. The goal should be to create something awesome and well-tested, not to fuss over a little bit of redundancy here and there as I mistakenly did long ago.

在我们使用非常可靠的第三方库时,要注意并记住我当时没有的常识性事项之一就是我们不介意一些冗余。您可能会使用第二方或第二方库,这些第三方库与您的团队正在进行的工作有一些冗余的工作。但是我们并不介意那些情况,因为第三方图书馆很棒且经过充分测试。我建议将相同的思维方式应用于您自己的内部代码。我们的目标应该是创造一些令人敬畏和经过充分测试的东西,而不是因为我在很久以前错误地做过这里和那里的一点点冗余。

So these days I've shifted my intolerance towards a lack of testing instead. Instead of getting upset over redundant efforts, I find it much more productive to get upset over other people's lack of unit and integration testing! :-D

所以这些天我把我的不宽容转向缺乏测试。我发现,对于其他人缺乏单元和集成测试感到不安,我发现它不会因冗余工作而感到沮丧! :-D

#16


-1  

Maven has solved code reuse. I'm completely serious.

Maven解决了代码重用问题。我完全认真。


推荐阅读
  • 本文介绍了如何使用PHP向系统日历中添加事件的方法,通过使用PHP技术可以实现自动添加事件的功能,从而实现全局通知系统和迅速记录工具的自动化。同时还提到了系统exchange自带的日历具有同步感的特点,以及使用web技术实现自动添加事件的优势。 ... [详细]
  • Nginx使用AWStats日志分析的步骤及注意事项
    本文介绍了在Centos7操作系统上使用Nginx和AWStats进行日志分析的步骤和注意事项。通过AWStats可以统计网站的访问量、IP地址、操作系统、浏览器等信息,并提供精确到每月、每日、每小时的数据。在部署AWStats之前需要确认服务器上已经安装了Perl环境,并进行DNS解析。 ... [详细]
  • 本文介绍了闭包的定义和运转机制,重点解释了闭包如何能够接触外部函数的作用域中的变量。通过词法作用域的查找规则,闭包可以访问外部函数的作用域。同时还提到了闭包的作用和影响。 ... [详细]
  • Iamtryingtomakeaclassthatwillreadatextfileofnamesintoanarray,thenreturnthatarra ... [详细]
  • Linux重启网络命令实例及关机和重启示例教程
    本文介绍了Linux系统中重启网络命令的实例,以及使用不同方式关机和重启系统的示例教程。包括使用图形界面和控制台访问系统的方法,以及使用shutdown命令进行系统关机和重启的句法和用法。 ... [详细]
  • 本文介绍了C#中生成随机数的三种方法,并分析了其中存在的问题。首先介绍了使用Random类生成随机数的默认方法,但在高并发情况下可能会出现重复的情况。接着通过循环生成了一系列随机数,进一步突显了这个问题。文章指出,随机数生成在任何编程语言中都是必备的功能,但Random类生成的随机数并不可靠。最后,提出了需要寻找其他可靠的随机数生成方法的建议。 ... [详细]
  • 本文介绍了UVALive6575题目Odd and Even Zeroes的解法,使用了数位dp和找规律的方法。阶乘的定义和性质被介绍,并给出了一些例子。其中,部分阶乘的尾零个数为奇数,部分为偶数。 ... [详细]
  • CF:3D City Model(小思维)问题解析和代码实现
    本文通过解析CF:3D City Model问题,介绍了问题的背景和要求,并给出了相应的代码实现。该问题涉及到在一个矩形的网格上建造城市的情景,每个网格单元可以作为建筑的基础,建筑由多个立方体叠加而成。文章详细讲解了问题的解决思路,并给出了相应的代码实现供读者参考。 ... [详细]
  • Commit1ced2a7433ea8937a1b260ea65d708f32ca7c95eintroduceda+Clonetraitboundtom ... [详细]
  • 本文介绍了Redis的基础数据结构string的应用场景,并以面试的形式进行问答讲解,帮助读者更好地理解和应用Redis。同时,描述了一位面试者的心理状态和面试官的行为。 ... [详细]
  • Java容器中的compareto方法排序原理解析
    本文从源码解析Java容器中的compareto方法的排序原理,讲解了在使用数组存储数据时的限制以及存储效率的问题。同时提到了Redis的五大数据结构和list、set等知识点,回忆了作者大学时代的Java学习经历。文章以作者做的思维导图作为目录,展示了整个讲解过程。 ... [详细]
  • XML介绍与使用的概述及标签规则
    本文介绍了XML的基本概念和用途,包括XML的可扩展性和标签的自定义特性。同时还详细解释了XML标签的规则,包括标签的尖括号和合法标识符的组成,标签必须成对出现的原则以及特殊标签的使用方法。通过本文的阅读,读者可以对XML的基本知识有一个全面的了解。 ... [详细]
  • 展开全部下面的代码是创建一个立方体Thisexamplescreatesanddisplaysasimplebox.#Thefirstlineloadstheinit_disp ... [详细]
  • 不同优化算法的比较分析及实验验证
    本文介绍了神经网络优化中常用的优化方法,包括学习率调整和梯度估计修正,并通过实验验证了不同优化算法的效果。实验结果表明,Adam算法在综合考虑学习率调整和梯度估计修正方面表现较好。该研究对于优化神经网络的训练过程具有指导意义。 ... [详细]
  • 本文详细介绍了Spring的JdbcTemplate的使用方法,包括执行存储过程、存储函数的call()方法,执行任何SQL语句的execute()方法,单个更新和批量更新的update()和batchUpdate()方法,以及单查和列表查询的query()和queryForXXX()方法。提供了经过测试的API供使用。 ... [详细]
author-avatar
发的好地方
这个家伙很懒,什么也没留下!
Tags | 热门标签
RankList | 热门文章
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有