When D feels unfinished: union initialization and NRVO

FeepingCreature feepingcreature at gmail.com
Wed Mar 18 09:12:31 UTC 2020


On Wednesday, 18 March 2020 at 07:17:05 UTC, Denis Feklushkin 
wrote:
> On Wednesday, 18 March 2020 at 06:55:24 UTC, Mathias Lang wrote:
>> So I've been toying around for a bit with writing a 
>> deserializer in D. It essentially converts types to an array 
>> of `ubyte[]` in a very simple way. Handles value types 
>> automatically, and pointers / arrays. Nothing too fancy, but I 
>> wanted to write something *correct*, and compatible with the 
>> types I'm dealing with.
>>
>> The issue I was faced with is how to handle qualifiers. For 
>> example, deserializing `const` or `immutable` data. 
>> Originally, my deserializer accepted a `ref T` as parameter 
>> and would deserialize into it. I changed it to return an 
>> element of type `T`.
>
> IMHO serialization of language level 
> types/objects/another_abstractions is the same kind of 
> deceiving goal as ORM, "all is object", etc.
>
> If you move to the higher level - serialize objects (in terms 
> of your software, not just OOP objects) that you are modeling - 
> this problem will gone.

Strongly disagree. Serialize objects, sure, events and entities 
and aggregates, all that good shit, but at the end of the day 
you'll still need a ground-level way to serialize domain values, 
ie. arrays, structs, strings, ints, floats, dates, Options, 
Nullables... basically anything that can be easily represented in 
JSON, stuff that can't be high-level serialized because it is 
*itself* the low level primitives that your high level semantics 
are built on. 90% of the loc effort of serialization is in those 
glue types, and they're very feasible to handle automatically in 
D. (Thank goodness.)

And yes, immutable is just an unending headache with that, though 
something like boilerplate's autogenerated builder types helps a 
lot ime, because you don't need to mixin constructor calls but 
can just assign to fields (immutable or not) and do the 
construction in one go at the end.



More information about the Digitalmars-d mailing list