Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C > Naming question
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 4 Topic 25224 of 27317
Post > Topic >>

Naming question

by evanevankan2@[EMAIL PROTECTED] Mar 31, 2008 at 06:59 PM

Lets say I have an example structure like this

struct day {
    /* Data goes here */
};

and in my program I work with an array of structs of that type.

Example:

int main(void)
{
    struct day *day;
    int count;

    /* Allocation of struct goes here. */

    do_stuff_on_array(day, count);
    do_stuff_on_day(day);

    return 0;
}

void do_stuff_on_array(struct day *day, int count)
{
    int i;
    for (i = 0; i < count; i++) {
        /* Do stuff on day[i] */
    }
}

void do_stuff_on_array(struct day *day)
{
    /* Do stuff on *day */
}

Now my question is just about the names. I always try to make up
the best describing names for my variables and structs, but I have
problems on which conventions I should use. I ended up with
the same name for both the variable and struct, that is 'day'.
So I write: struct day *day;
I know it works perfectly well because of different namespaces.
But is that a bad idea, would you say it is confusing to have the
same name?

Then the next question. The first parameter of the two functions
are idential, and I choose the same naming here too:
struct day *day
But the functions work on different things, the first one on
a whole array while the second only on an element.
Should I use some different naming here for the two functions
to indicate that they don't handle the argument in the same way,
in order to not confuse people who read my code?

Grateful for any opinions!
Thanks
 




 4 Posts in Topic:
Naming question
evanevankan2@[EMAIL PROTE  2008-03-31 18:59:04 
Re: Naming question
user923005 <dcorbit@[E  2008-03-31 20:45:07 
Re: Naming question
Ben Pfaff <blp@[EMAIL   2008-03-31 22:46:26 
Re: Naming question
Gregory Pietsch <GKP1@  2008-04-02 20:08:52 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu Sep 4 23:54:49 CDT 2008.