内部函数的命名约定 [英] Naming convention for inner functions

查看:80
本文介绍了内部函数的命名约定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我应该在这个示例代码中调用名为Factorial_的函数:


class SomeClass {


...

public int Factorial(int f){

if(f <0)抛出SomeException(Some message。);

if(f = = 0 || f == 1)返回1;

返回Factorial_(f);

}


private int Factorial_ (int f){

如果(f == 1)返回1;

返回f * Factorial_(f-1);

}

...

}


调用它Factorial_看起来很糟糕。无法调用Factorial,因为它是公共方法应该具有的

名称。应该是什么?


telmo

What should i call the functions named Factorial_ in this sample code:

class SomeClass {

...
public int Factorial(int f) {
if (f<0) throw SomeException("Some message.");
if (f==0 || f==1) return 1;
return Factorial_(f);
}

private int Factorial_(int f) {
if (f==1) return 1;
return f*Factorial_(f-1);
}
...
}

Calling it Factorial_ looks bad. Cannot call Factorial because it is the
name that the public method should have. What should it be?

telmo

推荐答案

为什么需要2个功能?你不能把它合二为一吗?


这通常不是问题,因为大部分时间都不会发生

冲突这样的名字之间。但是当它确实发生时,我猜想每个人都有自己的约定。


" Telmo Costa" < TE ********* @ netvisao.pt>在消息中写道

news:ne ******************** @ newsfront4.netvisao.pt ...
Why do you need 2 functions? Can''t you combine this into 1?

It is usually not an issue, since most of the time there wouldn''t be a
conflict between the names like that. But when it does happen, I would guess
everyone has their own conventions.

"Telmo Costa" <te*********@netvisao.pt> wrote in message
news:ne********************@newsfront4.netvisao.pt ...
我应该在这个示例代码中调用名为Factorial_的函数:

class SomeClass {

...
public int Factorial(int f){
if(f <0)抛出SomeException(Some message。);
if(f == 0 || f == 1)返回1;
返回Factorial_(f);
}

private int Factorial_(int f){
if if(f == 1)return 1;
return f * Factorial_(f-1);
}
...

调用它Factorial_看起来很糟糕。不能调用Factorial,因为它是公共方法应该具有的名称。应该是什么?

telmo
What should i call the functions named Factorial_ in this sample code:

class SomeClass {

...
public int Factorial(int f) {
if (f<0) throw SomeException("Some message.");
if (f==0 || f==1) return 1;
return Factorial_(f);
}

private int Factorial_(int f) {
if (f==1) return 1;
return f*Factorial_(f-1);
}
...
}

Calling it Factorial_ looks bad. Cannot call Factorial because it is the
name that the public method should have. What should it be?

telmo



我不相信如何命名私人

函数。在你的例子中,我会将它命名为FactorialInternal。

Telmo Costa写道:
I don''t believe there is any real convention for how to name private
functions. In your example I would name it something like FactorialInternal.
"Telmo Costa" wrote:
我应该在这个示例代码中调用名为Factorial_的函数:

class SomeClass {

... <公共int Factorial(int f){
如果(f <0)抛出SomeException(Some message。);
if(f == 0 || f == 1)返回1;
返回Factorial_(f);
}
私人int Factorial_(int f){
如果(f == 1)返回1;
返回f * Factorial_(f-1);
}
...


调用它Factorial_看起来很糟糕。不能调用Factorial,因为它是公共方法应该具有的名称。它应该是什么?

telmo
What should i call the functions named Factorial_ in this sample code:

class SomeClass {

...
public int Factorial(int f) {
if (f<0) throw SomeException("Some message.");
if (f==0 || f==1) return 1;
return Factorial_(f);
}

private int Factorial_(int f) {
if (f==1) return 1;
return f*Factorial_(f-1);
}
...
}

Calling it Factorial_ looks bad. Cannot call Factorial because it is the
name that the public method should have. What should it be?

telmo



Marina写道:
为什么你需要2个功能?你不能把它合二为一吗?


Factorial只是一个例子。

有很多情况下功能无法结合。在这个

的情况下,因为Factorial_是一个递归函数而且Factorial

代码只能执行一次。
Why do you need 2 functions? Can''t you combine this into 1?
Factorial was just an example.
There are many situations where functions cannot be combine. In this
case is just because Factorial_ is a recursive function and Factorial
code should be executed only once.
应该是什么我在这个示例代码中调用了名为Factorial_的函数:

class SomeClass {

...
public int Factorial(int f){
if (f< 0)抛出SomeException(Some message。);
if if(f == 0 || f == 1)返回1;
返回Factorial_(f);
}

private int Factorial_(int f){
如果(f == 1)返回1;
返回f * Factorial_(f-1);
}
...

调用它Factorial_看起来很糟糕。不能调用Factorial,因为它是公共方法应该具有的名称。它应该是什么?

telmo
What should i call the functions named Factorial_ in this sample code:

class SomeClass {

...
public int Factorial(int f) {
if (f<0) throw SomeException("Some message.");
if (f==0 || f==1) return 1;
return Factorial_(f);
}

private int Factorial_(int f) {
if (f==1) return 1;
return f*Factorial_(f-1);
}
...
}

Calling it Factorial_ looks bad. Cannot call Factorial because it is the
name that the public method should have. What should it be?

telmo




这篇关于内部函数的命名约定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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