功能与子/公共与私人 [英] Function vs Sub /Public vs Private

查看:77
本文介绍了功能与子/公共与私人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望有人可以告诉我,在将代码例程区分为函数或

a Sub或者是否存在时,我的应用程序是否有任何性能优势?在代码模块中识别作为函数或私有函数(或Sub作为Sub或

Private Sub)的函数之间的性能优势。


我明白使用私有函数或私有子限制了可以调用它的

范围,但我想知道是否有任何

进行区分的速度或间接费用。


我知道我不能使用= SubName()来调用Sub。在

a控制的事件过程中,只有=" = FunctionName(),所以我习惯了将

标记为一个函数而不是。


谢谢,

lq

I''m hoping someone can tell me if there is any performance benefit in
my applications between distinguishing a code routine as a Function or
a Sub or if there is a performance benefit between identiying a
Function as a Function or a Private Function (or Sub as a Sub or a
Private Sub) in code modules.

I understand that using Private Functions or Private Subs limits the
scope from which it can be called, but I''m wondering if there is any
speed or overhead benefit in making the distinction.

I know I can''t call a Sub using "=SubName()" in the event procedure of
a control, only = "=FunctionName()", so I just got in the habit of
labeling everything as a Function instead.

Thanks,
lq

推荐答案

7月18日2005 08:44:53 -0700,lauren quantrell

< la ************* @ hotmail.com>写道:
On 18 Jul 2005 08:44:53 -0700, "lauren quantrell"
<la*************@hotmail.com> wrote:
我希望有人可以告诉我,在将代码例程区分为函数或
时,我的应用程序是否有任何性能优势Sub或者在代码模块中将功能识别为功能或私有功能(或Sub as Sub或
Private Sub)之间存在性能优势。


如果没有返回一个值,Sub应该比函数更有效率
但我怀疑你会注意到区别。公共vs

私人不应该有任何差别,因为它只是一个

规则,在编译时检查。

我明白使用私有函数或私有子函数限制了可以调用它的范围,但我想知道是否有任何速度或开销优势来进行区分。


不应该。

我知道我不能使用" = SubName()"在一个控件的事件过程中,只有=" = FunctionName(),所以我养成了将所有内容标记为函数的习惯。
I''m hoping someone can tell me if there is any performance benefit in
my applications between distinguishing a code routine as a Function or
a Sub or if there is a performance benefit between identiying a
Function as a Function or a Private Function (or Sub as a Sub or a
Private Sub) in code modules.
If a value is not being returned, a Sub should be a tiny bit more efficient
than a Function, but I doubt you''ll ever notice the difference. Public vs
Private should not be expected to make any difference at all since it''s only a
rule, checked at compile-time.
I understand that using Private Functions or Private Subs limits the
scope from which it can be called, but I''m wondering if there is any
speed or overhead benefit in making the distinction.
There shouldn''t be.
I know I can''t call a Sub using "=SubName()" in the event procedure of
a control, only = "=FunctionName()", so I just got in the habit of
labeling everything as a Function instead.




我认为风格很差(但这是品味的问题),但我怀疑是否有任何显着的性能损失。



I consider that poor style (but that''s a matter of taste), but I doubt there''s
any noticeable performance penalty.


Steve,

感谢您的回复。


糟糕的风格指的是将所有内容标记为函数而不是在

控件的事件过程中使用= FunctionName()的
Sub或Poor Style?


谢谢,

lq

Steve,
Thanks for the reply.

Poor Style refering to labeling everything as a Function instead of a
Sub or Poor Style using =FunctionName() in the event procedure of a
control?

thanks,
lq


" lauren quantrell" < LA ************* @ hotmail.com>写在

新闻:11 ********************** @ z14g2000cwz.googlegr oups.com:
"lauren quantrell" <la*************@hotmail.com> wrote in
news:11**********************@z14g2000cwz.googlegr oups.com:
糟糕的风格指的是在控件的事件
过程中使用= FunctionName()将所有内容标记为函数而不是使用Sub或Poor样式?
Poor Style refering to labeling everything as a Function instead
of a Sub or Poor Style using =FunctionName() in the event
procedure of a control?




如果它是一个功能,它应该是一个功能。


如果不是,它应该是一个子。


听起来很公理,但是每个代码片段你都写了一个函数

放弃了你作为程序员评估

目的和使用的责任。你正在写的代码。


对我来说,默认是制作一个SUB。


你只需要写一个函数*必须*:


- 如果必须返回单个值


- 如果需要在只有函数的上下文中调用代码
工作(即宏等)。


如果你写一个sub,后来需要用它作为乐趣ction,它是关于

1秒的工作将它改成一个功能。


-

David W. Fenton http://www.bway.net/~dfenton

dfenton at bway dot net http://www.bway.net / ~dfassoc



If it''s a function, it should be a function.

If it''s not, it should be a sub.

Sounds axiomatic, but making every code snippet you write a function
is abdicating your responsibility as a programmer for evaluating the
purpose and use of the code you are writing.

To me, the default is to make a SUB.

You only write a function when you *must*:

- if you must return a single value

- if the code needs to be called in contexts where only functions
work (i.e., macros, etc.).

If you write a sub and later need to use it as function, it''s about
1 second''s work to change it to a function.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc


这篇关于功能与子/公共与私人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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