We try and adopt the default styles used in each programming language but there are aspects which apply to all repos. These are described below.
Thus spake the Master Programmer:
The below rules apply to all programming languages. Check back regularly for changes and clarifications.
The folling rules always apply:-
// Copyright 2020-2021 Herald Project Contributors
// SPDX-License-Identifier: Apache-2.0
&&
or ||
at end of each line, not the startThere are som apparently trivial style changes we mandate for performance reasons:-
Write a test first, see it fail, write just enough until it passes. Repeat.
Whilst not strictly a style, it ensures all new code has tests.
The following are things you should think of when writing tests:-
Where a static value or constant is compared against a variable’s value, the variable is always to the RIGHT of the (in)equality operator.
CORRECT SYNTAX: null == myVar
INCORRECT SYNTAX: myVar == null
If you miss the final ‘=’ symbol as in the incorrect syntax, you will set the value of the variable rather than compare it. In most languages this operation returns true, which means it still compiles. This leads to hard to find logic errors. Writing the comparison around this way prevents this error and throws a compilation error instead. This is much safer. It is a habit worth forming.
We compile against Java 8 as standard and Android SDK 21 as we have to support a very wide range of phones. SDK 21 allows us to support all Android phones that have Bluetooth Low Energy support, globally.
Where version-specific functionality is required it MUST NOT reduce interoperability or epidemiological efficacy in older versions.
You MUST support SDK 21 and above if you have if/else statements for OS versions.
The following rules apply in addition to the all languages rules:-
We target Swift 5 but iOS 9.3+. This allows us to support all iOS phones that support Bluetooth Low Energy, globally.
Default as per XCode.
We try to keep the same file names as the Java and C++ equivalents, even though you can declare multiple classes in a single source file. This makes locating code easier.
Exceptions are enumeration types, constants, and inner classes.
We use C++17 with no compiler extensions as standard. We do not rely on API above this version. STL use is allowed if of the same version.
#define
’s rather than #pragma once
, with HERALD_
as the start of the define name{
at the end of the lines{
at the end of the line{
and }
on their own lines, without indent.We try to keep the same file names as the Java equivalents, even though you can declare multiple classes in a single source file. This makes locating code easier.
Exceptions are enumeration types, constants, and inner classes. (E.g. Impl idiom)
Continue in this guide by visiting: Committing code.
To help you get started, see the documentation.