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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
10-29-2003, 01:54 PM
|
#1
|
Senior Member
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,203
Rep:
|
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
|
|
|
10-29-2003, 02:12 PM
|
#2
|
Member
Registered: May 2002
Posts: 964
Rep:
|
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.
|
|
|
10-29-2003, 02:28 PM
|
#3
|
Senior Member
Registered: Nov 2002
Location: Silly Con Valley
Distribution: Red Hat 7.3, Red Hat 9.0
Posts: 2,054
Rep:
|
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.
|
|
|
|
10-29-2003, 03:03 PM
|
#4
|
Member
Registered: May 2002
Posts: 964
Rep:
|
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.
|
|
|
10-29-2003, 06:15 PM
|
#5
|
Senior Member
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,203
Original Poster
Rep:
|
Xm...thx gyus....My problem depenends on namin attributes of data bases and not for c. So did u have something for db?
|
|
|
10-29-2003, 06:50 PM
|
#6
|
Senior Member
Registered: Nov 2002
Location: Silly Con Valley
Distribution: Red Hat 7.3, Red Hat 9.0
Posts: 2,054
Rep:
|
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.
|
|
|
All times are GMT -5. The time now is 03:20 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|