### ACE Software Development Guidelines

- General

  - Every text file must end with a newline.

  - Use spaces instead of tabs, except in Makefiles. Emacs users can add this to their .emacs:

        (setq-default indent-tabs-mode nil)

    Microsoft Visual C++ users should do the following:

                Choose:  Tools -- Options -- Tabs
                Then Set:  "Tab size" to 8 and "Indent size" to 2, and
                indent using spaces.

  - Do not end text lines with spaces. Emacs users can add this to their .emacs:

        (setq-default nuke-trailing-whitespace-p t)

  - Try to limit the length of source code lines to less than 80 characters. Users with 14 inch monitors appreciate it when reading code. And, it avoids mangling problems with email and net news.

  - If you add a comment to code that is directed to, or requires the attention of, a particular individual: SEND EMAIL TO THAT INDIVIDUAL!.

  - Every program should have a ``usage'' message. It should be printed out if erroneous command line arguments, or a `-?` command line argument, are provided to the program.

  - A program entry poing `main` can take any of the three forms:

                int main (int argc, char *argv[])
                int wmain (int argc, wchar_t *argv[])
                int ACE_TMAIN (int argc, ACE_TCHAR *argv[])

    Of them, the entry point `main` always gives you the command line arguemnt in char strings form. The entry point `wmain` currently can only be used under Win32 and it returns the command line arguments in wchar strings format. Defining the `ACE_TMAIN` as the program entry point is the more portable form. The command line arguments are given in char strings in most cases, or wchar strings when `ACE_USES_WCHAR` is defined. See `$ACE_ROOT/docs/wchar.txt` for more information on ACE support on wchar.
  - The program entry point function, in any form mentioned above, must always be declared with arguments, e.g.,

                int
                ACE_TMAIN (int argc, ACE_TCHAR *argv[])
                {
                  [...]

                  return 0;
                }

    If you don't use the `argc` and/or `argv` arguments, don't declare them, e.g.,

                int
                ACE_TMAIN (int, ACE_TCHAR *[])
                {
                  [...]

                  return 0;
                }

    Please declare the second argument as `ACE_TCHAR *[]` instead of `ACE_TCHAR **` or `char *[]`. Ancient versions of MSC complained about `ACE_TCHAR **` and `char *[]` is not Unicode-compliant.

    `main` must also return 0 on successful termination, and non-zero otherwise.

  - Avoid use of floating point types (float and double) and operations unless absolutely necessary. Not all ACE platforms support them. Therefore, wherever they are used, ACE_LACKS_FLOATING_POINT conditional code must be also be used.

  - Avoid including the string ``Error'' in a source code filename. GNU Make's error messages start with ``Error''. So, it's much easier to search for errors if filenames don't contain ``Error''.

  - Narrow interfaces are better than wide interfaces. If there isn't a need for an interface, leave it out. This eases maintenance, minimizes footprint, and reduces the likelihood of interference when other interfaces need to be added later. (See the ACE_Time_Value example below.

- Code Documentation

  - Use comments and whitespace (:-) liberally. Comments should consist of complete sentences, i.e., start with a capital letter and end with a period.

  - Insert a CVS/RCS keyword string at the top of every source file, Makefile, config file, etc. For C++ files, it is:

                // $Id$

    It is not necessary to fill in the fields of the keyword string, or modify them when you edit a file that already has one. CVS does that automatically when you checkout or update the file.

    To insert that string at the top of a file:

                perl -pi -e \
                  'if (! $o) {printf "// \$Id\$\n\n";}; $o = 1;' file

  - Be sure to follow the guidelines and restrictions for use of the ACE documentation tools, notably for header files.

  - One example of such guidelines is that comments, especially in header files, must follow the Doxygen format requirements. The complete documentation for Doxygen is available in the Doxygen manual.
    For an example header file using Doxygen-style comments, please refer to ACE.h.

- Preprocessor

  - Never #include standard headers directly, except in a few specific ACE files, e.g., OS.h and stdcpp.h. Let those files #include the correct headers. If you do not do this, your code will not compile with the Standard C++ Library.

  - Always follow a preprocessor `#endif` with a `/* */` C-style comment. It should correspond to the condition in the matching `#if` directive. For example,

                #if defined (ACE_HAS_THREADS)
                # if defined (ACE_HAS_STHREADS)
                #   include /**/ <synch.h>
                #   include /**/ <thread.h>
                #   define ACE_SCOPE_PROCESS P_PID
                #   define ACE_SCOPE_LWP P_LWPID
                #   define ACE_SCOPE_THREAD (ACE_SCOPE_LWP + 1)
                # else
                #   define ACE_SCOPE_PROCESS 0
                #   define ACE_SCOPE_LWP 1
                #   define ACE_SCOPE_THREAD 2
                # endif /* ACE_HAS_STHREADS */
                #endif /* ACE_HAS_THREADS */

  - Be sure to put spaces around comment delimiters, e.g., `char * /* foo */` instead of `char */*foo*/`. MS VC++ complains otherwise.

  - Always insert a `/**/` between an `#include` and `filename`, as shown in the above example. This avoids dependency problems with Visual C++.

  - Be very careful with names of macros, enum values, and variables It's always best to prefix them with something like `ACE_` or `TAO_`. There are too many system headers out there that #define `OK`, `SUCCESS`, `ERROR`, `index`, `s_type`, and so on.

  - When using macros in an arithmetic expression, be sure to test that the macro is defined, using defined(macro) before specifying the expression. For example:

        #if __FreeBSD__ < 3

    will evaluate true on any platform where __FreeBSD__ is not defined. The correct way to write that guard is:

        #if defined (__FreeBSD__)  &&  __FreeBSD__ < 3

  - Try to centralize `#ifdefs` with `typedefs` and `#defines`. For example, use this:

                #if defined(ACE_PSOS)
                  typedef long ACE_NETIF_TYPE;
                # define ACE_DEFAULT_NETIF 0
                #else  /* ! ACE_PSOS */
                  typedef const TCHAR* ACE_NETIF_TYPE;
                # define ACE_DEFAULT_NETIF ASYS_TEXT("le0")
                #endif /* ! ACE_PSOS */

    instead of:

                #if defined (ACE_PSOS)
                  // pSOS supports numbers, not names for network interfaces
                  long net_if,
                #else  /* ! ACE_PSOS */
                  const TCHAR *net_if,
                #endif /* ! ACE_PSOS */

  - Protect header files against multiple inclusion with this construct:

                #ifndef FOO_H
                #define FOO_H

                [contents of header file]

                #endif /* FOO_H */

    This exact construct (note the `#ifndef`) is optimized by many compilers such they only open the file once per compilation unit. Thanks to Eric C. Newton <ecn@smart.net> for pointing that out.

    If the header `#includes` an ACE library header, then it's a good idea to include the `#pragma once` directive:

                #ifndef FOO_H
                #define FOO_H

                #include "ace/ACE.h"
                #if !defined (ACE_LACKS_PRAGMA_ONCE)
                # pragma once
                #endif /* ACE_LACKS_PRAGMA_ONCE */

                [contents of header file]

                #endif /* FOO_H */

    `#pragma once` must be protected, because some compilers complain about it. The protection depends on `ACE_LACKS_PRAGMA_ONCE`, which is defined in some ACE config headers. Therefore, the protected `#pragma once` construct should only be used after an `#include` of an ACE library header. Note that many compilers enable the optimization if the `#ifndef` protection construct is used, so for them, `#pragma once` is superfluous.

    No code can appear after the final `#endif` for the optimization to be effective and correct.

  - Files that contain parametric classes should follow this style:

              #ifndef FOO_T_H
              #define FOO_T_H

              #include "ace/ACE.h"
              #if !defined (ACE_LACKS_PRAGMA_ONCE)
              # pragma once
              #endif /* ACE_LACKS_PRAGMA_ONCE */

              // Put your template declarations here...

              #if defined (__ACE_INLINE__)
              #include "Foo_T.i"
              #endif /* __ACE_INLINE__ */

              #if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
              #include "Foo_T.cpp"
              #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */

              #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
              #pragma implementation "Foo_T.cpp"
              #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */

              #endif /* FOO_T_H */

    Notice that some compilers need to see the code of the template, hence the `.cpp` file must be included from the header file.

    To avoid multiple inclusions of the `.cpp` file it should also be protected as in:

              #ifndef FOO_T_C
              #define FOO_T_C

              #include "Foo_T.h"
              #if !defined (ACE_LACKS_PRAGMA_ONCE)
              # pragma once
              #endif /* ACE_LACKS_PRAGMA_ONCE */

              #if !defined (__ACE_INLINE__)
              #include "ace/Foo_T.i"
              #endif /* __ACE_INLINE__ */

              ACE_RCSID(lib, Foo_T, "$Id$")

              // put your template code here

              #endif /* FOO_T_H */

    Finally, you may want to include the template header file from a non-template header file (check `$ACE_ROOT/ace/Synch.h`); in such a case the template header should be included after the inline function definitions, as in:

              #ifndef FOO_H
              #define FOO_H

              #include "ace/ACE.h"
              #if !defined (ACE_LACKS_PRAGMA_ONCE)
              # pragma once
              #endif /* ACE_LACKS_PRAGMA_ONCE */

              // Put your non-template declarations here...

              #if defined (__ACE_INLINE__)
              #include "Foo.i"
              #endif /* __ACE_INLINE__ */

              #include "Foo_T.h"

              #endif /* FOO_H */

  - Avoid `#include <math.h>` if at all possible. The `/usr/include/math.h` on SunOS 5.5.1 through 5.7 defines a struct name exception, which complicates use of exceptions.

  - On a `.cpp` file always include the corresponding header file first, like this:

                // This is Foo.cpp

                #include "Foo.h"
                #include "tao/Bar.h"
                #include "ace/Baz.h"

                // Here comes the Foo.cpp code....

    In this way we are sure that the header file is self-contained and can be safely included from some place else.

  - In the TAO library never include `<corba.h>`, this file should only be included by the user and introduces cyclic dependencies in the library that we must avoid.

  - Never include a header file when a forward reference will do, remember that templates can be forward referenced too. Consult your favorite C++ book to find out when you must include the full class definition.

- C++ Syntax and Constructs

  - `for` loops should look like:

                for (u_int i = 0; i < count; ++i)
                  ++total;

    Though, I prefer to always wrap the body of the loop in braces, to avoid surprises when other code or debugging statements are added, and to maintain sanity when the body consists of a macro, such as an ACE_ASSERT without a trailing semicolon:

                for (u_int i = 0; i < count; ++i)
                  {
                    ACE_ASSERT (++total < UINT_MAX;)
                  }

    Similarly, `if` statements should have a space after the ``if'', and no spaces just after the opening parenthesis and just before the closing parenthesis.

  - If a loop index is used after the body of the loop, it must be declared before the loop. For example,

                size_t i = 0;
                for (size_t j = 0; file_name [j] != '\0'; ++i, ++j)
                  {
                    if (file_name [j] == '\\' && file_name [j + 1] == '\\')
                      ++j;

                    file_name [i] = file_name [j];
                  }

                // Terminate this string.
                file_name [i] = '\0';

  - Prefix operators are sometimes more efficient than postfix operators. Therefore, they are preferred over their postfix counterparts where the expression value is not used.

    Therefore, use this idiom for iterators, with prefix operator on the loop index:

               ACE_Ordered_MultiSet<int> set;
               ACE_Ordered_MultiSet_Iterator<int> iter(set);

               for (i = -10; i < 10; ++i)
                 set.insert (2 * i + 1);

    rather than the postfix operator:

               for (i = -10; i < 10; i++)
                 set.insert (2 * i + 1);

  - Prefer using `if (...) else ....` instead of `?:` operator. It is a lot less error prone, and will help you avoid bugs caused due to the precedence of `?:` , compared with other operators in an expression.
  - When a class provides operator==, it must also provide operator!=. Also, both these operators must be const.
  - Avoid unnecessary parenthesis. We're not writing Lisp :-)

  - Put inline member functions in a `.i` file. That file is conditionally included by both the `.h` file, for example:

                    class ACE_Export ACE_High_Res_Timer
                    {
                      [...]
                    };

                    #if defined (__ACE_INLINE__)
                    #include "ace/High_Res_Timer.i"
                    #endif /* __ACE_INLINE__ */

    and `.cpp` file:

                    #define ACE_BUILD_DLL
                    #include "ace/High_Res_Timer.h"

                    #if !defined (__ACE_INLINE__)
                    #include "ace/High_Res_Timer.i"
                    #endif /* __ACE_INLINE__ */

                    ACE_ALLOC_HOOK_DEFINE(ACE_High_Res_Timer)

    NOTE: It is very important to ensure than an inline function will not be used before its definition is seen. Therefore, the inline functions in the .i file should be arranged properly. Some compilers, such as `g++` with the `-Wall` option, will issue warnings for violations.

  - Some inlining heuristics:

    - One liners should almost always be inline, as in:

          ACE_INLINE
          Foo::bar ()
          {
            this->baz();
          }

    - The notable exception is virtual functions, which should never be inlined.

    - Big (more than 10 lines) and complex function (more than one if () statement, or a switch, or a loop) should not be inlined.

    - Medium sized stuff depends on how performance critical it is. If you know that it's in the critical path, then make it inline.

  - `ACE_Export` must be inserted between the `class` keyword and class name for all classes that are exported from libraries, as shown in the example above. However, do not use `ACE_Export` for template classes!

  - Mutators and accessors should be of this form:

                void object_addr (const ACE_INET_Addr &);
                // Sets <object_addr_> cache from <host> and <port>.

                const ACE_INET_Addr &object_addr const (void);
                // Returns the <ACE_INET_Addr> for this profile.

    instead of the ``set_'' and ``get_'' form.

  - Never use `delete` to deallocate memory that was allocated with `malloc`. Similarly, never associate `free` with `new`. `ACE_NEW` or `ACE_NEW_RETURN` should be used to allocate memory, and `delete` should be used to deallocate it. And be careful to use the correct form, `delete` or `delete []` to correspond to the allocation.

  - Don't check for a pointer being 0 before deleting it. It's always safe to delete a 0 pointer. If the pointer is visible outside the local scope, it's often a good idea to 0 it _after_ deleting it. Note, the same argument applies to free().

  - Always use `ACE_NEW` or `ACE_NEW_RETURN` to allocate memory, because they check for successful allocation and set errno appropriately if it fails.

  - Never compare or assign a pointer value with NULL; use 0 instead. The language allows any pointer to be compared or assigned with 0. The definition of NULL is implementation dependent, so it is difficult to use portably without casting.

  - Never use TRUE, true, or anything else other than 1 to indicate true. Never use FALSE, false, or anything else other than 0 to indicate false.

  - Never cast a pointer to or from an `int`. On all currently supported ACE platforms, it is safe to cast a pointer to or from a `long`.

  - Be very careful when selecting an integer type that must be a certain size, e.g., 4 bytes. long is not 4 bytes on all platforms; it is 8 bytes on many 64-bit machines. ACE_UINT32 is always 4 bytes, and ACE_UINT64 is always 8 bytes.

  - If a class has any virtual functions, and its destructor is declared explicitly in the class, then the destructor should always be virtual as well. And to support compiler activities such as generation of virtual tables and, in some cases, template instantiation, the virtual destructor should not be inline. (Actually, any non-pure virtual function could be made non-inline for this purpose. But, for convenience, if its performance is not critical, it is usually easiest just to make the virtual destructor non-inline.)

  - Avoid default arguments unless there's a good reason. For an example of how they got us into a jam is:

                ACE_Time_Value (long sec, long usec = 0);

    So, `ACE_Time_Value (2.5)` has the unfortunate effect of coercing the 2.5 to a long with value 2. That's probably not what the programmer intended, and many compilers don't warn about it.

    A nice fix would be to add an `ACE_Time_Value (double)` constructor. But, that would cause ambiguous overloading due to the default value for the second argument of `ACE_Time_Value (long sec, long usec = 0)`. We're stuck with `ACE_Time_Value`, but now we know that it's easy to avoid.

  - Constructor initializers must appear in the same order as the data members are declared in the class header. This avoids subtle errors, because initialization takes place in the order of member declaration.

  - Initialization is usually cleaner than assignment, especially in a conditional. So, instead of writing code like this:

                ssize_t n_bytes;

                // Send multicast of one byte, enough to wake up server.
                if ((n_bytes = multicast.send ((char *) &reply_port,
                  sizeof reply_port)) == -1)

    Write it like this:

                ssize_t n_bytes = multicast.send ((char *) &reply_port,
                  sizeof reply_port)

                // Send multicast of one byte, enough to wake up server.
                if (n_bytes == -1)

    But, beware if the initialization is of a static variable. A static variable is only initialized the first time its declaration is seen. Of course, we should avoid using static variables at all.

  - It is usually clearer to write conditionals that have both branches without a negated condition. For example,

                if (test)
                  {
                    // true branch
                  }
                else
                  {
                    // false branch
                  }

    is preferred over:

                if (! test)
                  {
                    // false test branch
                  }
                else
                  {
                    // true test branch
                  }

  - If a cast is necessary, avoid use of function-style casts, e.g., `int (foo)`. Instead, use one of the ACE cast macros:

                return ACE_static_cast(size_t, this->count_) > that->size_;

    The general usage guidelines for the four styles of casts are:

    - ACE_const_cast: use to cast away constness, or volatile-ness.

    - ACE_static_cast: use to cast between compatible types, such as downcasting a pointer or narrowing an integer.

    - ACE_reinterpret_cast: use only when ACE_static_cast is not suitable.

    - ACE_dynamic_cast: avoid, unless you really want to type check at run-time.

  - In general, if instances of a class should not be copied, then a private copy constructor and assignment operator should be declared for the class, but not implemented. For example:

                // Disallow copying by not implementing the following . . .
                ACE_Object_Manager (const ACE_Object_Manager &);
                ACE_Object_Manager &operator= (const ACE_Object_Manager &);

    If the class is a template class, then the `ACE_UNIMPLEMENTED_FUNC` macro should be used:

                // = Disallow copying...
                ACE_UNIMPLEMENTED_FUNC (ACE_TSS (const ACE_TSS<TYPE> &))
                ACE_UNIMPLEMENTED_FUNC (void operator= (const ACE_TSS<TYPE> &))

    `ACE_UNIMPLEMENTED_FUNC` can be used with non-template classes as well. Though for consistency and maximum safety, it should be avoided for non-template classes.

  - Never use `bool`, `BOOL`, or similar types. (CORBA::Boolean is acceptable). Use `int` or `u_int` instead for boolean types.

  - Functions should always return -1 to indicate failure, and 0 or greater to indicate success.

  - Separate the code of your templates from the code for non-parametric classes: some compilers get confused when template and non-template code is mixed in the same file.

  - It's a good idea to specify the include path (with `-I`) to include any directory which contains files with template definitions. The Compaq Tru64 cxx `-ptv` compiler option may help diagnose missing template instantiation problems.

  - When referring to member variables and functions, use `this->`member. This makes it clear to the reader that a class member is being used. It also makes it crystal clear to the compiler which variable/function you mean in cases where it might make a difference.
- I/O

  - Use `ACE_DEBUG` for printouts, and `ACE_OS::fprintf ()` for file I/O. Avoid using iostreams because of implementation differences across platforms.

  - After attempting to open an existing file, always check for success. Take appropriate action if the open failed.

  - Notice that `ACE_DEBUG` and `ACE_ERROR` don't support `%ld` of any other multicharacter format.

- WCHAR conformity

  - For ACE, use ACE_TCHAR instead of char for strings and ACE_TEXT () around string literals. Exceptions are char arrays used for data and strings that need to remain as 1 byte characters.
  - If you have a char string that needs to be converted to ACE_TCHAR, use the ACE_TEXT_CHAR_TO_TCHAR () macro. If you have a ACE_TCHAR string that needs to be converted to a char string, use the ACE_TEXT_ALWAYS_CHAR () macro
  - Do not use the Win32 TCHAR macros. The wide character-ness of ACE is separate from UNICODE and _UNICODE.
  - For TAO, don't use ACE_TCHAR or ACE_TEXT. The CORBA specification defines APIs as using char. So most of the time there is no need to use wide characters.

- Exceptions

  - There are many ways of throwing and catching exceptions. The code below gives several examples. Note that each method has different semantics and costs. Whenever possible, use the first approach.

                #include "iostream.h"

                class exe_foo
                {
                public:
                  exe_foo (int data) : data_ (data)
                    { cerr << "constructor of exception called" << endl; }
                  ~exe_foo ()
                    { cerr << "destructor of exception called" << endl; }
                  exe_foo (const exe_foo& foo) : data_ (foo.data_)
                    { cerr << "copy constructor of exception called"
                           << endl; }
                  int data_;
                };

                void
                good (int a)
                {
                  throw exe_foo (a);
                };

                void
                bad (int a)
                {
                  exe_foo foo (a);
                  throw foo;
                };

                int main ()
                {
                  cout << endl << "First exception" << endl
                       << endl;
                  try
                    {
                      good (0);
                    }
                  catch (exe_foo &foo)
                    {
                      cerr << "exception caught: " << foo.data_
                           << endl;
                    }

                  cout << endl << "Second exception" << endl
                       << endl;
                  try
                    {
                      good (0);
                    }
                  catch (exe_foo foo)
                    {
                      cerr << "exception caught: " << foo.data_
                           << endl;
                    }

                  cout << endl << "Third exception" << endl
                       << endl;
                  try
                    {
                      bad (1);
                    }
                  catch (exe_foo &foo)
                    {
                      cerr << "exception caught: " << foo.data_
                           << endl;
                    }

                  cout << endl << "Fourth exception" << endl
                       << endl;
                  try
                    {
                      bad (1);
                    }
                  catch (exe_foo foo)
                    {
                      cerr << "exception caught: " << foo.data_
                           << endl;
                    }

                  return 0;
                }

    Output is:

                First exception

                constructor of exception called
                exception caught: 0
                destructor of exception called

                Second exception

                constructor of exception called
                copy constructor of exception called
                exception caught: 0
                destructor of exception called
                destructor of exception called

                Third exception

                constructor of exception called
                copy constructor of exception called
                destructor of exception called
                exception caught: 1
                destructor of exception called

                Fourth exception

                constructor of exception called
                copy constructor of exception called
                destructor of exception called
                copy constructor of exception called
                exception caught: 1
                destructor of exception called
                destructor of exception called

- Compilation

  - Whenever you add a new test or example to ACE or TAO, make sure that you modify the Makefile or project file in the parent directory. This will make sure that your code gets compiled on a regular basis. In some cases, this also applies to MSVC project files.

### ACE Usage Guidelines

- Always use `ACE_OS` (static) member functions instead of bare OS system calls.

- As a general rule, the only functions that should go into the `ACE_OS` class are ones that have direct equivalents on some OS platform. Functions that are extensions should go in the `ACE` class.

- Use the `ACE_SYNCH_MUTEX` macro, instead of using one of the specific mutexes, such as `ACE_Thread_Mutex`. This provides portability between threaded and non-threaded platforms.

- Avoid creating a static instance of user-defined (class) type. Instead, either create it as an `ACE_Singleton`, `ACE_TSS_Singleton`, or as an `ACE_Cleanup` object. See the ACE `Singleton.h`, `Object_Manager.h`, and `Managed_Object.h` header files for more information.

  Static instances of built-in types, such as `int` or any pointer type, are fine.

  Construction of static instance of a user-defined type should never spawn threads. Because order of construction of statics across files is not defined by the language, it is usually assumed that only one thread exists during static construction. This allows statics suchs as locks to be safely created. We do not want to violate this assumption.

- Do not use run-time type identification (RTTI) directly since some platforms do not support it. Instead, use the ACE macros, e.g., `ACE_static_cast()`, `ACE_dynamic_cast()`, etc.

- Do not use C++ exception handling directly. Some platforms do not support it. And, it can impose an execution speed penalty. Instead use the TAO/ACE try/catch macros.

- Because ACE does not use exception handling, dealing with failures requires a bit of care. This is especially true in constructors. Consider the following approach:

            ACE_NEW_RETURN (this->name_space_, LOCAL_NAME_SPACE, -1);

            if (ACE_LOG_MSG->op_status () != 0)
            ....

  This snip of code is from `ACE_Naming_Context`. All failed constructors in ACE (should) call ACE_ERROR. This sets the thread-specific op_status, which can be checked by the caller. This mechanism allows the caller to check for a failed constructor without the requiring the constructor to throw exceptions.

- Another consequence of ACE's avoidance of exception handling is that you should use `open()` methods on classes that perform initializations that can fail. This is because `open()` returns an error code that's easily checked by the caller, rather than relying on constructor and thread-specific status values.

- Avoid using the C++ Standard Template Library (STL) in our applications. Some platforms do not support it yet.

- Be very careful with `ACE_ASSERT`. It must only be used to check values; it may never be used to wrap a function call, or contain any other side effect. That's because the statement will disappear when ACE_NDEBUG is enabled. For example, this code is BAD:

            ACE_ASSERT (this->next (retv) != 0);  // BAD CODE!

  Instead, the above should be coded this way:

            int result = this->next (retv);
            ACE_ASSERT (result != 0);
            ACE_UNUSED_ARG (result);

- Never put side effects in `ACE_DEBUG` code:

            ACE_DEBUG ((LM_DEBUG,
                       "handling signal: %d iterations left\n",
                       --this->iterations_));        // BAD CODE!

  Note that this won't work correctly if `ACE_NDEBUG` is defined, for the same reason that having side-effects in `ACE_ASSERT`s won't work either, i.e., because the code is removed.

- Be very careful with the code that you put in a signal handler. On Solaris, the man pages document systems calls as being Async-Signal-Safe if they can be called from signal handlers. In general, it's best to just set a flag in a signal handler and take appropriate action elsewhere. It's also best to avoid using signals, especially asynchronous signals.

- Immediately after opening a temporary file, unlink it. For example:

            ACE_HANDLE h = open the file (filename);

            ACE_OS::unlink (filename);

  This avoids leaving the temporary file even if the program crashes.

- Always use `$(RM)` instead of `rm` or `rm -f` in Makefiles.

- Be sure to specify the `THR_BOUND` thread creation flag for time-critical threads. This ensures that the thread competes for resources globally on Solaris. It is harmless on other platforms.

### Other ACE and TAO Guidelines

- When enhancing, updating, or fixing ACE or TAO, always:

  1. Test your change on at least one platform. All changes must be tested with egcs before commiting. That means you may need to test on at least two platforms.

  2. An an entry to the appropriate ChangeLog. TAO and some ACE subdirectories, such as ASNMP, JAWS, and gperf, have their own ChangeLogs. If you don't use one of those, use the ChangeLog in the top-level ACE_wrappers directory.

  3. Commit your change using a message of this form:

     `ChangeLogTag: Thu Jul 22 09:55:10 1999 David L. Levine <levine@cs.wustl.edu>`

  4. If the change is in response to a request by someone else:
     1. Make sure that person is acknowledged in ACE_wrappers/THANKS, and

     2. Respond to that person.

- Never add copyrighted, confidential, or otherwise restricted code to the ACE or TAO distributions without written permission from the owner.

### CVS Usage Guidelines

- Always make sure that a change builds and executes correctly on at least one platform before checking it into the CVS repository. All changes must be tested with egcs before commiting. That means you may need to test on at least two platforms.

### Script Guidelines

- In general, it's best to write scripts in Perl. It's OK to use Bourne shell. Never, never, never use csh, ksh, bash, or any other kind of shell.

- Follow the Perl style guide guide as closely as possible. `man perlstyle` to view it.
- Don't specify a hard-coded path to Perl itself. Use the following code at the top of the script to pick up perl from the users `PATH`:

      eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
          & eval 'exec perl -S $0 $argv:q'
          if 0;

- Never, never, never start the first line of a script with ``#'', unless the first line is ``#! /bin/sh''. With just ``#'', t/csh users will spawn a new shell. That will cause their `.[t]cshrc` to be processed, possibly clobbering a necessary part of their environment.

- If your Perl script relies on features only available in newer versions of Perl, include the a statement similar to the following:

              require 5.003;

- Don't depend on `.` being in the user's path. If the script spawns another executable that is supposed to be in the current directory, be sure the prefix its filename with `.`.

### Software Engineering Guidelines

- Advise: Keep other developers informed of problems and progress.

- Authorize: We have contractual obligations to not unilaterally change interfaces. If you need to change or remove an interface, get an OK.

- Minimize risk: Test all changes. Solicit review of changes.

- Revise only when necessary: Every change has risk, so avoid making any change unless there is a good reason for it.

- Normalize: Factor out commonality. For example, maintain a data value in only one place.

- Synthesize: Build stubs and scaffolding early to simulate the complete system. Maintain a checked-in version of the system that cleanly builds and tests at all times.

- Be available: Breaking compilation in one platform or another should be avoided (see above), but it is bound to happen when so many platforms are in use. Be available after making a change, if you won't be available for at least 48 hours after the change is made then don't make it!

### PACE Software Development Guidelines

PACE code should be developed following the ACE guidelines above, with these exceptions:

- An `if` statement that has just one statement must be written with the braces:

      if (condition)
        {
          statement;
        }

  This avoids bugs caused by subsequent insertion of code:

        if (condition)
          ACE_OS::fprintf (stderr, "I need to see what's going on here\n");
          statement;  /* Ooops!  This statement will always be executed!!!! */

### ACE Design Rules

Last modified .

Back to ACE Documentation Home.