risingtyde.github.io

Integrity Checking

Intoduction

This readme covers the general philosophy behind the Integrity libraries, which share a common interface across multiple languages. The individual language implementations are: Language|Link ——–|—- Python | GitHub integrity for python JavaScript | GitHub integrity for JavScript (node & browser) c# | GitHub integrity for c# c++ | GitHub integrity for c++

The intention is to provide a common interface so that as you switch between languages you can add integrity checks without having to remember different functions, or how they work. There are a set of core functions and some languages have some extra functions added to help with type checking.

What is an integrity check?

Integrity checks should indicate that a coding error has occured. If an integrity check fires in the field, or in testing, it means a code change is required, either

Integrity checks should not be used for:

If in doubt ask: ‘If this check fires, does it automatically indicate a coding error?’ If the answer is yes, then use an integrity check. If no, then do some other form of error checking.

Aren’t Integrity checks the same as asserts?

The philisophical intention is somewhat similar, but the asserts themselves are mad, bad, and dangerous to know.

Asserts are mad

The implementaiton of assert across varuious languages is perplexing, to say the least. Here are some of the issues:

Aren’t Integrity checks just the same as: if(check) { throw } ?

Yes, they are. If you prefer writing the checks explicitly then knock yourself out. The Integrity libraries are just helpers to make life a little bit easier. Just to be clear (using Python for the example),

Integrity.check(a == b, "Oopsies", a, b)

is the same as:

if(a != b):
    raise ValueError("Oopsies, " + str(a) + ", " + str(b))

The advantages of using the Integrity library are:

Having said all that, the critical thing is that the check is made, and it doesn’t really matter whether you use the Integrity library or not, it is just a helper which is consistent across languages, which is nice if you jump between languages.

The philosophy behind the Integrity libraries

Don’t introduce new exceptions

The libraries all use exception classes which already exist in the native languages. This means that there is no need to indroduce a dependency on the Integrity library in the catching code.

Be as performant as possible

Perfromance is prioritised, which means:

Be as safe as possible

Be as consistent across languages as possible

The message building part is the same across all languages, but there are some minor variations in the function names to accommodate language idiosyncracies: