Go homepage(回首页)
Upload pictures (上传图片)
Write articles (发文字帖)

The author:(作者)
published in(发表于) 2013/11/12 12:32:07
If both programs are doing what?

If both programs are doing what?
-Programmers, computer programming-IT news If both programs are doing what?

The writer introduction


Raymond Chen


Raymond Chen is a well-known Microsoft Windows Shell development team programmers, starting from 1992 joined Microsoft, he participated in OS/2,Windows 95,DirectX has the development of future versions of Windows. His development on Windows, and Win32 programming blog, "The Old New Thing" is one of the most famous blog on the Microsoft MSDN. Author of a book of the same name of the The Old New Thing, Chinese name for the Windows programming book of revelation. Raymond also writes a column for Microsoft TechNet articles.



In his mind, "If", this approach can help you understand whether Windows will allow you to do one thing or another. If such a scenario would clearly lead to a paradoxical situation, conflict or people had accepted the principle of system, so you can clear that Windows does not support this conclusion. (Of course, if there is no apparent contradiction or conflict, is not proof that Windows will support such actions. But in this way you can rule out the obvious is not the right idea. )


Asking "what if both programs are doing? "Is also a very useful screening of a feature or design idea is a reasonable method. With "If", they can become a beautiful combination. Here are a few examples:


"How can I create a window, so it will never be covered by other Windows, even those top-level Windows are not? ”


Assume that if could be, plus if you have two programs to do so. Program a has created a "top-level" window, program b will do. Now users drag both Windows so that they overlap, what will happen? You have to create a logical conflict. It must have two Windows on top, facing down, overturned the supposed "Super top" design ideas.


"How do I highlight the process and let it be notified first/last system shutdown? I think when the system is shut down all other programs before/after you quit doing something. ”


If possible, assume that both programs do. You now have two programs want to do first/last. But you're not the first two, or two last. One of them had to give up. (This can be extended to the other on the first or the last thing people want. )


"How can you guarantee that when a user double-clicks. XYZ file I always associated program will start running? ”


Assuming that it is possible, assuming two programs want to do that. When the user clicks on it. XYZ file, which program to run?


A solution in this case is that the user to choose the program associated with the file, but once the user has decided to let another program to perform. XYZ file, then you have to accept the fact.


For many this "I want to be the best x" type problem, programmers will often come up with some tactics, such as running a timer to periodically check whether the x, if it is not, push it back into the x. Soon you begin to stop thinking, "what would happen if two programs do? "So that this is a bad idea.


If I did, I explained, many people still to no avail. I asked them to think "what would happen if two programs do? They can fight, "and the response I get is," can I get a second program to check first whether the program is running. "They don't understand that the second program is not what they wrote.


When two programs that "blows", we cannot predict which one will win, but we can determine who is expected to lose, 100%: the user.


I remember one time when my colleagues let me see there are two very good commercial software wants to be when the user clicks on it. Is called XYZ documents processes. Because this is no way to guarantee, and provides regular check in software program attempts to solve this problem.


Your first program is installed, it sets you are the. XYZ program associated with the file, it looks fine. Then you install the second program, it has its own settings. XYZ program associated with the file, so the first program came out and said, "no,. XYZ should be up to me to deal with ", and put back the file association. And the second program also said, "no way, I'm dealing with. XYZ file program ", and reset back to himself.


Children at war-game time, users can only help sat there stunned and look. XYZ file icons between the two programs for change. Both programs insist that their own to deal with. XYZ file is for the sake of users.


(

如果两个程序都这样做会怎样? - 程序员,计算机编程 - IT资讯
如果两个程序都这样做会怎样?

本文作者介绍


Raymond Chen


Raymond Chen是微软Windows Shell开发团队中的知名程序员,从1992年加入微软开始,他参与过OS/2,Windows 95,DirectX已经以后版本的Windows的开发。他的关于Windows的发展以及Win32编程个人博客“The Old New Thing”是微软MSDN上最著名的个人博客之一。著有同名书籍《The Old New Thing》,中文译名为《Windows编程启示录》。Raymond还为Microsoft TechNet撰写专栏文章。



在脑子里“设想如果可以这样”,这种方法能帮助你理解Windows是否会允许让你做这种或那种事情。如果这种设想会明显的导致一种自相矛盾的情况,或跟人们已经接受的原则体系相冲突,那你可以明确的得出Windows不会支持这种行为的结论。(当然,如果没有明显的矛盾或冲突,也不能证明Windows就一定会支持这种操作。但用这种方法你可以排除一些明显的不正确的想法。)


问“如果两个程序都这样做会怎样?”也是一种非常有用的甄别一个功能特征或设计想法是否合理的好方法。配合“设想如果可以这样”,它们能成为一个漂亮的组合拳。下面是几个例子:


“我怎么才能创建一个窗口,让它永远不会被其它窗口覆盖,即使那些最上层的窗口也不行?”


假设这样如果是可以的,加上如果有两个程序都这样做。程序A创建了一个“最上层”的窗口,程序B也这样做了。现在用户拖动这两个窗口,让它们重叠,会发生什么?你给自己创造了一个逻辑冲突。这两个窗口必须有一个在上,一个在下,推翻了假想的“超级最上层”设计想法。


“如何突出我的进程,让它成为在系统关机时第一个/最后一个接到通知?我想在系统关机时在所有其它程序退出之前/之后做一些事情。”


假设如果这样可能,假设两个程序都这样做。你现在有了两个程序都希望做第一/最后。但你不可能有两个第一或两个最后。其中有一个必须要放弃。(这个可以推广到其他的人们想要第一或最后的事情上。)


“如何能保证当用户双击.XYZ文件时总是我的关联程序会启动运行?”


假设这是可能的,假设两个程序都想这样。当用户点击.XYZ文件时,哪个程序运行?


这种情况下的一种解决方案是用户来选择文件的关联程序;但一旦用户决定让另外一个程序来执行.XYZ文件,那你不得不接受这样的事实。


对于很多这种“我想成为这最X”类型的问题,程序员通常会想出一些伎俩,比如运行一个定时器周期性的检查自己是否仍是最X,如果不是,就重新把它推到X位。不久,你就会开始停下来思考,“如果两个程序都这样做会怎样?”,于是认识到这是一个糟糕的想法。


就算是我这样解释了,很多人仍然不得要领。我让他们去想想“如果两个程序都这样做会怎样?它们会打架,”而我得到的回复是,“我可以让第二个程序检查第一个程序是否在运行。”他们不明白第二个程序不是他们写的。


当出现两个程序这样“互殴”时,我们无法预料哪一个会赢,但我们可以确定的、100%的预料的谁会输:用户。


我还清楚的记得有一回同事让我看有两个非常流利的商业软件都想成为当用户点击.XYZ文档时被调用的程序。因为这是没法保证的,于是软件里就提供了定时检查的程序试图解决这个问题。


你安装了第一个程序,它把自己设置成.XYZ文件的关联程序,这看起来很正常。然后你安装了第二个程序,它也把自己设置成.XYZ文件的关联程序,这样第一个程序就跳出来说,“不,.XYZ应该是由我来处理的”,并且把文件关联改了回去。而第二个程序也说,“没门,我才是处理.XYZ文件的程序”,并且把自己重置回去。


这种小孩斗气式的游戏进行的时候,用户只能无助的坐在那里发愣的看着.XYZ文件的图标在两个程序间换来换去。这两个程序都坚持认为让自己来处理.XYZ文件是在为用户着想。


)


If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)





QQ:154298438
QQ:417480759