Logo

Code Conventions

General Issues
  1. Avoid using code formatting (beautifier) tools
  2. Use spaces and never tab characters
  3. Indent code by 4 spaces (editors offer to set the TAB key to 4 spaces)
  4. Make use of spaces and white lines to separate code logically
  5. Comment all code exhaustively
CYBOL (XML)
  1. Write files that are valid according to the CYBOL DTD
CYBOI (C)
  1. Document each procedure (functionality, parameters) in javadoc style
  2. Use only procedures, no functions -- in other words: no return values besides void
  3. Hand over all parameters as void pointer being a reference to their value
  4. Make unchangeable parameters constant
  5. Only use arrays together with their size and element count; never use null-terminated strings
  6. Put the opening brackets to the end of a line, not on an extra line
  7. Check pointers for null before accessing them
  8. Define all standard strings such as log messages as constant character array
  9. Use only if-else conditions, never case statements
  10. Use only while loops, never do-while or for loops
  11. Use only endless loops and place the loop condition inside the loop
  12. Example:
    /**
     * This is an example procedure.
     * It does nothing.
     *
     * @param p0 the first parameter is an integer
     * @param p1 the second parameter is a character
     * @param p2 the third parameter is a pointer, for example a char pointer (string)
     */
    void example_procedure(void* p0, void* p1, const void* p2) {
    
        if (p2 != NULL_POINTER) {
    
            // Cast void pointer parameter to its actual type.
            char** s = (char**) p2;
    
            // Use the string by dereferencing s.
            // This value was handed over as constant parameter and cannot be changed.
            fprintf(stdout, "The string value is: %s\n", *s);
    
            if (p1 != NULL_POINTER) {
    
                // Cast void pointer parameter to its actual type.
                char* c = (char*) p1;
    
                // Use the character by dereferencing c.
                *c = 32;
    
                if (p0 != NULL_POINTER) {
    
                    // Cast void pointer parameter to its actual type.
                    int* i = (int*) p0;
    
                    // Use the integer by dereferencing i.
                    *i = *i + 10;
    
                    // An example loop.
                    int j = 0;
    
                    while (1) {
    
                        if (j >= 10) {
    
                            break;
                        }
    
                        j++;
                    }
    
                } else {
    
                    log_message((void*) &ERROR_LOG_LEVEL, (void*) &P0_IS_NULL_MESSAGE, (void*) &P0_IS_NULL_MESSAGE_COUNT);
                }
    
            } else {
    
                log_message((void*) &ERROR_LOG_LEVEL, (void*) &P1_IS_NULL_MESSAGE, (void*) &P1_IS_NULL_MESSAGE_COUNT);
            }
    
        } else {
    
            log_message((void*) &ERROR_LOG_LEVEL, (void*) &P2_IS_NULL_MESSAGE, (void*) &P2_IS_NULL_MESSAGE_COUNT);
        }
    }
                        


Copyright (c) 2002-2004. The CYBOP Webmasters. All rights reserved. GNU FDL license. Last Update: 2004-08-09