General rules on interface (function) design



Could you talk something about the general rules on the interface
(function) design in C program that recognized publically? Or introduce
some good advice of yourself.

How do you think about some of those advices like following?

a. keep the interface clean and clear (What does clean or clear mean
and how to achieve that?).
b. avoid using static variables in local function if possible.
c. avoid using global variables for local function if possible.
d. avoid allocating dynamic memory in local function if possible.
....

And I write following the function to convert an integer to a string.
Your advices are welcome and appreciated.

Requirement: convert an integer to character string, put one blank char
among the string, for example: "1 2 3 4 0 9" for 123409.

/* s : hold the string presentation of an integer.
* num : an integer is to be gotten its string presentation.
*/
void itoa2(char *s, int num)
{
int len = 100;
char s1[len]; /* C99 features involved */
sprintf(s1, "%d", num);
int i = 0, j = 0;
for (i = 0; s1[i]; ++i, ++j)
{
s[j] = s1[i];
s[++j] = ' ';
}
s[--j] = '\0';
}

How do you think about following choices of different interface design:

/* #2 self-contained or self-sufficient */
void itoa2(char *s, int num);

/* #3 global or static variables or dynamic memory may be required */
void itoa3(int num);
--
lovecreatesbeauty

.



Relevant Pages

  • Re: When is a function not a function?
    ... a DOM element and Array or a value with falseness. ... betrays very poor code design. ... subject of the test is expected to be any of a javascript function ... There is nothing to say that an object implementing the Node interface should not be a function object. ...
    (comp.lang.javascript)
  • Re: XP Requirement Analysis?
    ... and use TDD to force the same design to emerge. ... > These principles, used with other XP situations like pair programming, ... OK, but you need to know what that interface is, so you must do some ... to buy a business value. ...
    (comp.object)
  • Re: New to JUnit... Eclipse Question
    ... You create the interface to get the caller to compile then you have to write the implementation to get it to pass. ... I've argued before with someone claimed that according to YAGNI you would never create an interface until you have two classes that would implement the interface. ... its not a license for being dumb or lazy and making stupid design choices - see the end of this email for an account of when it did happen on one of my previous teams. ... So there are many good reasons for using interfaces even if you don't have a bona fide "need" yet. ...
    (comp.lang.java.programmer)
  • Re: OO applications (2)
    ... >> Thanks Alex for mentioning minimal interface; it is a more focussed expression ... >> 4) Is a desirable first step for any software design task. ... Imagine these steps are consecutive segments of a circle. ...
    (comp.os.os2.programmer.misc)
  • Re: Questions for DesginersArchiects
    ... I am familiar with the design you mention, I suppose I would just love to ... business classes might help to connect the data in the database with the ... a change is necessary in either the interface or the data? ... ..Net Developer ...
    (microsoft.public.dotnet.framework.aspnet)

Loading