C to D bindings: how much do you D-ify the code?
Jakob Ovrum
jakobovrum at gmail.com
Fri Oct 25 10:22:22 PDT 2013
On Friday, 25 October 2013 at 13:10:05 UTC, Lionello Lunesu wrote:
> These are some of the more trivial ones, but I'd like to see
> how other people go about making bindings. Do you keep as close
> to C as possible? Or do you "add value" by using more D style
> constructs?
>
> L.
I also think keeping the C bindings as faithful as possible is
the best, correct even, approach. By keeping the C bindings
faithful, one can defer to the existing documentation of the C
library, and user code can be ported from C trivially.
In a good wrapper, the C bindings are present only because the
second layer depends on them and for compatibility purposes,
while the second layer - the idiomatic D interface - should cover
all use cases. I've found that with D's expressive modelling
power and metaprogramming capabilities, the second layer does not
need to compromise on performance or functionality while
providing a safer, more intuitive and more convenient interface.
More information about the Digitalmars-d
mailing list