▲ | Show HN: Zig-DbC – A design by contract library for Zig | |||||||||||||||||||||||||||||||||||||||||||
45 points by habedi0 6 days ago | 11 comments | ||||||||||||||||||||||||||||||||||||||||||||
Hi everyone, I've made an open-source library for using design by contract (DbC) principles in the Zig programming language. It's called Zig-DbC, and it currently provides the following features: - A simple API to define preconditions, postconditions, and invariants. - Contracts are active in `Debug`, `ReleaseSafe`, and `ReleaseSmall` modes to catch bugs early. - All checks are removed at compile time in `ReleaseFast` mode for zero performance cost. - An optional mode to handle partial state changes in functions that return errors. - Transparent error handling that propagates errors from your code to the caller. Project's GitHub repo: https://github.com/habedi/zig-dbc | ||||||||||||||||||||||||||||||||||||||||||||
▲ | metalliqaz 3 days ago | parent | next [-] | |||||||||||||||||||||||||||||||||||||||||||
This is pretty cool, I like to see this kind of project coming to Zig. Zig's compile-time language features make DbC a natural fit. I am not yet proficient enough in Zig to be able to evaluate how well the syntax fits into idiomatic Zig. Good work. | ||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||
▲ | skyzouwdev 3 days ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||||||||||||||
Nice! Always thought DbC was underused outside of languages like Eiffel. Cool to see it brought to Zig with zero-cost checks in ReleaseFast — that’s a solid balance between safety and performance. | ||||||||||||||||||||||||||||||||||||||||||||
▲ | skavi 3 days ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||||||||||||||
Why are the checks included in ReleaseSmall? | ||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||
▲ | Defletter 3 days ago | parent | prev [-] | |||||||||||||||||||||||||||||||||||||||||||
Another project burdened by Andrew Kelley's weird hate-boner for function literals.
How ridiculous that this is required to do something so simple. | ||||||||||||||||||||||||||||||||||||||||||||
|