Re:Show HN: Parson, lighweight json parser in C
by huhtenberg on Sunday October 28, 2012 @03:33PM
(#4709738)
> json::Array commits = root_value.get_array();
You probably meant:
json::Array & commits = root_value.get_array();
Don't really want to copy an array there, right? After that you'll probably be tempted to use std::vector as a basis for json::array. Then you'll realize what an abysmal PoS default vector allocator is, and so you'd want to allow customizing it. Hello templates, and then before you know it, the whole thing not only looks like one of them incomprehensible boost beauties, but also compiles into a meg of code with a dozen dependencies. Neat :)
Re:Show HN: Parson, lighweight json parser in C
by zokier on Sunday October 28, 2012 @03:53PM
(#4709785)
> After that you'll probably be tempted to use std::vector as a basis for json::array. Then you'll realize what an abysmal PoS default vector allocator is, and so you'd want to allow customizing it. Hello templates, and then before you know it, the whole thing not only looks like one of them incomprehensible boost beauties, but also compiles into a meg of code with a dozen dependencies. Neat :)
Writing good code means having discipline to resist all sorts of temptations, such as the one you describe. And not all slippery slopes are actually all that slippery.
The one good thing about C++ is that you can pick the features you want and mostly ignore the rest. The reason C++ is so humungous is that everyone is using different subset of it.
Re:Show HN: Parson, lighweight json parser in C
by huhtenberg on Sunday October 28, 2012 @04:23PM
(#4709862)
> The reason C++ is so humungous is that everyone is using different subset of it.
I completely agree with this. Incidentally, this is exactly the reason why C++ libraries are far less useful than the C ones.
Re:Show HN: Parson, lighweight json parser in C
by malkia on Sunday October 28, 2012 @04:06PM
(#4709831)
RAII would break you if longjmp/setjmp are used. For example if you had the code in C++, but with "C" externs (like zeromq for example), then using RAII might bite someone unexpected where longjmp/setjmp would not unwind and call the destructors.
Key differences:
* actual namespaces, no need to prefix everything with "JSON_"
* RAII-style resource management, no need for "json_value_free" etc
* objects, so instead of get_array(root_value) you have root_value.get_array()