C+- ( C plus minus )

2024-05-21 (last update) / (published at) 2024-02-29


Note: This article is intended to be brief while providing enough information to be of value to the reader.


What is "C+-" ?

  • A subset of C++ language with additional code conventions.
  • A collection of libraries written in a special way.

"C+-" as a subset of C++:

  • No RTTI.
    • Enforced by compiler flags.
  • No exceptions.
    • Enforced by compiler flags.
  • No multiple inheritance.
    • Enforced by compiler flags where available, else by a code checker tool.
    • Note: single inheritance is allowed.

"C+-" additional code conventions:

  • A class/struct should have a default constructor.
  • A class/struct should use constexpr constructors.
  • A class/struct should have move-constructor and move-assignment enabled (explicit declared or default, by case).
    • Tests should check for the existence of move-constructor and move-assignment.
  • No "extern" keyword.
    • Enforced by a code checker tool.
  • No "mutable" keyword.
    • Enforced by a code checker tool.
  • No lambda constructs.
    • Enforced by a code checker tool.
  • Avoid syntactic saccharin.


  • Note the term used for the full context:
    • "should" to encourage consistent expected behavior.
    • Not "shall", which can lead to complicated code to pursuit a perfect common template everywhere. "shall" has its place in appropriate smaller contexts.

"C+-" libraries main code conventions:

  • Error handling aproach:
    • A function return is preffered to be boolean: true for success, false(zero) for error.
    • A function which returns a pointer will return either a valid pointer either nullptr.
    • A function which returns a pointer to a class/struct will return either a valid pointer to a valid object either nullptr.
    • An object or data structure is either entirely valid or uninitialized. A validation method (simple condition, flag, or function) must be available for this entity.
  • Public functions should not crash when non-valid arguments are given.
    • Functions should Not call other unsafe functions with non-valid arguments, when those unsafe functions are known to crash. e.g. Avoid calling standard C library functions with null pointers and/or no bounds checks.
  • There is no "warning" error level. The logical result is either "succes" either "error".
    • Where detailed error indication is required, specific data containers can be used. These data containers must always be valid and accessible from outside the scope of the function.
  • Return parameters, where used:
    • Should be placed at the start of arguments.
    • Return parameter names shall be visually marked by code conventions in addition to their return types.
  • Templates are allowed. However:
    • For 100% tests coverage a template-to-C++ converter can be used. This will replace the typename/class with the desired type.
  • Prefer data-oriented structures over logic-oriented generic classes.
  • Use the fail fast approach.
  • Prefer references over pointers.
  • Prefer to avoid allocating data in libraries, but provide safe and tested allocation/deallocation methods where necessary (eg containers).

Build-chain configuration for "C+-":

  • Enable compiler warnings for potentially wrong code.
  • Enable code checkers.
  • Enable tools which will check for unwanted syntax which is allowed by the C++ compiler. e.g. At least one code-checker tool will not allow lambda constructs.
  • The compiler must support C++17 or C++14.
    • "constexpr" in C++11 was too restrictive to allow chaining.

Why "C+-" ?

  • C++ and C are great, mature and already widely used programming languages.
  • For these C++ and C advantages: runtime speed, consistent runtime behavior.
  • For projects developed by humans: code quality and clarity, shorter product lead time.
  • C+- aims for reliability, safe and clear code.

History:

  • This flavor of "C+-" and its libraries began to exist in early 2020.
  • By the end of 2020, the first mature version was used in public binaries.


Notes:
  • Only core concepts were listed here.

    • The reasons for choosing for "C+-" one trait or another are derived from experience and good-practice. The reasoning behind this selection is beyond the scope of this article.
    • New features from future C++ standards may be added in the future as long as they fit the goals and conventions of C+-.
  • Let us not forget that C+- exists because of the prior existence of C and C++.

  • C+- depends on the compiler and the underlying libraries. As with any programming language, for that matter.

  • "C+-" similar flavors:

    • At the time C+- was created, there were no known definitions or implementations close enough.
    • In 2020 the main web search engines did not return any relevant results for the name "C+-". Pronunciation: "C plus minus".
    • There is no relation to the good joke article "C more or less" published by FSF (in 2021 most likely).
  • These concepts written here can be used by anyone.

    • How & what someone decides to implement these concepts depends on the particular goals and knowledge.
    • This article can inspire anyone to create a new and hopefully better flavor (at least for the creator).
    • So, in the future, who knows? New similar descriptions may appear!


Have fun! ;)

Previous Article Next Article

..