473,396 Members | 1,866 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,396 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 2670
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.