Thursday, March 12, 2015

JSON

JSON (JavaScript Object Notation) is a language that describes structured data.

It features:
  • Simple "atomic" data: numbers, strings, boolean, and a "null" value.
  • Arrays, i.e. sequences of successive values.
  • Dictionaries ("objects" in JSON parlance), which simply are bunches of values indexed by string keys.
That's all. And that's enough.

I fell in love with JSON a few years ago. The reasons are both functional and technical.

Functionally, JSON is the result of what XML failed to be: a simple data exchange format with a straightforward ecosystem (no DTD, schema, validation, tools over layers and layers of tools and libraries), no frivolities (e.g. no data vs. attribute wars).

Technically, the JSON parser is also very simple. Its grammar is a straightforward descending grammar with no rollbacks. It means that at each point in the JSON text, given the past and current letter, you know exactly what may follow. If it fails: syntax error, out.

Since I love that format I had to build my own parser library: YacJP. That library allows to read and write JSON data using any kind of UTF-8 character streams, including simple C strings, file descriptors, and POSIX files.

It was the first of a few projects that followed in the same "object-like" style.

There will be more to follow... stay tuned!

Monday, March 2, 2015

ExPerience

A few days ago, I came across a very cool tool: Petit.

That tool helps filter standard Linux logs. Since I have my own (small) server, I need that kind of tool.

My server is really small: a Cubieboard, with a Debian distro. It has an internet façade so I must at least cursolily read its logs. That's, hem, tedious. I am not at ease with the admin side of machines.

Back to the topic: Cubieboard is good, but it is not fast. Petit is written in Python; I needed something faster. So I wrote ExP, a Petit clone in plain C.

Well, "plain" is not really accurate. I am an object hacker deep inside. My C code is written in a modular fashion with a lot of encapsulation (static functions) and interfaces (structs with functions).

I find that way of programming usually enough to implement a basic OO design; the remaining of the object paradigm is usually useful in very few cases. When I need that, I switch to Eiffel, but most people won't follow there. Oh, well...


The project | Debian packages