是否有充分的理由来标记一个班级公众?

Paul Stovell was watching a talk I gave with Keith Pleas at Teched US 2006 on building your own Enterprise Framework. The basic jist was that architecting/designing/building a framework for other developers is a different task than coding for end users.  

Paul Stovell正在观看我与Keith Pleas在Teched US 2006上进行的有关构建自己的企业框架的讨论。 基本的原理是,为其他开发人员设计/设计/构建框架与为最终用户编码是不同的任务。

One thing that is valuable for context is that Keith and I were playing roles in this presentation. Keith was playing Einstein in his Ivory Tower, the developer who wants perfect purity and follows all the rules. I was playing Mort the realist, the developer who just wants to get the job done. We went back and forth with white slides for Keith, Black for me, each of us declaring the extreme view, then coming together on the final slide with some pragmatic and prescriptive guidance.

对于上下文而言有价值的一件事是,我和Keith在此演示文稿中扮演角色。 基思(Keith)在他的象牙塔(Ivory Tower)中扮演爱因斯坦(Einstein),该开发商想要完美的纯正并遵守所有规则。 我在扮演Mort的现实主义者,他只是想完成工作。 我们给基思带了白色幻灯片,给我带了黑色幻灯片,对我来说都是黑色,我们每个人都宣布了极致的观点,然后在最后的幻灯片上结合了一些务实和说明性的指导。

Paul had an issue with the slide on Extensibility where I, as the hyper-realist, said:

保罗在“可扩展性”幻灯片上遇到了一个问题,我作为超现实主义者说:

  • If they extend it, they will break it

    如果扩展它,它们将破坏它
  • Use Internal more

    使用内部更多
  • Seal first, ask questions later

    先盖章,再问问题

He said:

他说:

Frankly, I think this is crap.
[Paul Stovell

坦白说,我认为这很糟糕。 [保罗·斯托维尔]

For goodness' sake, Paul, don't sugarcoat it, tell me how you really feel! ;) Just kidding. He has some interesting observations and (some) valid points.

保佑,保罗,不要撒糖,告诉我你的真实感受! ;) 开玩笑。 他有一些有趣的发现和(一些)有效的观点。

If you are developing a framework or API for someone else to use, and you think you know more about how they plan to use your API than they do, you've got balls. [Paul]

如果您正在开发供其他人使用的框架或API,并且您认为自己比他们更了解他们计划如何使用API​​,那么您将获得很多帮助。 [保罗]

I mostly agree with this. However, you certainly need to have SOME idea of what they are using it for as you're on the hook to support it in every funky way they might used it. It is reasonable to have some general parameters for how your API should be used. If you design it poorly, it will likely get used in ways that may end up giving the developer a bad experience or even breaking the app.

我大部分都同意这一点。 但是,您肯定需要对他们使用它的目的有所了解,因为您将以各种可能使用它的时髦方式来支持它。 对于如何使用API​​具有一些常规参数是合理的。 如果设计不当,很可能会以某种方式使用它,最终给开发人员带来糟糕的体验,甚至破坏应用程序。

For example, in a logging service we had a method called ConfigureAndWatch that mirrored the log4net ConfigureAndWatch. It's meant to be called once per AppDomain, and never again. Because it was not only poorly named (since we too the internal implementation's name) and it didn't offer any suggestions (via exceptions, return values, or logging of its own) some users would call it on every page view within ASP.NET, causing a serious performance problem. There's a number of ways this problem could be solved, but the point is that there needs to be a boundary for the context in which an API is used. If we had constrained this more - and by doing that, we think we know more than they do - then some problems would have been avoided.

例如,在日志记录服务中,我们有一个名为ConfigureAndWatch的方法,该方法镜像了log4net ConfigureAndWatch。 它的意思是每个AppDomain调用一次,再也不会调用。 因为它不仅命名不当(因为我们也是内部实现的名称),并且没有提供任何建议(通过异常,返回值或自己的日志记录),所以某些用户会在ASP.NET中的每个页面视图上调用它,从而导致严重的性能问题。 有多种方法可以解决此问题,但要点是,使用API​​的上下文必须有一个边界。 如果我们对此进行更多的限制-并且这样做,我们认为我们比他们知道的更多-那么可以避免一些问题。

Scott goes on to give an example whereby he actually made every class "internal" in his API, and waited for users to tell him what classes they wanted to extend, and extended them one by one. [Paul]

Scott继续举一个例子,他实际上在他的API中将每个类都设置为“内部”,并等待用户告诉他他们想扩展哪些类,然后逐一扩展它们。 [保罗]

This little bit of inspired brilliance was not my idea, but rather Brian Windheim's, an architect at Corillian. We had an application that consisted largely of base classes and developers were insisting that they needed infinite flexibility. We heard "infinite" from the developers, but not the business owner. Brian theorized that they didn't need as much extensibility as they thought, and shipped a internally basically sealed version. When folks needed something marked virtual, they put it in a queue. The next internal version shipped with something like 7 methods in one class marked virtual - meeting the needs of all - when originally the developers thought they wanted over 50 points of extensibility.

一点点灵感的灿烂不是我的主意,而是Corillian的建筑师Brian Windheim's。 我们的应用程序主要由基类组成,并且开发人员坚持认为它们需要无限的灵活性。 我们听到了开发商的“无限”声音,但企业主却没有。 Brian理论上认为他们并不需要他们想像的那么多可扩展性,并发布了内部基本密封的版本。 当人们需要标记为虚拟的东西时,他们将其排队。 下一个内部版本在一个类中提供了类似于7种方法的标记为虚拟的-满足了所有人的需求-最初,开发人员认为他们想要超过50点的可扩展性。

