I have written some poll questions concerning the design trade-offs involved in making a good `SafeInt`/`CheckedInt` type. They are about the actual semantics of the API, not the internals, nor bike-shedding about names.

(`SafeInt` and `CheckedInt` are integer data types which use `core.checkedint` to guard against overflow, divide-by-zero, etc. Links to current work-in-progress versions by

1) Robert Schadek (burner):
    https://github.com/D-Programming-Language/phobos/pull/3389
2) Myself (tsbockman):
    https://github.com/tsbockman/CheckedInt)

For the purposes of this poll please assume the following (based on my own extensive testing):

1) Code using checked operations will take about **1.5x longer to run** than unchecked code. (If you compile with GDC, anyway; DMD and LDC are another story...) 2) The main design decision with a significant runtime performance cost, is whether to throw exceptions or not. With some optimization, the hit is modest, but noticeable. 3) Even if the API uses exceptions some places, it can still be used in `nothrow @nogc` code, at the cost of some extra typing.

Two further points I would ask the reader to consider:

* A checked integer type is fundamentally semantically different from an unchecked type. The difference is of similar magnitude to that of floating-point vs fixed-point. * It might be wise to read the entire poll before answering it - the questions are all related in some way.

The poll results are here, if you wish to preview the questions:
http://polljunkie.com/poll/kzrije/checked-integer-type-behaviour/view
When you are ready, please take the poll yourself:
http://polljunkie.com/poll/cytdbq/checked-integer-type-behaviour

Thanks for your time.

Reply via email to