{"id":2241,"date":"2018-09-08T10:24:54","date_gmt":"2018-09-08T15:24:54","guid":{"rendered":"https:\/\/bitpost.com\/news\/?p=2241"},"modified":"2018-09-11T10:55:38","modified_gmt":"2018-09-11T15:55:38","slug":"the-ultimate-dry-always-generate-your-code-from-json-schema","status":"publish","type":"post","link":"https:\/\/bitpost.com\/news\/2018\/the-ultimate-dry-always-generate-your-code-from-json-schema\/","title":{"rendered":"The ultimate DRY: Always generate your code from JSON schema"},"content":{"rendered":"<p>I spent this morning exploring available tech to address this goal:<\/p>\n<blockquote><p>Add a bigdata database to my application, to archive older data out of the realtime local model<\/p><\/blockquote>\n<p>This is for my stock app, which deals with realtime in-memory data during market hours, with a delayed-write to local storage.\u00a0 At the end of the day, it can then archive most of the data collected during market hours.<\/p>\n<p>Because I have not achieved &#8220;success&#8221; in life yet, at least enough to allow me to pursue my larger goals uninhibited, I have to be very careful about how I apply my limited resources.\u00a0 To be more precise:<\/p>\n<ul>\n<li>Follow patterns that are as simple as possible (but no less), and sustainable into the next decade.<\/li>\n<li>For my projects, limit languages, libraries and tools to those that are\n<ul>\n<li>well maintained<\/li>\n<li>solve difficult problems more elegantly than I could solve with a medium level of effort<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>The result of today&#8217;s philosophically-informed research:<\/p>\n<ul>\n<li>The primary languages of my software projects should be Javascript and C++<\/li>\n<li>All data should be defined by JSON schema that is used to generate code, via\u00a0<a href=\"https:\/\/github.com\/quicktype\/quicktype\">quicktype<\/a><\/li>\n<li>Long-term libraries and tools include boost, jquery, bootstrap, accounting.js, moment.js, nlohmann::json, sqlite, postgres<\/li>\n<\/ul>\n<p>Note that using quicktype with nlohmann::json is an elegant way to effectively get C++ reflection.\u00a0 Once you serialize an object to JSON you can walk all its fields.\u00a0 Then you can do things like automatically build SQL queries for your classes based on the JSON schema.\u00a0 Beautiful.<\/p>\n<p>PS. I avoided spotify-json, StaticJson\/autojsoncxx, Google Prototype Buffers, Code Synthesis&#8217;s ODB, the sqlite\u00a0JSON1 Extension, C++ reflection libraries like <a href=\"https:\/\/www.rttr.org\/\">RTTR,<\/a>\u00a0lots of code from\u00a0<a href=\"https:\/\/stiffstream.com\/ru\/\">Stiffstream<\/a>\u00a0and <a href=\"https:\/\/www.example-code.com\/cpp\/default.asp\">Chilkat<\/a>,\u00a0etc. because while they are all brilliant and compelling, they bring extra weight.\u00a0 The world keeps churning though, <a href=\"https:\/\/stackoverflow.com\/questions\/118945\/best-c-c-network-library\">so<\/a> <a href=\"http:\/\/www.stroustrup.com\/applications.html\">keep<\/a>\u00a0<a href=\"https:\/\/github.com\/fffaraz\/awesome-cpp\">searching<\/a>.\u00a0 Also, there are cases where my choices do not fit, most obviously being cross-platform mobile apps, which will have to be saved for another post&#8230; \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I spent this morning exploring available tech to address this goal: Add a bigdata database to my application, to archive older data out of the realtime local model This is for my stock app, which deals with realtime in-memory data during market hours, with a delayed-write to local storage.\u00a0 At the end of the day, [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"enabled":false},"version":2}},"categories":[204,22,216,4],"tags":[294,103,293,205,295,296,297,261],"class_list":["post-2241","post","type-post","status-publish","format-standard","hentry","category-a-better-trader","category-cpp","category-node-js","category-projects","tag-accounting-js","tag-boost","tag-bootstrap","tag-jquery","tag-moment-js","tag-nlohmannjson","tag-postgres","tag-sqlite"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9M11L-A9","jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/bitpost.com\/news\/wp-json\/wp\/v2\/posts\/2241","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bitpost.com\/news\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bitpost.com\/news\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bitpost.com\/news\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/bitpost.com\/news\/wp-json\/wp\/v2\/comments?post=2241"}],"version-history":[{"count":5,"href":"https:\/\/bitpost.com\/news\/wp-json\/wp\/v2\/posts\/2241\/revisions"}],"predecessor-version":[{"id":2248,"href":"https:\/\/bitpost.com\/news\/wp-json\/wp\/v2\/posts\/2241\/revisions\/2248"}],"wp:attachment":[{"href":"https:\/\/bitpost.com\/news\/wp-json\/wp\/v2\/media?parent=2241"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bitpost.com\/news\/wp-json\/wp\/v2\/categories?post=2241"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bitpost.com\/news\/wp-json\/wp\/v2\/tags?post=2241"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}