Is it normal to indicate to a function that modifies (increases or decreases) a value by a flag?


This is merely a design tip I'm looking for. I have a function that has some procedure before it could increase or decrease a value. Should I make separate functions or just one function and pass in the flag to indicate whether it increases or decreases a value?


void increment_xxx_counter(some arg)
void decrement_xxx_counter(some arg)


void modify_xxx_counter(some arg, bool flag)

I'd start by looking to the other interfaces used in your application. If there's a similar "modify" function, I'd design this function to match that in a way that makes sense. Otherwise, if I felt a function was needed, I might use the single-function approach:

    xxx_inc(some *arg, int value);

This way, it's easier to understand what is going on by reading the code. For example:

    timer_inc(&t, 1);
    timer_inc(&t, -1);
    timer_thing_inc(&t, 1);
    timer_thing_inc(&t, -1);

Instead of the less obvious:

    timer_modify_thing(%t, true);