Math Is Fun Forum
  Discussion about math, puzzles, games and fun.   Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ • π ƒ -¹ ² ³ °

You are not logged in.

#1 2008-10-14 11:29:03

MathsIsFun
Administrator
Registered: 2005-01-21
Posts: 7,535

Naming Conventions

I am trying to make my life easier by sticking to some Naming Conventions:

* avoid using "_"
* variables: use lowerCamelCase
* functions: use lowerCamelCase, with first word being a verb (like getThing(), or clearDrawing())
* classes: use UpperCamelCase
* arrays: use plural (dayNames, tableCells)
* file names: always lower case

I would also like to have some way of choosing which way around I put together variable names:

* should I use xStt or sttX ?
* how about dayCount, dayNum, currentDay, lastDay ... shouldn't "day" always be first or last?


"The physicists defer only to mathematicians, and the mathematicians defer only to God ..."  - Leon M. Lederman

Offline

#2 2008-10-14 12:39:20

Ricky
Moderator
Registered: 2005-12-04
Posts: 3,791

Re: Naming Conventions

Here is one I could never find a good solution for:

Parameter names (i.e. variable names that you pass to the function) in a modifier.  For example:

class DoesNothing {
public:
  DoesNothing();
  void Weight(int ???);
private:
  int weight;
};

I am opposed most of the time to call things "myWeight" for the class variables.  paramWeight seems to be too lengthy for the "???".


"In the real world, this would be a problem.  But in mathematics, we can just define a place where this problem doesn't exist.  So we'll go ahead and do that now..."

Offline

#3 2008-10-14 14:01:06

Chewy
Member
Registered: 2008-08-07
Posts: 67

Re: Naming Conventions

Question:

Is this Visual Basic ? Looks like it to me, correct me if I am wrong. My instructor advised our class to use the most descriptive naming convention, while keeping it brief.

Like :

dim intBeans
dim intPots   etc... 

*Note: ("dim" in this example is the dimension (< I think it stands for dimension) command, creating variables Beans and Pots, for anyone reading this that isn't necessarily familiar with Visual Basic)

He said that using CamelCase was fine, but he preferred something short and sweet, so instead of:

dim int dayCountYesterday

he would suggest for clarity

dim int countYest

or something really short and sweet for programmers that may look over the code after the program's creation, just in case the programmer that created the code wasn't doing the revising personally.

So to shorten this up, I think that using what makes sense at first glance matters more than being strict with naming conventions. Conventions should be considered, but ultimately you could try my instructors idea, MathsIsFun. My instructor by the way used to work for Google. So I guess that he must have learned a few good ideas while working there.

Last edited by Chewy (2008-10-14 14:02:31)

Offline

#4 2008-10-14 14:06:39

Chewy
Member
Registered: 2008-08-07
Posts: 67

Re: Naming Conventions

As I look at Ricky's example, it looks like you two are talking about either C++ or Java with the { 's.   I am not sure what naming conventions you should use, MathsIsFun, in regard to either of those languages. I am teaching myself some Java, and I like it so far.

Offline

#5 2008-10-14 14:45:23

Ricky
Moderator
Registered: 2005-12-04
Posts: 3,791

Re: Naming Conventions

Naming conventions are almost universal.  Just about all programming languages allow variables with AZaz09_, and can't start with a number.


"In the real world, this would be a problem.  But in mathematics, we can just define a place where this problem doesn't exist.  So we'll go ahead and do that now..."

Offline

#6 2008-10-14 16:28:35

MathsIsFun
Administrator
Registered: 2005-01-21
Posts: 7,535

Re: Naming Conventions

That's right, I am not being specific as to language (but we should be aware that many languages are case sensitive).

Ricky wrote:

I am opposed most of the time to call things "myWeight" for the class variables.  paramWeight seems to be too lengthy for the "???".

I have used newWeight and also TheWeight in cases like that ... it is somewhat annoying I agree.

Chewy wrote:

dim intBeans
dim intPots   etc...

I personally do not like putting the type in the name (like intBeans or charID) because if you need to change the type you then have to do variable renaming, and possibly miss one.


"The physicists defer only to mathematicians, and the mathematicians defer only to God ..."  - Leon M. Lederman

Offline

#7 2008-10-14 22:00:01

Chewy
Member
Registered: 2008-08-07
Posts: 67

Re: Naming Conventions

I could see how that could happen.

Offline

#8 2009-05-15 02:18:41

LorraineBR
Member
Registered: 2009-05-13
Posts: 33

Re: Naming Conventions

my lecturer always says give it a name that means something because it will be easier to understand when reading over, in functions the first letter in the word should be in lower case but after that to have them startin with an upper case letter e.g getLengthOfArray(). he also believes that member data should start with m_ eg m_Data


Theres only 10 type of people in the world
Those that understand binary
And those that dont

Offline

#9 2009-05-15 10:17:23

MathsIsFun
Administrator
Registered: 2005-01-21
Posts: 7,535

Re: Naming Conventions

For me "m_Data" looks ugly, just personal preference I suppose.


"The physicists defer only to mathematicians, and the mathematicians defer only to God ..."  - Leon M. Lederman

Offline

#10 2009-05-15 20:28:46

bobbym
Administrator
From: Bumpkinland
Registered: 2009-04-12
Posts: 86,776

Re: Naming Conventions

It is ugly. I wouldn't use m_Data,  a week later I wouldn't remember what it meant. Unless my proggie is heavily commented, I have no chance of understanding it later.


In mathematics, you don't understand things. You just get used to them.
Of course that result can be rigorously obtained, but who cares?
Combinatorics is Algebra and Algebra is Combinatorics.

Offline

Board footer

Powered by FluxBB