意见通缉:呼叫事件处理程序 [英] Opinion Wanted: Calling an Event Handler

查看:52
本文介绍了意见通缉:呼叫事件处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认识的一个人从不重构他的代码并坚持将所有内容放在事件处理程序中。例如,他在ItemDataBound事件处理程序中对一个

DataGrid进行了一些初始化(无论如何,这对于他的初始化来说实际上是错误的
的地方,因为它没有*没有*用绑定的项目来做

,但这是另一个话题,完全相同。

任何费率,有时候,有必要刷新。控件采取

优势发生的更新,他将手动调用事件

处理程序,传递给当前事件处理程序发送者和EventArgs

参数。它让我绝对疯狂,我向他解释他的

代码需要重构;但是,他坚持认为它有效。所以他

拒绝改变他的方式。


从技术上讲,他是对的 - 它确实有效。但是,在我看来,它很邋

并且可以从重构的一点时间中获益。


你们怎么想? br />

-

肖恩

A guy I know never refactors his code and insists on putting everything
in an event handler. For example, he does some initialization of a
DataGrid in the ItemDataBound event handler (which is actually the wrong
place for his initialization, anyhow, because it has *nothing* to do
with the items being bound, but that''s another topic, altogether). At
any rate, some times, it''s necessary to "refresh" the control to take
advantage of an update that occurred and he''ll manually call the event
handler, passing it the current event handlers sender and EventArgs
parameters. It drives me absolutely nuts and I explain to him that his
code needs to be refactored; but, he insists that "it works" so he
refuses to change his ways.

Technically, he''s right --it does work. But, in my opinion, it''s sloppy
and could benefit greatly from a little time spent on refactoring.

What do you guys think?

--
Sean

推荐答案

你好肖恩,


你是对的。但是,说服你的同事可能会证明是一项令人生畏的艰巨任务,尤其是如果你对他没有权力。在Microsoft MSDN上查看以下网站的



http://msdn.microsoft.com/practices/


这是关于最佳实践,良好设计和良好的大量信息< br $> b $ b架构。


为什么最佳实践很重要?最佳实践是为了降低软件开发和维护成本而开发的。

设计不良的软件成为公司的一个信天翁
开发它的
。解决问题比解决问题要昂贵得多。预防它们​​需要花费一些资源用于教育和开发过程中的时间。但任何软件公司的最大支出来自支持。而开发不佳的软件支持起来很昂贵。另一个成本因素是该软件不可避免的升级/扩展。精心设计的软件更容易扩展和升级,因为它是在考虑到这一点的基础上构建的。


如果您对同事没有权限,向你的主管显示这个

资源(上面的链接),让他/她做他/她的工作。如果您对此人确实拥有

权限,请在您的

组织中制定最佳做法策略。并且一定要为自己阅读这些最佳实践。


请记住,要求不是为了证明你是正确的(例如证明

你在与你的同事的辩论中是正确的)。您需要

才能成为您组织的资产。


-

HTH,
< br $>
Kevin Spencer

Microsoft MVP

..Net开发人员

谁是Mighty Abbott?

双炮塔scalawag。


Fao,Sean <恩********** @ yahoo.comI-WANT-NO-SPAM>在留言中写道

news:u7 ************** @ TK2MSFTNGP10.phx.gbl ...
Hi Sean,

You are correct. However, convincing your colleague may prove to be a
daunting task, esp. if you do not have authority over him. Check out the
following web site on the Microsoft MSDN:

http://msdn.microsoft.com/practices/

This is a wealth of information about best practices, good design, and good
architecture.

Why are best practices important? Best practices are developed for the
purpose of making software cost less to develop and maintain.
Poorly-designed software becomes an albatross on the neck of the company
that develops it. It is much more expensive to fix problems than to prevent
them. Preventing them entails an expenditure of some resources towards
education, and time in the development process. But the greatest expense to
any software company comes from support. And poorly-developed software is
expensive to support. Another cost factor is the inevitable
upgrade/extension of the software. Well-designed software is much easier to
extend and upgrade, because it is built with this in mind.

If you do not have authority over your colleague, show your supervisor this
resource (link above), and let him/her do his/her job. If you do have
authority over this person, make best practices a policy in your
organization. And be sure to read up on these best practices for yourself.

And remember, the requirement is not for you to be proven right (e.g. prove
you are correct in a debate with your colleague). The requirement is for you
to be an asset to your organization.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Who is Mighty Abbott?
A twin turret scalawag.

"Fao, Sean" <en**********@yahoo.comI-WANT-NO-SPAM> wrote in message
news:u7**************@TK2MSFTNGP10.phx.gbl...
我认识的一个人永远不会重构他的代码并坚持将所有内容放入事件处理程序中。例如,他在ItemDataBound事件处理程序中对DataGrid进行了一些初始化(这实际上是他初始化的错误位置,无论如何,因为它与项目没有任何关系
被束缚,但这是另一个话题,完全相同。无论如何,有些时候,有必要刷新。控件利用发生的更新,他将手动调用事件处理程序,将其传递给当前事件处理程序发送者和EventArgs参数。它驱使我绝对疯了,我向他解释他的代码需要重构;
但是,他坚持认为它有效。所以他拒绝改变他的方式。

从技术上讲,他是对的 - 确实有效。但是,在我看来,这很邋
并且可以从花一点时间在重构上获益。

你们怎么想?

- -
Sean
A guy I know never refactors his code and insists on putting everything in
an event handler. For example, he does some initialization of a DataGrid
in the ItemDataBound event handler (which is actually the wrong place for
his initialization, anyhow, because it has *nothing* to do with the items
being bound, but that''s another topic, altogether). At any rate, some
times, it''s necessary to "refresh" the control to take advantage of an
update that occurred and he''ll manually call the event handler, passing it
the current event handlers sender and EventArgs parameters. It drives me
absolutely nuts and I explain to him that his code needs to be refactored;
but, he insists that "it works" so he refuses to change his ways.

Technically, he''s right --it does work. But, in my opinion, it''s sloppy
and could benefit greatly from a little time spent on refactoring.

What do you guys think?

--
Sean



它的工作原理是一个新手的话。


我的一位大学教授问了一个问题(给了答案)

我永远不会忘记。他问,


编写代码的目的是什么?


我们很多人给出了答案,制作计算机执行某项任务,等等。
等他的回答:


"向下一个读这段代码的人说清楚你是如何解决的。

问题。


我教授的说法很简单:如果唯一的一点是让

计算机做点什么,那么为什么不只是用汇编语言写它?

还是机器语言?计算机理解它和它一样好。
理解C#,就像它一样。答案是

后来其他程序员很难发现你做了什么和

为什么。


这导致了我的编程规则之一:


平庸的标准总比没有标准好。





你做的最好的新方式比通常的方式好十倍好b / b
,或者根据定义很糟糕,因为如果你要去b $ b来强迫别人花更多的时间来弄清楚你做了什么,

最好值得这么麻烦。


破解时髦代码有效你的雇主需要额外付费,因为维修费用会更高。任何白痴都可以(给予足够的时间)使程序工作。一个优秀的程序员将使它工作,并且

清楚地说明它是如何工作的,以便在

的未来很容易修复和修改。这就是专业人士与稀释剂之间的区别。

"It works" are the words of a greenhorn.

A university professor of mine asked a question (and gave the answer)
that I''ll never forget. He asked,

"What is the purpose of writing code?"

Lots of us gave answers, "To make the computer perform some task," etc.
etc. His answer:

"To make it clear to the next guy who reads that code how you solved
the problem."

My professor''s claim was simple: if the only point is to make the
computer do something, then why not just write it in assembly language?
Or machine language? The computer understands that just as well as it
understands C#, as it were. The answer is that it''s very difficult for
other programmers coming along afterward to discover what you did and
why.

This leads into one of my "rules of programming":

"A mediocre standard is better than no standard at all."

or

"Your cool new way of doing whatever had better be ten times better
than the usual way, or by definition it sucks, because if you''re going
to force someone else to spend extra time to figure out what you did,
it had better be worth the trouble."

Hacking out funky code "that works" costs your employer extra, because
it will be more expensive to maintain. Any moron can (given enough
time) make a program "work." A good programmer will make it work, and
make it clear how it works so that it''s easy to fix and modify in the
future. That''s what separates the professionals from the dilletantes.


让你的整个团队投入并购买一个Martin Fowler's的副本预订。

-

Dale Preston

MCAD C#

MCSE,MCDBA

Fao,Sean写道:
Get your whole team to pitch in and buy the guy a copy of Martin Fowler''s book.
--
Dale Preston
MCAD C#
MCSE, MCDBA
"Fao, Sean" wrote:
我认识的一个人从不重构他的代码并且坚持将所有内容放在事件处理程序中。例如,他在ItemDataBound事件处理程序中对一个
DataGrid进行了一些初始化(无论如何,这对于他的初始化实际上是错误的地方,因为它没有*没有*要做的事情。绑定的项目,但这是另一个主题,完全)。无论如何,有时候,刷新是必要的。控件采取发生更新的优势,他将手动调用事件处理程序,传递当前事件处理程序发送者和EventArgs
参数。它让我绝对疯狂,我向他解释他的代码需要重构;但是,他坚持认为它有效。所以他拒绝改变他的方式。

从技术上讲,他是对的 - 这确实有用。但是,在我看来,这很邋
并且可以从花一点时间在重构上获益。

你们怎么想?

- -
肖恩
A guy I know never refactors his code and insists on putting everything
in an event handler. For example, he does some initialization of a
DataGrid in the ItemDataBound event handler (which is actually the wrong
place for his initialization, anyhow, because it has *nothing* to do
with the items being bound, but that''s another topic, altogether). At
any rate, some times, it''s necessary to "refresh" the control to take
advantage of an update that occurred and he''ll manually call the event
handler, passing it the current event handlers sender and EventArgs
parameters. It drives me absolutely nuts and I explain to him that his
code needs to be refactored; but, he insists that "it works" so he
refuses to change his ways.

Technically, he''s right --it does work. But, in my opinion, it''s sloppy
and could benefit greatly from a little time spent on refactoring.

What do you guys think?

--
Sean



这篇关于意见通缉:呼叫事件处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