When D feels unfinished: union initialization and NRVO

Denis Feklushkin feklushkin.denis at gmail.com
Wed Mar 18 09:52:35 UTC 2020


On Wednesday, 18 March 2020 at 09:12:31 UTC, FeepingCreature 
wrote:
> 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...

I prefer do not mix types and arrays of typed values here, and 
other like structs or objects in this list, which include "raw" 
typed values.

Some D language constructs (aggregates) just cannot be serialized 
automatically by design and you need to manually reinvent some 
constructors or special functions for this purpose.

This situation is no different from that you will still need to 
explain to the serializer how to correctly serialize a some 
complex object so that no duplication or data loss occurs.



More information about the Digitalmars-d mailing list