Blog series to teach and show off D's metaprogramming by creating a JSON serialiser

Steven Schveighoffer schveiguy at gmail.com
Mon Nov 11 16:56:31 UTC 2019


On 10/30/19 8:05 PM, SealabJaster wrote:
> https://bradley.chatha.dev/Home/Blog?post=JsonSerialiser1
> 
> Currently only the first post is out, as I'd like to collect feedback 
> before writing any more.
> 
> The series is aimed at people new to D, or people who have heard of D, 
> but haven't really explored its metaprogramming too much, hence certain 
> things such as calling D's metaprogramming "often overlooked" as that 
> tends to be true for non/new users of D.
> 
> Sorry in advance if this is the wrong forum group to post to, I didn't 
> know whether to put it here or in the Learn group.
> 
> Future plans for this series:
>   * Serialising structs (next up).
> 
>   * Serialising enums via their names, rather than values (and certain 
> complications such as is(SomeEnum == int) being true).
> 
>   * Serialising classes.
> 
>   * Using UDAs to let classes and structs customise their fields.
> 
>   * Using __traits(compiles) to determine if a struct or class 
> implements a custom (de)serialisation function.
> 
>   * Trying to think of how I can shoe horn mixin templates in, just so 
> they're shown off.
> 
> I'm welcome to any other ideas to try and fit into the series. The 
> serialiser won't be overly robust in terms of edge cases (such as nested 
> classes/structs needing to be filtered out sometimes), but I'll try to 
> mention them and provide a workaround where possible.
> 
> I've also taken to certain decisions in the code snippets, to try and 
> reduce the amount of things I need to explain at once, and to hopefully 
> make things more readable. e.g. Using "const string" instead of just 
> "const" or "enum" (and then having to explain why not to use "enum" for 
> strings), giving all if and else statements brackets to make things more 
> readable (that's the plan at least), etc.
> 
> As for release schedule, I'm planning on getting at least one post out a 
> week.
> 
> Other than feedback for the actual content of the blog, I'd also 
> appreciate any feedback on visual style of the blog, since I'm quite a 
> novice at CSS, let alone writing things like this.
> 
> While I'm not really capable of contributing to D in terms of improving 
> phobos, or writing quality libraries, I'm hoping to at least be able to 
> provide some educational material on what I feel makes D worth it as a 
> way of contribution.

Looks like a great idea! Sounds very similar to what I've been learning 
over the past 5 years or so.

See my dconf presentation from this year.

Also, if you want some inspiration for serialization/deserialization, 
check out jsoniopipe: http://code.dlang.org/packages/jsoniopipe

Simply put, I think it's great to use D overloading as much as possible 
instead of static if (reading your first article). OK, now reading the 
"alternate function layout", I see you did do that :) That's how I did 
mine, and I think it reads much nicer.

-Steve


More information about the Digitalmars-d-announce mailing list