Question

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?

Was it helpful?

Solution

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...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top