PDA

View Full Version : Do you adhere to Naming Conventions?



CreganTur
04-21-2008, 11:43 AM
As programmers it's easy to say that we're an eclectic bunch. We all have our own ways of doing things; and some ways are definately more optimal than others.

Without accepted standards our individuilism would take over and the only people who could read our code, other than ourselves, would be our close friends.

But standards can be confining sometimes, hence the question: Do you adhere to Naming Conventions?

ProteanBeing
04-21-2008, 03:28 PM
Is there a site with all the naming conventions?

Tommy
04-21-2008, 05:42 PM
No.
I make it up as I go along. But as a general rule I name the variables for what they are. ex ChartForPLotA arrOfPoints.... On subs and functions I use iVariableName for input oVariableName for output and ioVariableName for input output. Locals are prefixed with mVariableName . what I was told to do and old habit die hard :) besides I like it, makes cents(hehe) to me.

Why would I want to put cmdExit_Click? I like Exit_Click 3 letters less to type. Most of my code is self explainitory (unless it's the traffic cop and then your guess is about as good as mine after I'm through) LOL

matthewspatrick
04-22-2008, 07:50 AM
I'm with Tommy. My variable names are very descriptive, and I feel little need to prepend them with things like lng and dbl.

That said, there are times that I do it anyway. (Think Walt Whitman, http://www.brainyquote.com/quotes/quotes/w/waltwhitma132584.html) For example, for some reason I have a tendency to use naming conventions on my UserForms like cmd for CommandButtons, chk for CheckBoxes, and lb for ListBoxes. And I also tend to start all class names with cls.

But regular variables and constants? Simple descriptive names, and that's it.

Oorang
04-23-2008, 08:05 PM
I go so far as to enforce naming conventions using static code analysis:)

It really makes it WAY easier to manage the code. Aside from being to easily tell if something is a variable and it's type & scope, it also makes it quite easy to use find/replace features as most of your names end up unique.

Trevor
04-26-2008, 10:22 PM
I make it up as I go along, anything that will confuse anyone trying to steal my work , even though in vars that don't go anywhere just for amusment :-p

Norie
04-27-2008, 08:04 AM
I think there's a clue in the question.

ie Naming Convention(s)

Of course there are formal, documented conventions and a lot of people follow them.

But a lot of people have there own.:)

Bob Phillips
04-27-2008, 12:54 PM
Absolutely!

All global variables (if I use them are preceded by mg).

All private module level variables are preceded ny mm.

All private procedure level variables are preceded by mp.

The rest is a descriptive text for the variable. I don't bother to try and describe the variables type, totally pointless.

All worksheets, forms, controls also get a standard prefix.

BTW I don't go with 'less to type', it rarely makes any difefrence in a project, and it if is less meaningful, the time lost down the line will far exceed the time taken to add it.

fumei
04-28-2008, 12:00 PM
For the most part, yes. Although I have to say not always. I would agree with the statement:

"But regular variables and constants? Simple descriptive names, and that's it"

Also, I am much more rigid in my naming for userform controls.

Ken Puls
04-29-2008, 07:10 PM
I tend to use a modified form of the Reddick convention. (i.e. I do preface with the variable type.) I aslo try to make them short, but descriptive. I just find that it makes it easier to see them in the middle of the code, and I can easily pull them up with CTRL+Space once I've put in the variable type.

Honestly, as long as the convention is a (consistent) convention within the project, I think that is the important part. Like writing, everyone will develop their own style that works best for them.

OBP
07-14-2008, 09:18 AM
I know I should, but alas I don't and my lame excuse is that I am too busy :omg2:

Imdabaum
05-11-2010, 08:41 AM
I was once criticized for using camel casing in .NET. The guy apparently thought I was a weak programmer because of it.

I shrugged it off laughing and said "Anyone that can read my code would know that I'm weak. I've only been doing this professionally for 2 years. And only started in .NET 3 months ago. My naming conventions aren't even the half of it."

He didn't find it amusing and I was forced to change all the code while he hovered over my shoulder.

In short, I'll do better from now on. Just have to remember which conventions go with which language.

EDITED: Sorry didn't realize how old this was. I was doing a search on Set ctrl =.. and it came up. Sorry to beat a dead horse.

CreganTur
05-11-2010, 11:00 AM
Camel Case is a perfectly acceptable form of coding- in fact it's required where I work because it makes it much easier to read variables and code. That guy sounds like he's more than a little full of himself.

Norie
05-11-2010, 01:18 PM
What is 'camel case'?

I don't think I've ever heard of it.

Anyone be able to provide a decent link?

Imdabaum
05-11-2010, 02:09 PM
What is 'camel case'?

I don't think I've ever heard of it.

Anyone be able to provide a decent link?

SurEiCanGiveYouaLink (http://en.wikipedia.org/wiki/CamelCase)

Bob Phillips
05-27-2010, 01:11 AM
Camel Case is a perfectly acceptable form of coding- in fact it's required where I work because it makes it much easier to read variables and code. That guy sounds like he's more than a little full of himself.

You aren't wrong. People who force their conventions are basically saying that they are incapable of understanding anything that strays one iota from their comfort zone, so I doubt that they have any real skill in the profession.

stanl
05-27-2010, 04:44 AM
so I doubt that they have any real skill in the profession.

but if you think about it there is just soooo much code out there that can be dragged and dropped into a project; the word eclectic comes to mind. Can't count how many routines I have written that re-appear as postings with the header chopped. However, as to naming - I'm mostly interested in variables and try to stick to the Hungarian Notation

oVAR = Object
aVAR = Array
nVAR = numeric
cVAR = char
lVAR = logical
dVAR = date

.02

Imdabaum
05-27-2010, 09:19 AM
You aren't wrong. People who force their conventions are basically saying that they are incapable of understanding anything that strays one iota from their comfort zone, so I doubt that they have any real skill in the profession.

He's skilled, but like stanl said... I think it was more of him just being eclectic. Nevertheless, I still try to learn the notation and make my code easier to read by others.

Bob Phillips
05-27-2010, 02:36 PM
but if you think about it there is just soooo much code out there that can be dragged and dropped into a project; the word eclectic comes to mind. Can't count how many routines I have written that re-appear as postings with the header chopped. However, as to naming - I'm mostly interested in variables and try to stick to the Hungarian Notation

oVAR = Object
aVAR = Array
nVAR = numeric
cVAR = char
lVAR = logical
dVAR = date

.02

So don't you think if you were working for someone who said you can't use that style, you had to use o_var as an example, would be showing a scary degree of inflexibility?

Bob Phillips
05-27-2010, 02:37 PM
He's skilled, but like stanl said... I think it was more of him just being eclectic. Nevertheless, I still try to learn the notation and make my code easier to read by others.

Huh? How does saying that Camel Case shows you as a weak programmer translate to being eclectic?

Imdabaum
05-28-2010, 12:52 PM
Huh? How does saying that Camel Case shows you as a weak programmer translate to being eclectic?

:banghead: See now I'm not only a bad programmer, but I'm a poor vocabularian as well. Sorry, I read eclectic, but thought eccentric. In that he is very conventional in an unconventional way. Everything has to be a certain way... perhaps anal would be a better description.

stanl
05-28-2010, 05:13 PM
So don't you think if you were working for someone who said you can't use that style, you had to use o_var as an example, would be showing a scary degree of inflexibility?

Those people get charged by the hour, not by the line:devil2: