From d697ed498cd66d0d7f01469c6d685d3b6246da5a Mon Sep 17 00:00:00 2001 From: Shahbaz Youssefi Date: Thu, 16 Nov 2023 11:32:50 -0500 Subject: Prepare the VK branch for cleanup/reformat Split from cleanup CL, containing bits that don't apply to older GL branches. This allows the cleanup CL to be cleanly cherry-picked to those branches. Affects: * Components: Framework, OpenGL, Vulkan VK-GL-CTS issue: 2282 Bug: b/327004039 Test: make cts -j 45 Change-Id: I5aeb09d06e51282f23f3b6a0599e40b80464ed12 (cherry picked from commit 0048f2464754b9bf2ce6c608a175bd5951e8221c on upstream-vulkan-cts-1.3.5) Merged-In: I5aeb09d06e51282f23f3b6a0599e40b80464ed12 --- .../api/vktApiMemoryRequirementInvarianceTests.cpp | 2 +- .../vktPipelineCreationCacheControlTests.cpp | 3 - .../coding_guidelines/de-coding-guidelines.html | 1534 -------------------- framework/delibs/coding_guidelines/prettify.css | 1 - framework/delibs/coding_guidelines/prettify.js | 23 - framework/delibs/decpp/deDefs.hpp | 1 + scripts/cppcheck.py | 160 -- 7 files changed, 2 insertions(+), 1722 deletions(-) delete mode 100644 framework/delibs/coding_guidelines/de-coding-guidelines.html delete mode 100644 framework/delibs/coding_guidelines/prettify.css delete mode 100644 framework/delibs/coding_guidelines/prettify.js delete mode 100644 scripts/cppcheck.py diff --git a/external/vulkancts/modules/vulkan/api/vktApiMemoryRequirementInvarianceTests.cpp b/external/vulkancts/modules/vulkan/api/vktApiMemoryRequirementInvarianceTests.cpp index 479e28afb..4ec5505bc 100644 --- a/external/vulkancts/modules/vulkan/api/vktApiMemoryRequirementInvarianceTests.cpp +++ b/external/vulkancts/modules/vulkan/api/vktApiMemoryRequirementInvarianceTests.cpp @@ -596,7 +596,7 @@ tcu::TestStatus InvarianceInstance::iterate (void) { int a = deRandom_getUint32(&m_random) % testCycles; int b = deRandom_getUint32(&m_random) % testCycles; - DE_SWAP(int, order[a], order[b]); + std::swap(order[a], order[b]); } // Allocate objects in shuffled order diff --git a/external/vulkancts/modules/vulkan/pipeline/vktPipelineCreationCacheControlTests.cpp b/external/vulkancts/modules/vulkan/pipeline/vktPipelineCreationCacheControlTests.cpp index c1c1bc9f8..cb952136e 100644 --- a/external/vulkancts/modules/vulkan/pipeline/vktPipelineCreationCacheControlTests.cpp +++ b/external/vulkancts/modules/vulkan/pipeline/vktPipelineCreationCacheControlTests.cpp @@ -1117,8 +1117,6 @@ TestStatus testInstance(Context& context, const TestParams& testParameter) using namespace test_common; -// Disable formatting on this next block for readability -// clang-format off /*--------------------------------------------------------------------*//*! * \brief Duplicate single pipeline recreation with explicit caching *//*--------------------------------------------------------------------*/ @@ -1343,7 +1341,6 @@ static constexpr TestParams TEST_CASES[] = DUPLICATE_BATCH_PIPELINES_NO_CACHE, DUPLICATE_BATCH_PIPELINES_DERIVATIVE_INDEX }; -// clang-format on /*--------------------------------------------------------------------*//*! * \brief Variadic version of de::newMovePtr diff --git a/framework/delibs/coding_guidelines/de-coding-guidelines.html b/framework/delibs/coding_guidelines/de-coding-guidelines.html deleted file mode 100644 index e1e42d6c3..000000000 --- a/framework/delibs/coding_guidelines/de-coding-guidelines.html +++ /dev/null @@ -1,1534 +0,0 @@ - - - -drawElements Coding Guidelines - - - - - - - - - - - -
- -
drawElements Coding Guidelines
-
-
"Always code as if the person who will maintain your code is a maniac serial killer that knows where you live."
- - - -
    -
  1. Table of Contents -
      - TODO: fill in, with links (use JavaScript?) -
    -
  2. - -
  3. Introduction -
      -
    1. Goal and philosophy -

      This document describes the drawElements coding style for C and C++ languages.

      - -

      The intention of the drawElements coding guidelines is to allow us to produce code written in a - consistent fashion, so that our product line will look similar throughout the line. The guiding - philosophy for choosing the described coding style is to avoid bugs when writing code, keep the code - maintainable, and also aim to make it beautiful. Some of the decisions are purely a matter of taste, - but have been made to keep the code consistent overall (say, camelCasing versus underscore_usage in - variable names.

      - -

      There are also many areas which are not covered by this document and there is some room to bring - your own style into the soup. Some of the ways of writing code are just purely matters of opinion. - The use of whitespace in code is a good example.

      - -

      This document is *not* the law of drawElements. If there is a good reason to deviate from it, you - should do that. However, if the reason is purely a matter of taste, then please follow the rules set - in here. Also, we want to encourage discussion about these guidelines and contributing to them, in - case you disagree or know a way of doing something better. This is meant to be an evolving document - that follows us as we learn as a group.

      - -

      A lot of examples are included in this document to make things easily readable and unambiguous. - For more source material, feel free to browse the source code of whichever drawElements projects - you have visibility to. You should see at least debase and depool libraries, if nothing - else.

      -
    2. - -
    3. Languages of choice -

      The main languages at drawElements are Ansi C89 and ISO C++ 98. Ansi C is used for developing - driver or middleware IP, while C++ can be used for stand-alone applications.

      - -

      The reason for using C for middleware IP development is that we build software for - mobile devices and the compilers there are often of dubious quality, especially when it comes to - support of C++. In addition C++ runtime library is a non-trivial dependency.

      - -

      Stand-alone userspace applications can be written in ISO C++11.

      - -

      For utility and tool development, other languages may also be used. So far, Python has been used - for all such development and is encouraged to be used in future tools as well. If there are strong - reasons, other languages may also be considered.

      -
    4. - -
    5. C code example - -

      Let's get started with some sample drawElements code. The code files below show a simple random - "class" implemented in C89. The code is taken from the drawElements base portability library, debase.

      -
      deRandom.h: The header file.
      -
      -#ifndef _DERANDOM_H
      -#define _DERANDOM_H
      -/*-------------------------------------------------------------------------
      - * drawElements Base Portability Library
      - * -------------------------------------
      - *
      - * Copyright 2014 The Android Open Source Project
      - *
      - * Licensed under the Apache License, Version 2.0 (the "License");
      - * you may not use this file except in compliance with the License.
      - * You may obtain a copy of the License at
      - *
      - *      http://www.apache.org/licenses/LICENSE-2.0
      - *
      - * Unless required by applicable law or agreed to in writing, software
      - * distributed under the License is distributed on an "AS IS" BASIS,
      - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      - * See the License for the specific language governing permissions and
      - * limitations under the License.
      - *
      - * Id: $Id$
      - *//*!
      - * \file
      - * \brief Random number generation.
      - *//*--------------------------------------------------------------------*/
      -
      -#ifndef _DEDEFS_H
      -#   include "deDefs.h"
      -#endif
      -
      -DE_BEGIN_EXTERN_C
      -
      -/*--------------------------------------------------------------------*//*!
      - * \brief Random number generator.
      - *
      - * Uses the Xorshift algorithm for producing pseudo-random numbers. The
      - * values are generated based on an initial seed and the same seed always
      - * produces the same sequence of numbers.
      - *
      - * See: http://en.wikipedia.org/wiki/Xorshift
      - *//*--------------------------------------------------------------------*/
      -typedef struct deRandom_s
      -{
      -    deUint32	x;      /*!< Current random state.  */
      -    deUint32	y;
      -    deUint32	z;
      -    deUint32	w;
      -} deRandom;
      -
      -void        deRandom_init           (deRandom* rnd, deUint32 seed);
      -deUint32    deRandom_getUint32      (deRandom* rnd);
      -float       deRandom_getFloat       (deRandom* rnd);
      -deBool      deRandom_getBool        (deRandom* rnd);
      -
      -DE_END_EXTERN_C
      -
      -#endif /* _DERANDOM_H */
      -
      -
      deRandom.c: The implementation file.
      -
      -/*-------------------------------------------------------------------------
      - * drawElements Base Portability Library
      - * -------------------------------------
      - *
      - * Copyright 2014 The Android Open Source Project
      - * \todo insert legalese here.
      - *
      - * Id: $Id$
      - *//*!
      - * \file
      - * \brief Random number generation.
      - *//*--------------------------------------------------------------------*/
      -
      -#include "deRandom.h"
      -
      -#include 
      -#include 
      -
      -DE_BEGIN_EXTERN_C
      -
      -/*--------------------------------------------------------------------*//*!
      - * \brief Initialize a random number generator with a given seed.
      - * \param rnd	RNG to initialize.
      - * \param seed	Seed value used for random values.
      - *//*--------------------------------------------------------------------*/
      -void deRandom_init (deRandom* rnd, deUint32 seed)
      -{
      -    rnd->x = (deUint32)(-(int)seed ^ 123456789);
      -    rnd->y = (deUint32)(362436069 * seed);
      -    rnd->z = (deUint32)(521288629 ^ (seed >> 7));
      -    rnd->w = (deUint32)(88675123 ^ (seed << 3));
      -}
      -
      -/*--------------------------------------------------------------------*//*!
      - * \brief Get a pseudo random uint32.
      - * \param rnd	Pointer to RNG.
      - * \return Random uint32 number.
      - *//*--------------------------------------------------------------------*/
      -deUint32 deRandom_getUint32 (deRandom* rnd)
      -{
      -    const deUint32  w = rnd->w;
      -    deUint32        t;
      -
      -    t = rnd->x ^ (rnd->x << 11);
      -    rnd->x = rnd->y;
      -    rnd->y = rnd->z;
      -    rnd->z = w;
      -    rnd->w = w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
      -    return w;
      -}
      -
      -/*--------------------------------------------------------------------*//*!
      - * \brief Get a pseudo random float in range [0, 1[.
      - * \param rnd	Pointer to RNG.
      - * \return Random float number.
      - *//*--------------------------------------------------------------------*/
      -float deRandom_getFloat (deRandom* rnd)
      -{
      -    return (deRandom_getUint32(rnd) & 0xFFFFFFFu) / (float)(0xFFFFFFFu+1);
      -}
      -
      -/*--------------------------------------------------------------------*//*!
      - * \brief Get a pseudo random boolean value (DE_FALSE or DE_TRUE).
      - * \param rnd	Pointer to RNG.
      - * \return Random float number.
      - *//*--------------------------------------------------------------------*/
      -deBool deRandom_getBool (deRandom* rnd)
      -{
      -    deUint32 val = deRandom_getUint32(rnd);
      -    return ((val & 0xFFFFFF) < 0x800000);
      -}
      -
      -DE_END_EXTERN_C
      -
      -
    6. -
    7. C++ code example - -

      The following code, taken from deutil demonstrates how C++ classes should look like.

      -
      deUniquePtr.hpp: Unique pointer template.
      -
      -#ifndef _DEUNIQUEPTR_HPP
      -#define _DEUNIQUEPTR_HPP
      -/*-------------------------------------------------------------------------
      - * drawElements C++ Base Library
      - * -----------------------------
      - *
      - * Copyright 2014 The Android Open Source Project
      - *
      - * Licensed under the Apache License, Version 2.0 (the "License");
      - * you may not use this file except in compliance with the License.
      - * You may obtain a copy of the License at
      - *
      - *      http://www.apache.org/licenses/LICENSE-2.0
      - *
      - * Unless required by applicable law or agreed to in writing, software
      - * distributed under the License is distributed on an "AS IS" BASIS,
      - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      - * See the License for the specific language governing permissions and
      - * limitations under the License.
      - *
      - *//*!
      - * \file
      - * \brief Unique pointer.
      - *//*--------------------------------------------------------------------*/
      -
      -#ifndef _DEDEFS_HPP
      -#   include "deDefs.hpp"
      -#endif
      -
      -namespace de
      -{
      -
      -/*--------------------------------------------------------------------*//*!
      - * \brief Unique pointer
      - *
      - * UniquePtr is smart pointer that retains sole ownership of a pointer
      - * and destroys it when UniquePtr is destroyed (for example when UniquePtr
      - * goes out of scope).
      - *
      - * UniquePtr is not copyable or assignable. Pointer ownership cannot be
      - * transferred between UniquePtr's.
      - *//*--------------------------------------------------------------------*/
      -template<typename T, class Deleter = DefaultDeleter<T> >
      -class UniquePtr
      -{
      -public:
      -    explicit    UniquePtr       (T* const ptr, Deleter deleter = Deleter());
      -                ~UniquePtr      (void);
      -
      -    T*          get             (void) const throw() { return m_ptr;    }   //!< Get stored pointer.
      -    T*          operator->      (void) const throw() { return m_ptr;    }   //!< Get stored pointer.
      -    T&          operator*       (void) const throw() { return *m_ptr;   }   //!< De-reference stored pointer.
      -
      -    operator    bool            (void) const throw() { return !!m_ptr;  }
      -
      -private:
      -                UniquePtr       (const UniquePtr<T>& other); // Not allowed!
      -    UniquePtr   operator=       (const UniquePtr<T>& other); // Not allowed!
      -
      -    T* const    m_ptr;
      -    Deleter     m_deleter;
      -};
      -
      -/*--------------------------------------------------------------------*//*!
      - * \brief Construct unique pointer.
      - * \param ptr Pointer to be managed.
      - *
      - * Pointer ownership is transferred to the UniquePtr.
      - *//*--------------------------------------------------------------------*/
      -template<typename T, class Deleter>
      -inline UniquePtr<T, Deleter>::UniquePtr (T* const ptr, Deleter deleter)
      -    : m_ptr     (ptr)
      -    , m_deleter (deleter)
      -{
      -}
      -
      -template<typename T, class Deleter>
      -inline UniquePtr<T, Deleter>::~UniquePtr (void)
      -{
      -    m_deleter(m_ptr);
      -}
      -
      -} // de
      -
      -#endif // _DEUNIQUEPTR_HPP
      -
      -
    8. -
    -
  4. - -
  5. Naming conventions and formatting -
      -
    1. Basic naming conventions -

      Each project should have a prefix of its own. For drawElements base libraries, - the prefix de is used. Other projects should use a different, arbitrary prefix. - For instance, the stitcher project uses the xo prefix.

      - -

      Anything which has a reasonable possibility of causing a naming conflict should be - prefixed. This includes files, structs, enums, functions (except private ones), macros, etc. - In C projects, just about everything in the code needs to be prefixed (files, struct, enums, - global functions, etc.), but in C++ code, namespaces remove the need for most prefixing. - File names and macros should still be prefixed in C++ code as well. Note that members - of classes (either C or C++), or structs or unions do not need to be prefixed with the - package prefix.

      - -

      Identifiers are generally typed in camelCase. This applies to file names, structs, - enums, local variables, and struct members. In some cases, prefixes are used to clarify - the behavior of a variable. Static variables are prefixed with s_, global variables - with g_, and C++ class member variables with m_. Macros and enum entries should - always be written in UPPER_CASE with underscores separating the words. Members of C classes - don't need to be prefixed.

      - -

      When emulating classes in C, the class name itself should be written in CamelCase, but - starting with a upper-case letter. Usually the classes are prefixed: xoArmEmu, - deRandom, but if the class only exists within a single .c file, the prefix can be - omitted: StringBuilder. The member functions of the class should be prefixed with - the full class name and an underscore, followed by a camelCased function name: - xoArmEmu_emulateCode().

      - -

      Examples of correctly named identifiers:

      -
        -
      • dePool.c, dePool.h, deUniquePtr.hpp, deThread.cpp -- file names
      • -
      • deRandom, xoStitcher -- structs / classes
      • -
      • deMemPoolFlag, xoConditionCode -- enums
      • -
      • DE_COMPILER_MSC -- macros
      • -
      • XO_BACKEND_NEON -- enum entry
      • -
      • setTableSize() -- local (static) function
      • -
      • xoArmEmu_emulateCode() -- C class member function
      • -
      • numVariables -- local variable
      • -
      • m_itemHash -- member variable in a C++ class
      • -
      • s_rcpTable -- static variable in a function
      • -
      • g_debugFlag -- global variable
      • -
      -
    2. - -
    3. Choosing good names -

      Naming your variables is somewhat of a black art, but the main goal of giving a name should - be clarity. You want to communicate what the contents of the variable mean. The more obscure - the purpose of a variable is, the longer (and more descriptive) a name you should invent for it. - Also, the longer the life time of a variable is, the longer a name it deserves. For example, a - loop counter which is alive for page worth of code should be named something like vertexNdx, - whereas a loop counter which lives only a couple of lines can be named simply i or ndx.

      - -

      Most variables should be declared const and never changed (see coding philosophy section). - Thus one often successful approach for variable naming is to give name for the value instead. - For example when querying first child of node and storing it in variable, that should be named - as firstChild instead of node.

      - -

      Consistency is one important factor in naming variables. When a similar kind of name is needed - in multiple places, choose a way of devising the name and stick to that. E.g., if you query the - number of elements in an array to a local variable in several functions, always use the same name - in each of the functions.

      - -

      When dealing with counts or numbers (number of elements in an array, etc.), you should always - clearly indicate with the name that this is the case, e.g., numElements (preferred), - elementCount, etc. Which ever prefix or postfix you choose to use, stick to it.

      - -

      Function parameters that have an unit of measure (e.g. seconds or bytes) should have the unit - as part of the name, for example timeLimitMs and chunkSizeKb.

      - -

      Use American English instead of English English. Choose gray over grey, color over colour, - and so forth.

      -
    4. -
    5. Canonical abbreviations - - - - - - -
      buffer buf
      destination dst
      index ndx
      source src
      variable var
      -
    6. - -
    7. Struct and enum typedeffing -

      For enums and structs, the types should always be typedeffed and used without the struct or - enum prefix in actual code.

      - -
      Example.
      -
      -/* Declaration. */
      -typedef enum xoConditionCode_e
      -{
      -    ...
      -} xoConditionCode;
      -
      -typedef struct deMempool_s
      -{
      -    ...
      -} deMemPool;
      -
      -/* Usage. */
      -deMemPool*        memPool;
      -xoConditionCode   condCode;
      -
      -
    8. - -
    9. Header files and including -

      All header files should have include guards in them to avoid processing them multiple times - in case they are included from multiple places. The style used for the macro is _FILENAME_H, - for example: _DEDEFS_H. Whenever including other headers from a header file, you should - always use external include guards as well. The external include guards considerably reduce the - number of file accesses that the compiler needs to make, resulting in faster compile times.

      - -

      Each implementation file should have matching header file and vice versa. The implementation - file must include the corresponding header file first. By doing that, it is guaranteed that the - header file includes all of its dependencies.

      - -

      Each header file should first include deDefs.h, or alternatively project-specific - xxDefs.h/hpp file that in turn includes deDefs.h. That way all the usual types and macros - are always properly defined.

      - -
      External include guard example.
      -
      -#ifndef _DEDEFS_H
      -#   include "deDefs.h"
      -#endif
      -#ifndef _DEINT32_H
      -#   include "deInt32.h"
      -#endif
      -#ifndef _DEUNIQUEPTR_HPP
      -#   include "deUniquePtr.hpp"
      -#endif
      -
      - -

      The include order of files should start from debase (esp. deDefs.h), go thru - other base libraries, then your own project header files, and lastly the system header files. - Also, a .c file must include its own header file first. E.g., deMemPool.c must - first include deMemPool.h.

      - -

      Every include path must also end up including deDefs.h before any actual code is processed. - This ensures that the basic portability macros (DE_OS, DE_COMPILE, etc.) have been - defined.

      -
    10. - -
    11. Indenting and whitespace -

      Code should be indented with tabs (instead of spaces) and a tab-width of 4 characters should - be used.

      - -

      Always put braces on their own lines. This applies to functions, structs, enums, ifs, loops, - everything. The only exception are single-line scopes. For one-statement ifs or loops, braces - should not be used. Also, put else and else if on their own lines as well.

      - -
      Brace usage
      -
      -void main (int argc, const char** argv)
      -{
      -    if (argc > 1)
      -        parseArgs(argv[1]);
      -    else
      -    {
      -        printf("Usage:\n");
      -        printf("...\n");
      -    }
      -}
      -
      - -

      In addition to only indenting your code, things like variable names in a list of - declarations or comments at the end of line, should also be aligned such that they start at - the same column. Compare the following two examples of the same code, only with differing - alignments in the text.

      - -
      Aligned variable declarations and comments.
      -
      -struct deMemPool_s
      -{
      -    deUint32        flags;         /*!< Flags.                                      */
      -    deMemPool*      parent;        /*!< Pointer to parent (null for root pools).    */
      -    deMemPoolUtil*  util;          /*!< Utilities (callbacks etc.).                 */
      -    int             numChildren;   /*!< Number of child pools.                      */
      -    deMemPool*      firstChild;    /*!< Pointer to first child pool in linked list. */
      -    deMemPool*      prevPool;      /*!< Previous pool in parent's linked list.      */
      -    deMemPool*      nextPool;      /*!< Next pool in parent's linked list.          */
      -    ...
      -};
      -
      - -
      No alignments used.
      -
      -struct deMemPool_s
      -{
      -    deUint32 flags; /*!< Flags. */
      -    deMemPool* parent; /*!< Pointer to parent (null for root pools). */
      -    deMemPoolUtil* util; /*!< Utilities (callbacks etc.). */
      -    int numChildren; /*!< Number of child pools. */
      -    deMemPool* firstChild; /*!< Pointer to first child pool in linked list. */
      -    deMemPool* prevPool; /*!< Previous pool in parent's linked list. */
      -    deMemPool* nextPool; /*!< Next pool in parent's linked list. */
      -    ...
      -};
      -
      -
    12. - -
    13. Other formatting - -

      Always use C-style comments in C code: /* This is a C comment. */ Only use - the C++ // end-of-line comments in C++ code.

      - -
      Comment styles.
      -
      -/* Use this kind of comments in C code. */
      -
      -// This kind of comments may only be used in C++ code.
      -
      - -
      Pointer and references.
      -
      -// Good: pointers and references are a part of the type
      -void*          ptr;
      -deInt32*       colorBuffer;
      -xoArmEmu*      armEmu;
      -Array<int>&    intArray;
      -void doBlend (deUint32* dst, const deUint32* src);
      -
      -// Bad: pointer symbol should not be a part of the name
      -void *ptr;
      -void doBlend (deUint32 *dst, const deUint32 * src);
      -
      - -
      Formatting of function declarations.
      -
      -// Good: void if empty param list, empty space after name, braces on own line
      -void doStuff (void)
      -{
      -}
      -
      -// Bad: horrible function name!
      -void doStuff() {
      -}
      -
      -// Good: separate arguments with spaces, function name
      -ShapeList getIntersectingShapes (float x, float y, float z)
      -{
      -}
      -
      -// Bad: function name (list of what volumes?), no space after commas in arg list
      -ShapeList getShapeList (float x,float y,float z)
      -{
      -}
      -
      -// Exception: sometimes simple function are best written as one-liners
      -float deFloatAbs (float f) { return (f < 0.0f) ? -f : f; }
      -
      -
      - -
      Formatting of control statements.
      -
      -// Good: no extra braces for one-liner if cases
      -if (a.isZero)
      -    result = 0.0f;
      -else
      -    result = a.value * (1.0 / 65536.0f);
      -
      -// Bad: extraneous braces, bad whitespace usage
      -if (a.isZero)
      -{
      -    result=0.0f;
      -}
      -else
      -{
      -    result=a.value*(1.0 / 65536.0f);
      -}
      -
      -// Good: expression easy to read
      -if (a.isZero && b.isZero)
      -{
      -    ...
      -}
      -
      -// Bad: missing spaces around && operator, missing space after 'if'
      -if(a.isZero&&b.isZero)
      -{
      -    ...
      -}
      -
      -// Good: else on its own line
      -if (alpha == 0)
      -{
      -    ...
      -}
      -else if (alpha == 255)
      -{
      -    ...
      -}
      -else
      -{
      -    ...
      -}
      -
      -// Bad: else on same line as closing brace
      -if (alpha == 0)
      -{
      -    ...
      -} else if (...)
      -{
      -    ...
      -} else
      -{
      -    ...
      -}
      -
      -// Good: note space after 'while'
      -while (numTriangles--)
      -{
      -    ...
      -}
      -
      -// Bad: whitespace usage
      -while(numTriangles --)
      -{
      -    ...
      -}
      -
      -// Good: while on same line as closing brace
      -do
      -{
      -    ...
      -} while (--numTriangles);
      -
      -// Bad: while on its own line, missing whitespace after 'while'
      -do
      -{
      -    ...
      -}
      -while(--numTriangles);
      -
      -// Good: easy to read
      -for (ndx = 0; ndx < numTriangles; ndx++)
      -
      -// Bad: missing spaces all over (whitespace should be used to separate expressions)
      -for(ndx=0;ndx<numTriangles;ndx ++)
      -
      -// Good: note missing braces for while, correct usage of whitespace
      -while (numTriangles--)
      -    area += computeArea(triangle[ndx++]);
      -
      -// Bad: don't put unnecessary braces, avoid extraneous whitespace in expressions
      -while (numTriangles--)
      -{
      -    area+=computeArea( triangle [ndx++] );
      -}
      -
      - -
      Formatting switch cases.
      -
      -// Good: case-statements indented, code indented another level (including breaks)
      -switch (blendMode)
      -{
      -    case XX_BLENDMODE_NORMAL: // no variable declarations
      -        ...
      -        break;
      -
      -    case XX_BLENDMODE_SRC_OVER: // need braces if declaring variables inside
      -    {
      -        int alpha = ...;
      -        break;
      -    }
      -
      -    case XX_BLENDMODE_XYZ:
      -        ...
      -        // FALLTHRU! -- make non-breaked cases very explicit!
      -
      -    default: // handles the final blendmode (DISABLED) with an assertion!
      -        DE_ASSERT(blendMode == XX_BLENDMODE_DISABLED);
      -
      -        break; // always put break!
      -}
      -
      -// Bad:
      -switch(blendMode)
      -{
      -case XX_BLENDMODE_NORMAL: // always indent case labels
      -    ...
      -break; // put break on same level as indented code!
      -
      -case XX_BLENDMODE_SRC_OVER:
      -    {
      -        ...
      -        break;
      -    }
      -
      -case XX_BLENDMODE_XYZ:
      -    ...
      -
      -case XX_BLENDMODE_DISABLED: // always comment the case fall-through (like above)
      -    ...
      -} // default case missing! always need to handle it (and assert if illegal!)
      -
      - -
      Formatting of expressions.
      -
      -// Good: parenthesis or whitespace used to indicate evaluation order
      -array[(a * b) + c];
      -array[a*b + c];
      -
      -// Bad: order unclear
      -array[a*b+c];
      -
      -// Good: parenthesis (or whitespace) makes evaluation order unambiguous
      -array[(a && b) || (c == 0)]
      -array[a==0 || b==0 || c==0] // in some cases spaces can be used instead of parenthesis
      -
      -// Bad: unclear evaluation order
      -array[a&&b || c==0] // does this even work?
      -array[a == 0 || b == 0 || c == 0]
      -
      -// Good: easy to see different parts of evaluation (whitespace where it matters)
      -array[triangle->index0 - cache.baseIndex];
      -
      -// Bad: hard to read (whitespace around brackets doesn't help readability!)
      -array[ triangle->index0-cache.baseIndex ];
      -array [triangle -> index0 - cache.baseIndex];
      -
      -// Good: easy to see all function arguments
      -computeArea(vtx0.x, vtx0.y, vtx1.x, vtx1.y, vtx2.x, vtx2.y);
      -
      -// Bad: missing spaces makes it hard to read, no space after function name when calling
      -computeArea ( vtx0.x,vtx0.y,vtx1.x,vtx1.y,vtx2.x,vtx2.y );
      -
      -// Good: readable (the code itself is a made-up example and thus incomprehensible)
      -// Consider: would probably make more readable code to use temporary variables here
      -if (sizeArray[a+5] > getSize(getFoo()+2))
      -if (sizeArray[a + 5] > getSize(getFoo() + 2))
      -
      -// Bad: whitespace usage confuses rather than helps
      -if(sizeArray[a+5]>getSize(getFoo()+2))
      -if ( sizeArray [ a + 5 ] > getSize ( getFoo () + 2 ) )
      -
      -// Bad: unclear (and wrong) evaluation order
      -if (bitMask & (1<<bit) == 0)
      -
      - -
      Other formatting.
      -
      -#if defined(DE_DEBUG)      // prefer #if defined() to #ifdef
      -    ...
      -#endif /* DE_DEBUG */      // only put ending comment if #if is far away
      -
      -
      -
    14. -
    -
  6. - -
  7. Base library services -

    TODO: explain all of these

    - -
      -
    1. debase/deDefs.h -
      -- DE_COMPILER, DE_OS, DE_CPU
      -- basic types (deUint8, deIntptr, deBool==int, ..)
      -- DE_NULL
      -- DE_DEBUG -- #if defined(DE_DEBUG)
      -- DE_INLINE
      -- DE_ASSERT(), DE_VERIFY(), DE_TEST_ASSERT(), DE_STATIC_ASSERT()
      -- DE_BREAKPOINT()
      -- DE_SWAP()
      -- DE_LENGTH_OF_ARRAY()
      -- DE_OFFSET_OF()
      -- DE_UNREF()
      -- DE_BEGIN_EXTERN_C, DE_END_EXTERN_C
      -- DE_NULL_STATEMENT
      -
    2. - -
    3. Other debase headers -
      -- deInt32.h: deInRange32(), deInBounds32(), hashing
      -- deFloat16.h: fp16<->fp32
      -- deMath.h: generic float math
      -- deRandom.h: random number generation
      -- deMemory.h: allocating memory, deMemset(), deMemcpy(), DE_NEW(), DE_DELETE()
      -- deString.h:
      -
    4. - -
    5. depool services -
      -- memory pools (deMemPool)
      -- pooled data structures
      -  * Array
      -  * Set
      -  * Hash
      -  * HashArray
      -  * HashSet
      -
    6. -
    -
  8. - -
  9. Commenting code -
      -
    1. File comment boxes -

      Each source file should contain the following comment box. In header files the comment is placed after - the #ifdef-#endif pair. On implementation files the comment box is placed at the beginning.

      -
      -/*-------------------------------------------------------------------------
      - * Full Module Name
      - * ----------------
      - *
      - * Copyright 2014 The Android Open Source Project
      - *
      - * Licensed under the Apache License, Version 2.0 (the "License");
      - * you may not use this file except in compliance with the License.
      - * You may obtain a copy of the License at
      - *
      - *      http://www.apache.org/licenses/LICENSE-2.0
      - *
      - * Unless required by applicable law or agreed to in writing, software
      - * distributed under the License is distributed on an "AS IS" BASIS,
      - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      - * See the License for the specific language governing permissions and
      - * limitations under the License.
      - *
      - *//*!
      - * \file
      - * \brief Short description of the contents.
      - *
      - * Followed by longer description if necessary (such as high-level algorithm
      - * description).
      - *//*--------------------------------------------------------------------*/
      -
      -			
    2. - -
    3. Structs/classes/enums comment boxes -

      TODO:

      -
    4. - -
    5. Other Doxygen comment boxes (/** ... */ and /*!< ... */) -

      TODO: single-line, multi-line

      -
    6. - -
    7. Code comments -

      Below and example of code commenting for C. When doing C++, you can replace C-style comments with C++-comments.

      -
      -callFoo(&a);
      -
      -/* Comment about following block (Note empty line before and after)*/
      -
      -callBar(&b);
      -c = a + b; /* Why we need to do this op */
      -doItAll(a, b, c);
      -
      -/* Badness starts with this comment */
      -callBar(&b);
      -/* Why we need to do this op */
      -c = a + b;
      -doItAll(a, b, c);
      -
      -			  
      -
    8. - -
    9. Tags -

      Todo-comments should use the following syntax:

      -
      -/* \todo [2012-01-26 pyry] Give a longer description of todo-usage in code. */
      -
      -

      If you wish to communicate to fellow developer about some unexpected behavior or corner-case - that is not obvious, \note tag can be used.

      -
      -/* \note Tangent may be zero. */
      -
      -
    10. -
    -
  10. - -
  11. Generic programming -
      -
    1. Classes in C -

      TODO: explain

      -
    2. - -
    3. Const correctness -

      When declaring function arguments, local variables, or class members, all non-mutable ones - must be declared const. Declaring variable const communicates clearly your intent to not modify - the given value. This is especially important in function argument lists.

      - -

      Declaring local variables, or function arguments that are passed by value, const, may be a bit - controversial. There are indeed a lots of existing code that doesn't follow this rule. However, - adding extra constness has proven to improve code readability a quite bit and thus all new code - must use const correctly. The only exception is function arguments passed by value; for those - const keyword can be omitted. By-value function arguments are however considered to be const - for all purposes.

      - -
      Example.
      -
      -// Function example. Note const qualifier on maxDepth as well which is passed by value.
      -static glu::VarType generateRandomType (const int maxDepth, int& curStructIdx, vector<const StructType*>& structTypesDst, Random& rnd)
      -{
      -    const bool isStruct     = maxDepth > 0 && rnd.getFloat() < 0.2f;
      -    const bool isArray      = rnd.getFloat() < 0.3f;
      -
      -    ...
      -}
      -
      -// Class members
      -class Node
      -{
      -public:
      -                   Node      (Node* const parent);
      -                   ~Node     (void);
      -
      -    ...
      -private:
      -    Node* const    m_parent;
      -};
      -
      -Node::Node (Node* const parent)
      -    : m_parent(parent) // Const members can be initialized
      -{
      -}
      -
      -
    4. - -
    5. Declaring variables -

      All variables should be declared at the beginning of a block. If variables are introduced in - the middle of code, nested block must be used. This is what ANSI C requires, and the same style must - be used in C++ code as well. The only exception for this is loop counters in C++; they may be - declared in loop init expression.

      - -

      Having variable declarations always at the beginning of the block makes code easier to read - as no new state is introduced in the middle of code. It also guides towards writing smaller - functions that don't use too many variables.

      - -
      Example.
      -
      -static void logTransformFeedbackVaryings (TestLog& log, const glw::Functions& gl, const deUint32 program)
      -{
      -    int numTfVaryngs    = 0;
      -    int	maxNameLen      = 0;
      -
      -    gl.getProgramiv(program, GL_TRANSFORM_FEEDBACK_VARYINGS, &numTfVaryngs);
      -    gl.getProgramiv(program, GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH, &maxNameLen);
      -    GLU_EXPECT_NO_ERROR(gl.getError(), "Query TF varyings");
      -
      -    {
      -        vector<char> nameBuf(maxNameLen+1);
      -
      -        for (int ndx = 0; ndx < numTfVaryngs; ndx++)
      -        {
      -            ...
      -
      -
    6. - -
    7. Variable life-time -

      TODO: minimize life-time of a variable (may sometimes need additional scopes in C)

      -
    8. - -
    9. Enumerations -

      TODO: assign zero to first, let compiler assign others (in typical lists)

      -

      TODO: use ENUM_LAST

      -

      TODO: mask values

      -

      TODO: use instead of #defines

      -

      TODO: typedef xxEnumName_e trick (already explained above?)

      -
    10. - -
    11. Error handling -

      There are generally two types of errors that can occur in code; errors that stem from environment - or bad input, and errors that are caused by logic error in the code. Former ones are typically - outside our control (such as running into a network error) and latter are simply programming mistakes.

      - -

      External errors must be handled in a graceful way. Depending on the project it may include handling - out-of-memory situations as well (most certainly when doing drivers or middleware). In C function return - value should be used for communicating whether external error was hit. In C++ code exceptions can - be used as well. Assertions must not be used for checking external error conditions.

      - -

      Internal logic errors must be checked with assertions. See next section.

      -
    12. - -
    13. Assertions -

      Assertions are a form of code documentation. They explicitly declare what the code expects from - input values or current state. They are tremendously useful when trying to understand how certain - piece of code should be used. In addition they are a very nice debugging aid as they help catch logic - errors early on before those errors get chance to corrupt program state.

      - -

      Functions should assert all non-trivial input data and conditions. The one notorious exception is - that pointer validity doesn't need to be asserted if the pointer is dereferenced immediately. - Non-trivial computation results should also be checked with assertions.

      - -
      Example.
      -
      -// Examples of good assertions:
      -void* deMemPool_alignedAlloc (deMemPool* pool, int numBytes, deUint32 alignBytes)
      -{
      -    void* ptr;
      -    DE_ASSERT(pool); // Must be asserted since not dereferenced but passed to another function
      -    DE_ASSERT(numBytes > 0); // Assertion on input data condition
      -    DE_ASSERT(deIsPowerOfTwo32((int)alignBytes)); // Non-trivial input condition
      -    ptr = deMemPool_allocInternal(pool, numBytes, alignBytes);
      -    DE_ASSERT(deIsAlignedPtr(ptr, alignBytes)); // Assertion on computation result
      -    return ptr;
      -}
      -
      -// Badness starts here
      -
      -void getTextureWidth (const Texture* texture)
      -{
      -    DE_ASSERT(texture); // Bad: unnecessary, will crash anyway if texture is null
      -    return texture->width;
      -}
      -
      -void doStuff (void)
      -{
      -    int i = 3;
      -    i += 2;
      -    DE_ASSERT(i == 5); // Bad: assertion on trivial computation result
      -
      -    FILE* f = fopen("myfile.txt", "rb");
      -    DE_ASSERT(f); // Bad: there are legitimate reasons for failure
      -}
      -
      - -
    14. - -
    15. Lookup tables -

      TODO: DE_STATIC_ASSERT lookup table size - should usually match to ENUM_TYPE_LAST

      - -
      -typedef enum xxBlendEquation_e
      -{
      -    XX_BLEND_EQUATION_ADD = 0,
      -    XX_BLEND_EQUATION_SUBTRACT,
      -    XX_BLEND_EQUATION_REVERSE_SUBTRACT,
      -
      -    XX_BLEND_EQUATION_LAST
      -} xxBlendEquation;
      -
      -// Note: size is left for compiler to figure out
      -static const s_blendModeMap[] =
      -{
      -    GL_FUNC_ADD,                // XX_BLEND_EQUATION_ADD
      -    GL_FUNC_SUBTRACT,           // XX_BLEND_EQUATION_SUBTRACT
      -    GL_FUNC_REVERSE_SUBTRACT    // XX_BLEND_EQUATION_REVERSE_SUBTRACT
      -};
      -// This will cause compilation failure lookup table size gets out of date
      -DE_STATIC_ASSERT(DE_LENGTH_OF_ARRAY(s_blendModeMap) == XX_BLEND_EQUATION_LAST);
      -
      -
    16. - -
    17. Struct size -

      TODO: DE_STATIC_ASSERT of struct sizes

      -

      TODO: use small datatypes (deUint8 instead of deBool) when size matters.

      -
    18. - -
    19. Extraneous code -

      TODO: avoid too verbose code.

      - -
      Example.
      -
      -// Good: compact without sacrificing readability
      -return (a < 0.0f) ? -a : a;
      -
      -// Bad: waste of space
      -float result;
      -if (a < 0.0f)
      -{
      -    result = -a;
      -}
      -else
      -{
      -    result = a;
      -}
      -return result;
      -
      - -
    20. -
    -
  12. - -
  13. C++ topics -
      -
    1. Class declarations -

      TODO: how declaration looks like (already shown in example..)

      -

      TODO: function definitions inside class ok if single-line, other special cases

      -
    2. - -
    3. Class boilerplate -

      TODO: copy ctor, assignment operator

      -
    4. - -
    5. Code Formatting -
      -
      -// Constructors
      -FooAtom::FooAtom(int proton, float electron)
      -	: m_proton    (proton)   // Note aligning member initializers.
      -	, m_electron  (electron)
      -{
      -
      -}
      -
      -// Remember to add the name of the namespace at the end of the namespace
      -namespace foo
      -{
      -
      -// Namespaces aren't indented
      -class Proton;
      -
      -...
      -} // foo
      -
      -
    6. -
    7. RAII -

      Everyone should get familiar with RAII. In a nutshell, "resource acquisition is initialization" - means that a class destructor must always release all resources (such as memory or OS handles) - that have been allocated during the whole lifetime of the object.

      - -

      RAII is essential for exception-safe code. You should always make sure that if an exception is - thrown, including out-of-memory cases, your code behaves properly and releases all allocated resources.

      -
    8. - -
    9. Pointers and references -

      In C++ references should be generally preferred over pointers. The main difference between pointers - and references is that references can not change, and are not expected to be null. References should be - used instead of pointers for passing objects when both conditions hold; object can not be null nor - reference won't be modified once initialized.

      -

      Pointers are used when there is need to change the address, or it can be null for a valid reason. - Additionally, pointers are always used for passing basic type or object arrays.

      -
    10. - -
    11. Containers -

      TODO: describe stl container usage policies

      -
    12. - -
    13. Exceptions -

      TODO: exceptions can be used, custom ones must be based on std::exception

      -
    14. - -
    15. Polymorphism -

      TODO: when to use virtual functions, virtual destructor

      -
    16. - -
    17. Namespaces -

      TODO: namespace naming

      -

      TODO: using statement, never using in headers

      -
    18. - -
    -
  14. - -
  15. Tools -
      -
    1. Git -

      Git is currently the weapon of choice for source control management. Even though it is - not the perfect solution, it gets job done well, or at least better than most other solutions.

      - -

      Our repositories are hosted on github.com. You are allowed and encouraged to push any number - of new branches to the github repositories. Remember to clean up the obsolete ones after they - have been merged to master. But never delete a remote branch that hasn't been created by you.

      - -

      Before you commit anything, make sure user.name and user.email are properly set up.

      -
      -git config --global user.name "Veijo Elements"
      -git config --global user.email "veijo.elements@drawelements.com"
      -
      - -

      The standard line ending format for all text files is Unix-style. The best way to handle - line endings on Windows systems is to set core.autocrlf to input. That causes - conversion to Unix-style line endings on commit only (i.e. not in checkout).

      -
      -git config --global core.autocrlf input
      -
      - -

      In order to keep trailing whitespace out of source tree, a standard pre-commit hook must - be placed in each local clone of any source repositories.

      -
      -# in repository directory
      -cp ~/Dropbox/drawElements/Misc/git/pre-commit .git/hooks/
      -
      -
    2. - -
    3. Build systems and IDEs -

      CMake is used as an official project file generator. CMake can be used to generate makefiles - or project files for most IDEs. Unless there is a good reason, you should use project files - generated by CMake.

      - -

      You are free to choose any IDE or editor you like. At least Visual Studio, vim and - emacs have been successfully used in the past. Good debugger integration is strongly recommended.

      -
    4. -
    -
  16. - -
  17. Coding philosophy -
      -
    1. Designing classes -

      Each class should have only a single purpose to fulfill, and it should encapsulate that - entirely. All functionality that is secondary and doesn't require access to classes' internal - implementation should not be part of that class. This is called - single responsibility principle. It is probably easier to grasp it with an example.

      - -

      Consider a Texture2D class that manages 2D-dimensional texture data. Such class is clearly - responsible for managing lifetime of the associated memory, and storing properties such as - size and format. Now, one could need a function for blitting (copying) portion of one texture - to some position in an another texture. This could be added as a method to texture class, but - it most certainly isn't core responsibility of that class. So correct way to implement that - is either as a plain function operating on publicly accessible methods of Texture2D class, - or as a separate Blitter class. Same applies to things such as reading texture from a file, - clearing the texture to a certain color and so forth.

      - -
      Texture class example.
      -
      -class Texture2D
      -{
      -public:
      -                        Texture2D       (const TextureFormat format, const int width, const int height);
      -                        Texture2D       (const char* const filename); // Bad: not core functionality
      -                        ~Texture2D      (void);
      -
      -    // Good methods: essential functionality
      -    Vec4                getPixel        (const int x, const int y) const;
      -    void                setPixel        (const int x, const int y, const Vec4& c);
      -    const deUint8*      getPixelPtr     (void) const;
      -
      -    // Bad: non-essential
      -    void                clear           (const Vec4& c);
      -    bool                containsColor   (const Vec4& c) const;
      -    void                setInitialized  (void); // Why texture would store bit that belongs outside?
      -
      -private:
      -    // Good: essential, minimum data set
      -    vector<deUint8>     m_pixels;
      -    TextureFormat       m_format;
      -    int                 m_width;
      -    int                 m_height;
      -
      -//  deUint8*            m_pixels; // Bad: explicit mem. mgmt, not core functionality
      -    bool                m_initialized; // Bad: extraneous information
      -};
      -
      -// Good: independent functions operating on textures
      -void        clearTexture    (Texture2D& texture, const Vec4& color);
      -Texture2D*  createFromFile  (const char* const filename);
      -
      -

      One sign of a successful class design is that the interface feels natural to use. Thus when - designing a new class from a scratch, you should start by writing the use cases first. Class - interface can be refined until it suits the most important use cases, and only then the - implementation is filled in. Doing things in reverse order often leads to interfaces that are - later found to be inadequate.

      - -

      When writing the internal implementation a lot of thought should be put on maintaining - consistent state, or more formally, class invariant. - Member variables in a class are a form of global state and thus special care must be taken - when manipulating that state. If class requires a lot of state, it can be helpful to group - some of the members into separate state-only classes whose sole responsibility is maintaining - the class invariant for that set of members. Another good pattern is to write a state validation - function that is called in debug builds after each non-trivial state change.

      - -

      Only a minimal set of class member variables should ever be used. If some value can be derived - with a relatively little effort from the minimal set of members, it must not be stored as a - member variable. In the Texture2D class example, length of a pixel row or image size can - be derived from size and format and thus member variables must not be used for them. - - - -

    2. - -
    3. Global state -

      Pretty much everyone can agree that relying on global state is undesirable. However, what - is not always obvious is what counts as a global state. Global variables are clearly such state, - but many more can be considered as well. For example state encapsulated in shared objects, state - retained in library API, or even state passed in member variables between member functions - could be counted as a form global state. Another way to define global state is that it is anything - that can be passed from one function to another without including it in function call arguments.

      - -

      All forms of global state should be used only when necessary. Excluding some very rare cases, - mutable global variables are never necessary. Singletons are really just a fancier version of - global variables. Instead of using for example singleton for application log object, it should be - passed in explicitly to all objects and functions that require logging.

      - - -
    4. - -
    5. Variables vs. immutable values -

      Traditional imperative programming puts emphasis on variables. They are thought of being - limited resource, used for storing immediate computation results for brief periods of time. - In early C days it was even common to declare variable register in order to communicate - the compiler that it should place the variable into a register. Things have changed a lot since - then, and it is no longer necessary to limit use of variables for performance reasons.

      - -

      Functional languages declare variables immutable, i.e. they are not really varying - values, but instead named values. This often greatly improves code clarity and correctness, - as variables can not change unexpectedly. While imperative languages certainly need some amout - of mutability, the concept of immutable values certainly has advantages.

      - -

      As discussed in variable naming section, you often should name a single value, not some - storage slot for arbitrary set of values. In such case it makes a lot of sense to treat that - as immutable named value, not mutable varibale. In C and C++ that can be explicitly declared - with use of const qualifier.

      - -

      In general the amount of state that is considered mutable in any given context should be - minimized. Understanding code is a much more easier if number of things that can change is - small. This also guides code towards natural separation into smaller functions.

      - -

      Limiting number of mutable variables leads to a more functional programming style, where a - lot of computation done in initializer expressions at the beginning of a block. This is not - necessarily a bad thing as it requires separating any non-trivial computation into separate - functions. Most often we only need the result of such computation anyway, and how the - value itself is computed is not important for the problem at hand. - -

      Complex code example.
      -
      -std::vector<Node*> topologicalSortFromRoot (Node* const root)
      -{
      -    // Returning containers is OK if called functions are local and compiler
      -    // can easily do return value optimization.
      -    const std::vector<Node*>    allNodes    = collectAllNodesFromRoot(root); // Reduce number of mutables by computing outside
      -    std::map<Node*, int>        useCounts   = computeUseCounts(allNodes); // Uses allNodes value, mutable
      -    std::vector<Node*>          liveSet;        // Mutable as well
      -    std::vector<Node*>          sortedNodes;    // Used as return value - only appended to
      -
      -    // We have multiple mutables here. Invariant is that each node that has zero in useCount
      -    // must be either in liveSet or sortedNodes, but not in both.
      -
      -    for (std::vector<Node*>::iterator nodeIter = allNodes.begin();
      -         nodeIter != allNodes.end();
      -         ++nodeIter)
      -    {
      -        // Note that nodeIter is not considered mutable here - instead it is iteration-specific
      -        // immutable value.
      -        if (useCounts[*nodeIter] == 0)
      -            liveSet.push_back(*nodeIter); // liveSet is used as return value here
      -    }
      -
      -    while (!liveSet.empty())
      -    {
      -        Node* const curNode = liveSet.back();
      -        liveSet.pop_back();
      -
      -        sortedNodes.push_back(curNode);
      -
      -        ...
      -    }
      -
      -    return sortedNodes;
      -}
      -
      -
    6. - -
    7. Pure functions -

      Pure functions have two properties. Firstly, the result depends only on the input values and - always produces same output value given same set of input values. Secondly, the function does not - cause any observable side effects or changes to global state. For example sin(x) is pure - function as it always returns the same value for same argument value and does not cause any side effects.

      - -

      As much of the code as possible should be kept pure. Moving pure parts of logic and computation - into separate functions is recommended. Unit testing those pure functions is then much easier.

      - -

      Mutating objects passed in counts as a side effect. Instead pure functions must return a completely - new value. This may not always be feasible and some functions may need to be impure for performance - reasons. One way to work around that while remaining as pure as possible is to use separate output-only - argument for output value. Perhaps the most ubiquitous example of such function is memcpy().

      - -
      Examples
      -
      -// Good: pure function (assuming that it doesn't touch global state)
      -vector<int> findUniqueNumbers (const vector<int>& numbers);
      -
      -// Good: single output-only parameter
      -void        findUniqueNumbers (vector<int>& dst, const vector<int>& numbers);
      -
      -// Bad: copying a lot of data for sake of pureness
      -LargeStateObject setStateX (const LargeStateObject& state, const int value);
      -
      -// Bad: manipulates input for no reason
      -void        removeDuplicates  (vector<string>& words);
      -
      -
      -
    8. -
    - - - -
  18. - - - -
- -
- - - - diff --git a/framework/delibs/coding_guidelines/prettify.css b/framework/delibs/coding_guidelines/prettify.css deleted file mode 100644 index 0f1ed7599..000000000 --- a/framework/delibs/coding_guidelines/prettify.css +++ /dev/null @@ -1 +0,0 @@ -.str{color:#080}.kwd{color:#008}.com{color:#800}.typ{color:#606}.lit{color:#066}.pun{color:#660}.pln{color:#000}.tag{color:#008}.atn{color:#606}.atv{color:#080}.dec{color:#606}pre.prettyprint{padding:2px;border:1px solid #888}@media print{.str{color:#060}.kwd{color:#006;font-weight:bold}.com{color:#600;font-style:italic}.typ{color:#404;font-weight:bold}.lit{color:#044}.pun{color:#440}.pln{color:#000}.tag{color:#006;font-weight:bold}.atn{color:#404}.atv{color:#060}} \ No newline at end of file diff --git a/framework/delibs/coding_guidelines/prettify.js b/framework/delibs/coding_guidelines/prettify.js deleted file mode 100644 index 8fc4c9339..000000000 --- a/framework/delibs/coding_guidelines/prettify.js +++ /dev/null @@ -1,23 +0,0 @@ -function H(){var x=navigator&&navigator.userAgent&&/\bMSIE 6\./.test(navigator.userAgent);H=function(){return x};return x}(function(){function x(b){b=b.split(/ /g);var a={};for(var c=b.length;--c>=0;){var d=b[c];if(d)a[d]=null}return a}var y="break continue do else for if return while ",U=y+"auto case char const default double enum extern float goto int long register short signed sizeof static struct switch typedef union unsigned void volatile ",D=U+"catch class delete false import new operator private protected public this throw true try ", -I=D+"alignof align_union asm axiom bool concept concept_map const_cast constexpr decltype dynamic_cast explicit export friend inline late_check mutable namespace nullptr reinterpret_cast static_assert static_cast template typeid typename typeof using virtual wchar_t where ",J=D+"boolean byte extends final finally implements import instanceof null native package strictfp super synchronized throws transient ",V=J+"as base by checked decimal delegate descending event fixed foreach from group implicit in interface internal into is lock object out override orderby params readonly ref sbyte sealed stackalloc string select uint ulong unchecked unsafe ushort var ", -K=D+"debugger eval export function get null set undefined var with Infinity NaN ",L="caller delete die do dump elsif eval exit foreach for goto if import last local my next no our print package redo require sub undef unless until use wantarray while BEGIN END ",M=y+"and as assert class def del elif except exec finally from global import in is lambda nonlocal not or pass print raise try with yield False True None ",N=y+"alias and begin case class def defined elsif end ensure false in module next nil not or redo rescue retry self super then true undef unless until when yield BEGIN END ", -O=y+"case done elif esac eval fi function in local set then until ",W=I+V+K+L+M+N+O;function X(b){return b>="a"&&b<="z"||b>="A"&&b<="Z"}function u(b,a,c,d){b.unshift(c,d||0);try{a.splice.apply(a,b)}finally{b.splice(0,2)}}var Y=(function(){var b=["!","!=","!==","#","%","%=","&","&&","&&=","&=","(","*","*=","+=",",","-=","->","/","/=",":","::",";","<","<<","<<=","<=","=","==","===",">",">=",">>",">>=",">>>",">>>=","?","@","[","^","^=","^^","^^=","{","|","|=","||","||=","~","break","case","continue", -"delete","do","else","finally","instanceof","return","throw","try","typeof"],a="(?:(?:(?:^|[^0-9.])\\.{1,3})|(?:(?:^|[^\\+])\\+)|(?:(?:^|[^\\-])-)";for(var c=0;c:&])/g,"\\$1")}a+="|^)\\s*$";return new RegExp(a)})(),P=/&/g,Q=//g,Z=/\"/g;function $(b){return b.replace(P,"&").replace(Q,"<").replace(R,">").replace(Z,""")}function E(b){return b.replace(P,"&").replace(Q,"<").replace(R,">")}var aa= -/</g,ba=/>/g,ca=/'/g,da=/"/g,ea=/&/g,fa=/ /g;function ga(b){var a=b.indexOf("&");if(a<0)return b;for(--a;(a=b.indexOf("&#",a+1))>=0;){var c=b.indexOf(";",a);if(c>=0){var d=b.substring(a+3,c),g=10;if(d&&d.charAt(0)==="x"){d=d.substring(1);g=16}var e=parseInt(d,g);if(!isNaN(e))b=b.substring(0,a)+String.fromCharCode(e)+b.substring(c+1)}}return b.replace(aa,"<").replace(ba,">").replace(ca,"'").replace(da,'"').replace(ea,"&").replace(fa," ")}function S(b){return"XMP"===b.tagName} -function z(b,a){switch(b.nodeType){case 1:var c=b.tagName.toLowerCase();a.push("<",c);for(var d=0;d");for(var e=b.firstChild;e;e=e.nextSibling)z(e,a);if(b.firstChild||!/^(?:br|link|img)$/.test(c))a.push("");break;case 2:a.push(b.name.toLowerCase(),'="',$(b.value),'"');break;case 3:case 4:a.push(E(b.nodeValue));break}}var F=null;function ha(b){if(null===F){var a=document.createElement("PRE"); -a.appendChild(document.createTextNode('\n'));F=!/=0;i-=" ".length)d.push(" ".substring(0,i));g=e+1;break; -case "\n":a=0;break;default:++a}}if(!d)return c;d.push(c.substring(g));return d.join("")}}var ja=/(?:[^<]+|