Design Principles, Best Practices and Design Patterns for C (or Procedural Programming in general)? [closed]

Information hiding – as espoused by Parnas (Software Fundamentals).

Careful management of headers and visibility:

  • Everything in a source file that can be hidden from the outside world should be; only the documented external interface should be exposed.
  • Everything that is exposed is declared in a header.
  • That header is used where the functionality is needed (and where it is defined).
  • The header is self-contained – when you need it, you use it, and you don’t have to fret about ‘what other headers do I also have to include’ because the header ensures it works by including anything it needs to make it work.
  • The header is self-protected – so it does not matter if it is included multiple times.

    #ifndef HEADER_H_INCLUDED
    #define HEADER_H_INCLUDED
    ...rest of header contents, including other #include lines if necessary
    #endif /* HEADER_H_INCLUDED */
    
  • Design sets of functions to work on ‘objects’ (usually structures) – and use those functions rather than poking around the innards of the structure in the code that is using it. Think of it as self-imposed encapsulation.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)