GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 25-Feb-2004, 13:30
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,432
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all
Post

Re: Naming Conventions


I just posted a GID Community blog entitled: Naming Conventions.

Quote:
NAMING CONVENTIONS

Definitely a matter of choice, I will outline various ideas for naming variables, functions, and the like for ease of readability. Let's tackle the obvious one first: read more...

Please let me know what you think.

This is an auto-generated message posted by GIDNetwork™ on behalf of the author.
  #2  
Old 29-Feb-2004, 16:44
dsmith's Avatar
dsmith dsmith is offline
Senior Member
 
Join Date: Jan 2004
Location: Utah, USA
Posts: 1,351
dsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of light
I wanted to add one thing to the end of Walts excellent tutorial on variable names.

#3) Be consistent.

While I feel that it is important to consistantly code with the same naming convention once you find one that works for you, it is even more crucial in a project to be consistent with a naming convention.

At times you will have to work on a project that has already been started with a differing naming convention than what you would choose. If you have to maintain code that is not yours, keep the naming conventions that were originally started.
Last edited by admin : 23-Oct-2005 at 09:58. Reason: Split discussion into it's own thread.
  #3  
Old 05-Jun-2004, 05:10
BobbyMurcerFan BobbyMurcerFan is offline
Member
 
Join Date: May 2004
Posts: 103
BobbyMurcerFan is on a distinguished road

[Discussion][Tutorial] Naming Conventions


Thanks. This is helpful. I've settled in on using a single letter to indicate a variable's type. But I'm differentiating strings from char by using s for strings, which means I'm using h for short. But I really never use short anyway.

Thanks again.
Last edited by admin : 23-Oct-2005 at 09:57. Reason: Inserted link/reference to original thread
  #4  
Old 05-Jun-2004, 09:31
aaroncohn's Avatar
aaroncohn aaroncohn is offline
Regular Member
 
Join Date: Feb 2004
Location: Bay Area, CA.
Posts: 570
aaroncohn is a jewel in the roughaaroncohn is a jewel in the roughaaroncohn is a jewel in the rough
These two comments should be moved...

As far as using a single letter before your variable name to denote the type... it's a good idea, however it's not very useful except in very large programs with a lot of different data types where another programmer is going to be reading your code. I've tried this method as well, and it just makes the code ugly and actually more difficult to read. There's also the problem with data types that use the same prefix. Anyway, you can do what you want, but if you're just coding simple programs right now, it's really more of a hassle to use prefixes, and it doesn't make understanding any easier.
__________________
-Aaron
  #5  
Old 06-Jun-2004, 18:07
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,432
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all
Quote:
Originally Posted by aaroncohn
These two comments should be moved...

As far as using a single letter before your variable name to denote the type... it's a good idea, however it's not very useful except in very large programs with a lot of different data types where another programmer is going to be reading your code. I've tried this method as well, and it just makes the code ugly and actually more difficult to read. There's also the problem with data types that use the same prefix. Anyway, you can do what you want, but if you're just coding simple programs right now, it's really more of a hassle to use prefixes, and it doesn't make understanding any easier.
That may be true for small programs, but IMO if you develop a habit that will help programming large programs, by all means use that same technique for your small programs. It keeps consitancy throughout all your code. As you get comfortable with the style the prefixes don't get in the way.

Otherwise you learn to program with multiple styles, for small, medium, large programs.

Try your way for a while and see if the prefixes help or hinder on your small programs, then decide whether to adopt or toss the idea. It certainly doesn't hurt to experiment at the beginning.
__________________

Definition: Politics
Latin, from
poly meaning many and
tics meaning blood sucking parasites
-- Tom Smothers
  #6  
Old 06-Jun-2004, 19:47
aaroncohn's Avatar
aaroncohn aaroncohn is offline
Regular Member
 
Join Date: Feb 2004
Location: Bay Area, CA.
Posts: 570
aaroncohn is a jewel in the roughaaroncohn is a jewel in the roughaaroncohn is a jewel in the rough
Well, honestly, I think that if you give your variables good names, prefixes are not necessary. I can always find a name that makes sense for a variable in relation to it's data-type, and I never have problems remember what the data-type of the variable is, because its name, as well as the context in which I find it, will tell me what type of variable it is without using an ugly little prefix :-P
__________________
-Aaron
  #7  
Old 06-Jun-2004, 20:12
Max Payne's Avatar
Max Payne Max Payne is offline
Regular Member
 
Join Date: Apr 2004
Location: 3° 08 North 101° 42 East
Posts: 332
Max Payne is a jewel in the roughMax Payne is a jewel in the roughMax Payne is a jewel in the rough
Hmm for me, using prefix is a good way to differentiate your variables, even for small problems. If you are familiar with MFC, it actually would need you to use the prefix in naming your variable, then you could differentiate if its a classobject or a data type.

anyway, it all depends on ones preferblity.
__________________
When you say "I wrote a program that crashed Windows," people just stare at you blankly and say "Hey, I got those with the system, for free." Linus Torvalds
  #8  
Old 06-Jun-2004, 20:32
aaroncohn's Avatar
aaroncohn aaroncohn is offline
Regular Member
 
Join Date: Feb 2004
Location: Bay Area, CA.
Posts: 570
aaroncohn is a jewel in the roughaaroncohn is a jewel in the roughaaroncohn is a jewel in the rough
Well, it also depends on ease of understanding. When I read microsoft's code and see a bunch of prefixes, I have no idea what they mean. It's impossible to understand someone else's prefixes (unless they're totally standardized, which they aren't, except for maybe hungarian notation) unless you have some kind of legend to use as a reference.
__________________
-Aaron
  #9  
Old 06-Jun-2004, 22:22
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,432
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all
Quote:
Originally Posted by aaroncohn
Well, it also depends on ease of understanding. When I read microsoft's code and see a bunch of prefixes, I have no idea what they mean. It's impossible to understand someone else's prefixes (unless they're totally standardized, which they aren't, except for maybe hungarian notation) unless you have some kind of legend to use as a reference.
That's because you're not familiar with the prefixes

Bottom line here is we are all correct. Yes you can name variables well, but that doesn't necessarily help you with the type. And using the prefix to denote the type can help obscure the 'name' of the variable.

It's all a matter of style.
__________________

Definition: Politics
Latin, from
poly meaning many and
tics meaning blood sucking parasites
-- Tom Smothers
 
 

Recent GIDBlogConfiguring iptables for Webmin Servers Index Module by gidnetwork

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Style Guide Books?? BobbyMurcerFan C++ Forum 4 16-May-2004 13:19

Network Sites: GIDNetwork · GIDApp · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 06:23.


vBulletin, Copyright © 2000 - 2013, Jelsoft Enterprises Ltd.