Hacker News new | ask | show | jobs
by jstimpfle 1791 days ago
I think writing a JSON parser should be perfectly fine, it's quite a simple format (while imperfect and probably way overused). I would say 50 lines of header + 500 lines of .cpp file should be plenty to write a solid reusable implementation that parses to a generic tree (dicts, lists, float/string/bool literals). Should be doable in an afternoon.

But if you disagree, you should try a particular, very popular JSON library for C++ (removed the mention of the name here, you can figure it out on your own if you want).

Last I checked, a git clone of this library downloaded 260 Megabytes of data. The project consists of many many files, but most notably it is a C++ header-only library consisting of 24000 lines of header files to be included into every (transitively) dependent .cpp file.

When you run "g++ -E" on it (to do the preprocessing step only) those 24000 lines will unfold to about 84000 lines.

Just write a short test.cpp with #include <THIS JSON LIBRARY.h> in it and add a int main() { printf("Hello, world\n"); }. Compiling this with "g++ -c" takes about 1 sec on my laptop.

Add a tiny amount of code that "parses" the string literal "3" (which I think is not valid JSON actually. But anyway) and compile + link. Takes 2 secs on my laptop. With -O2, I'm at 3.5 seconds.

Imagine writing a larger project with many many .cpp file that include a header file that publishes such a dependency. Or just imagine compiling a project where multiple .cpp files directly include this thing.

It's a truly sad time to be a programmer.

1 comments

I don't think full size of the git clone is relevant information. You can always do a shallow clone.
I think your statement that it doesn't matter is kind of making my point.