0

Status Quo

For a project of mine I need a client library that communicates with my API for every major programming platform. Currently I implemented just one (Java) and was thinking 'I don't want to do this 8 times (or hope someone else will)'.

The client is relatively small, but not trivial; does mostly JSON reading/writing and sending TCP/UDP data over SSL. Every call to the client is fire-and-forget, so it works completely asynchronously in its own thread.

Problem

I was asking myself if it made sense to write a single C library and integrate it with the other platforms.

I did a bit of research and it seems every platform deals with this differently (obviously) with varying necessary efforts. I also realised that I never saw something like it - for example database drivers always seem to be written from scratch rather than using a C library at the core. Is the overhead too big?

I also read about Thrift, Protocol Buffers etc. - but this seems to be aimed at network interoperability?

Question

So the final question is:

Is it feasible to use a single C library at the core of each platform's client? If yes: how should it be done?

stephanos
  • 3,319
  • 7
  • 33
  • 47
  • I think it's reasonable. C is the greatest common divisor of programming languages when it comes to multiplatform native development; writing the core in C and making bindings for it is usually the way to go. –  Dec 25 '12 at 18:24
  • would you know an open source project like this that has 6+ bindings available, so I could learn from it? – stephanos Dec 25 '12 at 18:28
  • well, off the top of my head, I don't have anything useful, but you might want to have a look at how CPython implements native bindings. It's a nice example of scripting <-> native interaction. –  Dec 25 '12 at 18:29
  • I found a good example: ZeroMQ - it appears to have bindings for a lot of languages: http://www.zeromq.org/bindings:_start – stephanos Dec 26 '12 at 08:24

1 Answers1

2

Using a C library makes sense if you want to consolidate all implementations of the same functionality into one piece of code - it is probably the only language that can be universally used by higher level languages.

Your work would be significantly easier if you could automate the process to a degree. You might want to have a look at SWIG. It is a binding generator that allows C/C++ code to be used with a large number of other programming languages, including most, if not all, of the languages that you mentioned.

For my rather superficial experience with it, SWIG does a rather decent job, although the generated code does occasionally need some tweaking...

thkala
  • 84,049
  • 23
  • 157
  • 201