admin管理员组

文章数量:1579409

There was a great comment on a recent post here last week where I was trying to get a Managed Plugin working with an application that insisted on its plugins being C++ DLLs with specific virtual methods implemented.

上周在这里最近的一篇文章中有一个很好的评论,我试图使一个托管插件与一个应用程序一起工作,该应用程序坚持其插件是C + + DLLs,并且实现了具体的虚拟方法。

Here's the comment with my emphasis

这是我的重点评论:

Great article. It would be nice to see a little less "managed snobism". Personally, I don't need to use up 100MB of my memory with a framework just to let me generate 32x32 bitmaps. So I'm grateful that the managed route is not the default. Remember, 90% of functions in .NET are just wrappers around the underlying API functions, so in effect, all they do is slow you down, while giving you convenience.

很棒的文章。 看到一些“管理的势利主义”会更好。 就个人而言,我不需要用一个框架来占用100MB的内存,只需让我生成32x32位图即可。 因此,我对托管路由不是默认路由表示感谢。 请记住,.NET中90%的功能只是底层API函数的包装,因此,实际上,它们所做的所有事情都会降低速度,同时给您带来便利。

This reminded me of an article I did a few years ago when folks were still asking silly questions like "Is your application Pure .NET?" The article was called The Myth of .NET Purity and was published up on MSDN under an article series called ".NET in the Real World." To this day I'm still surprised that they let me publish it.

这让我想起了我几年前写的一篇文章,当时人们仍在问诸如“您的应用程序是纯.NET吗? ”之类的愚蠢问题。该文章被称为.NET Purity的神话,并发表在MSDN上,名为“。 “现实世界中的.NET。” 直到今天,我仍然感到惊讶,他们让我出版了它。

The (interestingly anonymous) commenter says: "...so in effect, all they do is slow you down, while giving you convenience." Well, sure. Everyone knows this quote:

(有趣的匿名)评论者说:“ ...实际上,他们所做的只是使您放慢速度,同时给您带来方便。 ” 每个人都知道这句话:

Any problem in Computer Science can be solved with another layer of indirection.

计算机科学中的任何问题都可以通过另一层间接解决。

It's a great quote. As an aside, the quote is attributed to nearly every smart Computer Scientist. Including David Wheeler, Butler Lampson and Steven M. Bellovin. Lampson says it was Wheeler, but it was one of these three guys.

这是一个很好的报价。 顺便说一句,报价几乎归功于每位精明的计算机科学家。 包括David Wheeler,Butler Lampson和Steven M. Bellovin。 兰普森说那是惠勒,但那是这三个家伙之一。

But a game developer at Sun adds a clever touché to the old adage:

但是,Sun的游戏开发人员为这句老话添加了巧妙的修饰:

The two software problems that can never be solved by adding another layer of indirection are that of providing adequate performance or minimal resource usage. - Jeff Kesselman

不能通过添加另一层间接解决的两个软件问题是提供足够的性能或最少的资源使用。 -杰夫·凯塞尔曼

And he's right. Of course, .NET is a (most excellent layer of) Managed Spackle over the Win32 API. But it's really GOOD spackle. It's so good that we get collectively frustrated when a new API (SideShow, AzMan) doesn't have a good initial managed API (SideShow does now). A nice, clean managed API adds a fantastic amount of convenience in exchange for a very reasonable performance hit.

而且他是对的。 当然,.NET是Win32 API上的(最出色的) Managed Spackle 。 但这确实是好消息。 太好了,以至于当新的API(SideShow,AzMan)没有好的初始托管API(现在的SideShow)时,我们都会感到沮丧。 好的,干净的托管API为实现非常合理的性能提升提供了极大的便利。

The performance hit - which I haven't personally measured - is no doubt less than even the most trivial of network calls. How much overhead is added? Not much.

我个人并没有对性能造成的影响,甚至比最琐碎的网络呼叫都要少。 增加了多少开销? 不多。

Approximate overhead for a platform invoke call: 10 machine instructions (on an x86 processor)

平台调用的大概开销: 10条机器指令(在x86处理器上)

Approximate overhead for a COM interop call: 50 machine instructions (on an x86 processor)

COM互操作调用的大约开销: 50条机器指令(在x86处理器上)

Gosh, that isn't much. Sure, there are always scenarios we conceive of that could add up, but that's what profiling on a case-by-case basis is for.

天哪,那不多。 当然,我们总会想到一些可能会加在一起的场景,但这就是根据情况进行概要分析的目的。

If .NET Purity is a myth, and the whole thing is just there to make our lives easier, then this is an easy trade off. I just remember that I can code in C#/VB.NET, for a small cost. I get speed of dev, and I give up speed of execution. I can code in C++, and give up speed of dev (a smidge) and gain (possibly) speed of execution. I can code in ASM and give up lots of productivity in exchange for my immortal soul and a really fast program. Or I can go to heaven, pursue beauty if I like, and give up so much performance to cause a scandal.

如果.NET Purity是一个神话,而整件事只是为了使我们的生活更轻松,那么这是一个容易的权衡。 我只是记得我可以用C#/ VB.NET编写代码,而花费很少。 我得到了开发人员的速度,却放弃了执行速度。 我可以用C ++编写代码,并放弃dev(麻烦)的速度,而(可能)获得执行速度。 我可以用ASM编写代码并放弃很多工作效率,以换取我不朽的灵魂和一个非常快速的程序。 或者我可以去天堂,如果我愿意的话追求美,放弃那么多的表现以引起丑闻。

But it's not a simple trade off. Certainly not at the method or even component level. William Caputo makes a similar point with emphasis mine:

但这不是一个简单的权衡。 当然不在方法或组件级别。 威廉·卡普托(William Caputo)也强调了我的观点:

...this calculation is done unconsciously by those programmers who hear "we're trading efficiency for productivity." It's why they are reluctant to take a serious look at higher-level languages. A one-time productivity hit to get faster run-time performance certainly seems like a good trade-off, but the flaw in the argument is that productivity measurement is not reset with each task. It's cumulative. Unlike a programming assignment ("Implement Quick Sort Please"), productivity is measured across an entire solution (whether a build script or a trading system) -- and not just the first writing of the code, but throughout its useful lifetime (the vast majority of coding time is spent changing, or maintaining existing code).

……听到“我们正在以效率换取生产力”的程序员不知不觉地完成了这一计算。 这就是为什么他们不愿认真看待高级语言的原因。 一次性提高生产率以获得更快的运行时性能显然是一个不错的权衡,但是该论点的缺点是生产率度量标准不会随每个任务而重置。 它是累积的。 与编程任务(“请快速实施排序”)不同,生产率是在整个解决方案(无论是构建脚本还是交易系统)中进行衡量的-不仅是第一次编写代码,而且还要贯穿整个有用的生命周期(大部分编码时间都花费在更改或维护现有代码上)。

In the real world, its not "write once, run forever", its "write a bit, run a bit, change a bit, run a bit", and so on. I am not saying that run-time efficiency isn't important. It is. The best way to compare run-time efficiency and programmer productivity is not at the micro level, but at the macro level.

在现实世界中,它不是“写一次,永远运行”,而是“写一点,运行一点,改变一点,运行一点”,依此类推。 我并不是说运行时效率并不重要。 它是。 比较运行时效率和程序员生产率的最好方法不是在微观层面,而是在宏观层面。

Yes, .NET adds overhead. Certainly not enough to worry about for business apps, given the productivity gains. We're not writing device drivers here. In my original example where I want to write managed plugins for the Optimus Keyboard, since the max frames per second on the keyboard is 3fps, performance isn't a concern (nor would it be even if I needed 30fps).

是的,.NET增加了开销。 考虑到生产率的提高,对于企业应用程序而言,当然还不足以担心。 我们不在这里编写设备驱动程序。 在我想为Optimus Keyboard编写托管插件的原始示例中,由于键盘上的最大每秒帧数为3fps,因此性能不是问题(即使我需要30fps也是如此)。

If being a Managed Code Snob is wrong, I don't wanna be right.

如果成为Managed Code Snob是错误的,那我就不对了。

翻译自: https://www.hanselman/blog/managed-snobism

本文标签: 势利主义