The point of Brian's exercise was to find a balance between extensibility, both explicit and implicit, and supportability.

Brian的工作重点是在显性和隐性的可扩展性与可支持性之间找到平衡。

When you mark something virtual or make a class public, as a developer framework designer explicitly expressing support for the use of that API. If you choose to mark everything virtual and everything public as Paul advocates, be aware of not only the message you send to the downstream developer, but also the unspeakably large combinatorics involved when that developer starts using the API in an expected way.

当您将某些内容标记为虚拟或将类公开时,作为 开发人员 框架设计人员应明确表示支持使用该API。 如果您按照Paul的主张选择标记所有虚拟内容和公共内容,则不仅要注意发送给下游开发人员的消息,而且还要注意当开发人员以预期方式开始使用API​​时涉及的庞大组合。

Cyclomatic complexity can give you a number that expresses the complexity of a method and offer valuable warnings when something is more complex than the human mind can comfortably hold. There are other tools (like NDepend and Afferent Coupling, Lattix and it's Dependency Structure Matrices and Libcheck and its measure of the churn of the public surface area of a framework) that can help you express the ramifications of your design decisions in fairly hard metrics and good reporting.

圈复杂性可以为您提供一个数字,该数字表示方法的复杂性,并且在某些事情比人的脑力所能承受的复杂时,会提供有价值的警告。 还有其他工具(例如NDepend和传入耦合, Lattix及其依赖关系矩阵和Libcheck及其对框架公共表面积的流失度量)可以帮助您以相当困难的度量标准来表达设计决策的后果。良好的报告。

If you mark all your classes and methods public,  be informed of these metrics (and others) and the computer science behind them and acknowledge that you're saying they aren't right for you. Just be aware and educated of the potential consequences, be those consequences bad or good.

如果您将所有类和方法都标记为公开,则应将这些度量标准(以及其他度量标准)以及背后的计算机科学知会,并承认您说的是它们不适合您。 只要意识到潜在的后果并受其教育,无论这些后果是好是坏。

Can you honestly rely on people who are "just playing" with a technology to tell you which bits they will need to be extensible 12 months into the future?

您能诚实地依靠那些正在“玩弄”一项技术的人来告诉您,他们需要在未来12个月内扩展哪些位吗?

You totally can't. When you're designing for Users, you do a usability study. When you're designing for Developers, you need do a a developability study.

你完全不能。 在为用户设计时,您需要进行可用性研究。 在为开发人员设计时,需要进行可开发性研究

Microsoft actually does more of this than most folks think. Sure there's the Alphas, Betas and CTPs, but there's also TAP (Technology Adoption Programs) programs, Deep Dives where folks go to labs at Microsoft and work on new technology and frameworks for a week while folks take notes. These programs aren't for RDs or MVPs, they're for developer houses. If you're interesting, ask your local Microsoft rep (whoever organizes your local Nerd Dinners perhaps) how you can get into an Early Adopter Program for whatever technology you're hoping to influence. They really DO listen. We just came back from a Deep Dive into PowerShell and got not only access to the team but a chance to tell them how we use the product and the direction we'd like to see it go.

微软实际上比大多数人认为的要多。 当然,这里有Alpha,Beta和CTP,但也有TAP(技术采用计划)计划,即Deep Divs ,人们可以在Microsoft的实验室进行研究,并在一周之内研究新技术和框架,而人们则做笔记。 这些程序不是针对RD或MVP的,而是针对开发人员的。 如果您有兴趣,请咨询您当地的Microsoft代表(可能由谁组织您的本地书呆子晚宴),以何种方式进入“早期采用者计划”,以获取希望影响的任何技术。 他们确实听。 我们刚从Dive深入到PowerShell中,不仅可以访问团队,而且还可以有机会告诉他们我们如何使用该产品以及我们希望其发展的方向。

Scotts [sic] philosophy, and that of many people at Microsoft (and many component vendors - Infragistics being another great example), seems to be to mark everything as internal unless someone gives them a reason to make it public.

Scotts(sic)的哲学以及Microsoft许多人(以及许多组件供应商-Infragistics是另一个很好的例子)的哲学似乎是将一切都标记为内部的,除非有人给出理由将其公开。

That's not my philosophy, and I didn't say it was in the presentation. It was part of the schtick. The slides looked like this with Keith as Ivory Tower Guy first, then Me as Realist guy, and the "in actuality" slide last with guidance we could all agree on. However, I still think that marking stuff internal while you're in your design phase is a great gimmick to better understand your user and help balance good design with the important business issue of a supportable code base.

那不是我的哲学,我没有说是在演讲中。 这是schtick的一部分。 幻灯片看起来像这样,首先是基思(Keith)是象牙塔哥(Ivory Tower Guy),然后是我(Meist),是现实主义者(Realist),最后是“实际上”幻灯片,我们都同意了指导。 但是,我仍然认为,在您处于设计阶段时,将内容标记在内部是一个很好的头,可以更好地了解您的用户,并帮助平衡良好的设计与可支持代码库的重要业务问题。

The salient point in the whole talk is be aware of the consequences of extremes and make the decision that's right for you and your company. (Very ComputerZen, eh?)

整个谈话的重点是要意识到极端情况的后果,并做出适合您和您的公司的决定。 ( Very ComputerZen,是吗? )

  

Paul's right that it is frustrating to see internal classes that do just what you want, but simply marking them public en masse isn't the answer, nor is marking everything internal.

保罗是对的,看到内部类可以满足您的要求是令人沮丧的,但是简单地将它们整体标记为公共对象并不能解决问题,也不能将所有内部对象都标记出来。

翻译自: https://www.hanselman.com/blog/is-there-a-good-reason-to-mark-a-class-public

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值