LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > General
User Name
Password
General NOTE: The general forum has been closed to new posts while we evaluate moderator availability. This forum is for non-technical general discussion which can include both Linux and non-Linux topics. Have fun!

Notices


 
  Search this Thread
Old 10-29-2003, 01:54 PM   #1
alaios
Senior Member
 
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,203

Rep: Reputation: 45
Name the attributes


Hi there I want to know if there are rules likes these in c++ programming.
I am trying to find a simple way for naming the attributes of a table with a common way.
For example i have the attribute
Yahoo messenger id.
What u will select as for name?
Ymessenger
YM
Yahoo_messenger
Ymessenger
etc...........
Do u know a "technique" in order to help me take a right decision?
Thx
 
Old 10-29-2003, 02:12 PM   #2
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
Rules? Not really.

Good practice - yes.

Consider using a notation system that tells you what the class, object or variable is and what it does.

Consider, for example -

prefix = the datatype like sz, ch, int, lng... etc.
thing it references = Yahootbl, filenameVector, etc.

szFileNameRope - tells you exactly what you've got. This one doesn't make a lot of sense necessarily, but in context it might.
clsMyFileClass, etc.

This one is a simplified Hungarian notation. IT may not be what you need, but you can find one or build one that fits your needs.
 
Old 10-29-2003, 02:28 PM   #3
megaspaz
Senior Member
 
Registered: Nov 2002
Location: Silly Con Valley
Distribution: Red Hat 7.3, Red Hat 9.0
Posts: 2,054

Rep: Reputation: 46
i always thought the coding style text file was amusing. usually found in /usr/src/your_kernel_version/Documentation.

Quote:
Chapter 3: Naming

C is a Spartan language, and so should your naming be. Unlike Modula-2
and Pascal programmers, C programmers do not use cute names like
ThisVariableIsATemporaryCounter. A C programmer would call that
variable "tmp", which is much easier to write, and not the least more
difficult to understand.

HOWEVER, while mixed-case names are frowned upon, descriptive names for
global variables are a must. To call a global function "foo" is a
shooting offense.

GLOBAL variables (to be used only if you _really_ need them) need to
have descriptive names, as do global functions. If you have a function
that counts the number of active users, you should call that
"count_active_users()" or similar, you should _not_ call it "cntusr()".

Encoding the type of a function into the name (so-called Hungarian
notation) is brain damaged - the compiler knows the types anyway and can
check those, and it only confuses the programmer. No wonder MicroSoft
makes buggy programs.

LOCAL variable names should be short, and to the point. If you have
some random integer loop counter, it should probably be called "i".
Calling it "loop_counter" is non-productive, if there is no chance of it
being mis-understood. Similarly, "tmp" can be just about any type of
variable that is used to hold a temporary value.

If you are afraid to mix up your local variable names, you have another
problem, which is called the function-growth-hormone-imbalance syndrome.
See next chapter.
 
Old 10-29-2003, 03:03 PM   #4
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
I've coded in C since 1979 - and that is amusing.

We have rules here about how variables get named.
The reason is that most modules usually have several hundred data entities they are piddling around with. For our
database code, variables are named after the table and column they come from or are aimed at - uabopen_billed_chg.

I am working on two co-modules (with sub modules) that are 62500 lines of code, with 750+ data items, not including control variables. Using any method other than something like what we have would render the code absolutely unmaintainable.

And it lints clean, BTW.
 
Old 10-29-2003, 06:15 PM   #5
alaios
Senior Member
 
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,203

Original Poster
Rep: Reputation: 45
Xm...thx gyus....My problem depenends on namin attributes of data bases and not for c. So did u have something for db?
 
Old 10-29-2003, 06:50 PM   #6
megaspaz
Senior Member
 
Registered: Nov 2002
Location: Silly Con Valley
Distribution: Red Hat 7.3, Red Hat 9.0
Posts: 2,054

Rep: Reputation: 46
i don't think there's a difference between naming database attributes and naming variables/functions/structs/classes/etc. in c/c++ or any language. just make sure your name is descriptive by either using hungarian notation or some other naming convention. just be consistent. although variables named "i", while acceptable for loop counters, are not acceptable for other naming situations. use your judgement and be consistent with it.
 
  


 


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Attributes - color satimis Linux - General 2 03-22-2005 10:39 PM
Kdesktop attributes rogere Linux - Software 0 12-15-2004 08:10 PM
Python and instance attributes clausawits Programming 2 12-08-2004 10:17 AM
thread attributes iftiuk Programming 2 07-29-2004 01:41 PM
file attributes binky22 Linux - Newbie 2 09-26-2003 04:17 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > General

All times are GMT -5. The time now is 03:20 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration