473,322 Members | 1,417 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Naming convention for inner functions

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
Nov 17 '05 #1
12 2667
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 ...
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

Nov 17 '05 #2
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:
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

Nov 17 '05 #3
Marina wrote:
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.
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


Nov 17 '05 #4
Hi,

One recommendation is to name private elements of classes with names
starting with lowercase letter, so you could use 'factorial',
'factorialHelper', etc.

Regards - Octavio

"Telmo Costa" <te*********@netvisao.pt> escribió en el mensaje
news:ne********************@newsfront4.netvisao.pt ...
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

Nov 17 '05 #5
Octavio Hernandez <do****@danysoft.com> wrote:
One recommendation is to name private elements of classes with names
starting with lowercase letter, so you could use 'factorial',
'factorialHelper', etc.


I've never seen that, and it goes against the MS naming conventions,
which state that Pascal case should be used. There's nothing saying
that's only for public methods, and changing it just for private
methods introduces inconsistency in my view.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #6
Jon,

Thanks for the correction! You're absolutely right regarding naming
guidelines for methods (by the way, here is the link for readers interested)

http://msdn.microsoft.com/library/de...guidelines.asp

Maybe I've violated them 2 or 3 times :-)

Regards - Octavio

"Jon Skeet [C# MVP]" <sk***@pobox.com> escribió en el mensaje
news:MP************************@msnews.microsoft.c om...
Octavio Hernandez <do****@danysoft.com> wrote:
One recommendation is to name private elements of classes with names
starting with lowercase letter, so you could use 'factorial',
'factorialHelper', etc.


I've never seen that, and it goes against the MS naming conventions,
which state that Pascal case should be used. There's nothing saying
that's only for public methods, and changing it just for private
methods introduces inconsistency in my view.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 17 '05 #7
Octavio Hernandez <do****@danysoft.com> wrote:
One recommendation is to name private elements of classes with names
starting with lowercase letter, so you could use 'factorial',
'factorialHelper', etc.


I've never seen that, and it goes against the MS naming conventions,
which state that Pascal case should be used. There's nothing saying
that's only for public methods, and changing it just for private
methods introduces inconsistency in my view.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #8
Jon,

Thanks for the correction! You're absolutely right regarding naming
guidelines for methods (by the way, here is the link for readers interested)

http://msdn.microsoft.com/library/de...guidelines.asp

Maybe I've violated them 2 or 3 times :-)

Regards - Octavio

"Jon Skeet [C# MVP]" <sk***@pobox.com> escribió en el mensaje
news:MP************************@msnews.microsoft.c om...
Octavio Hernandez <do****@danysoft.com> wrote:
One recommendation is to name private elements of classes with names
starting with lowercase letter, so you could use 'factorial',
'factorialHelper', etc.


I've never seen that, and it goes against the MS naming conventions,
which state that Pascal case should be used. There's nothing saying
that's only for public methods, and changing it just for private
methods introduces inconsistency in my view.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 17 '05 #9

"Telmo Costa" <te*********@netvisao.pt> wrote in message
news:ne********************@newsfront4.netvisao.pt ...
What should i call the functions named Factorial_ in this sample code:


I usually use something like InternalXxx if the method is non-virtual, and
something like XxxCore or XxxImpl if the method is virtual.
Nov 17 '05 #10

"Telmo Costa" <te*********@netvisao.pt> wrote in message
news:ne********************@newsfront4.netvisao.pt ...
What should i call the functions named Factorial_ in this sample code:


I usually use something like InternalXxx if the method is non-virtual, and
something like XxxCore or XxxImpl if the method is virtual.
Nov 17 '05 #11
It's very rare that I write a private method that does _exactly the
same_ thing as a public method, and so run into such a naming conflict.
I would be tempted to call it something like CalculateFactorial().

I find it far more common that the private method does some _part_ of a
larger job, in which case I name it based on what it does without
running into a naming conflict.

Be careful that by creating an "internal method" naming convention you
don't encourage people to start blindly naming their methods
XxxInternal just because they're used from the Xxx public method,
without really considering what the internal method is doing.

Nov 17 '05 #12
It's very rare that I write a private method that does _exactly the
same_ thing as a public method, and so run into such a naming conflict.
I would be tempted to call it something like CalculateFactorial().

I find it far more common that the private method does some _part_ of a
larger job, in which case I name it based on what it does without
running into a naming conflict.

Be careful that by creating an "internal method" naming convention you
don't encourage people to start blindly naming their methods
XxxInternal just because they're used from the Xxx public method,
without really considering what the internal method is doing.

Nov 17 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: Generic Usenet Account | last post by:
A lot has been said in this newsgroup regarding the "evil" set/get accessor methods. Arthur Riel, (of Vanguard Training), in his class, "Heuristis for O-O Analysis & Design", says that there is...
27
by: Derek | last post by:
The company where I work uses a naming convention that I have never used before. They use mixed-case letters for public member functions, but lower-case with underscores for the rest, like this:...
5
by: Ook | last post by:
Is there any kind of naming convention for accessor and modifiers? What I've been doing is something like this: // accessor int getSize(); // Modifier void setSize( int newsize); private:
4
by: Telmo Costa | last post by:
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)...
0
by: Carl Colijn | last post by:
Hi all, Disclaimer: before I might trigger your "let's start a holy war!" button, I'd like to say I'm not intended to; I just post this message to get some input and not to promote "Yet Another...
0
by: Bruno Lavoie | last post by:
Hello, i'm etablishing a naming convention for a new project under postgresql. For tables, sequences, views, that's ok! I used good naming conventions for this in the past and i'll keep these...
6
by: dm1608 | last post by:
I'm relatively new to ASP.NET 2.0 and am struggling with trying to find the best naming convention for the BAL and DAL objects within my database. Does anyone have any recommendations or best...
2
by: Bill Pursell | last post by:
In libabc, I have a function which takes a NULL-terminated array of character strings. A second, closely related function take a NULL-terminated array of void *: abc_foo( char ** ); abc_vfoo(...
23
by: Thorsten Kampe | last post by:
Okay, I hear you saying 'not another naming conventions thread'. I've read through Google and the 'naming conventions' threads were rather *spelling conventions* threads. I'm not interested...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.