When D feels unfinished: union initialization and NRVO
FeepingCreature
feepingcreature at gmail.com
Wed Mar 18 13:28:50 UTC 2020
On Wednesday, 18 March 2020 at 09:52:35 UTC, Denis Feklushkin
wrote:
> On Wednesday, 18 March 2020 at 09:12:31 UTC, FeepingCreature
> wrote:
>> 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.
Sure, but the limit is "anything with 'uses'-relations" -
anything that contains a non-exclusive reference is hard to
serialize. My point is that excluding these objects still leaves
80% of the typesystem, including structs, arrays, hashmaps,
sets... The reference to "things that can be easily encoded as
json" was not accidental - the common trait here is exactly that
JSON doesn't support pointer types, so you can't get a reference
cycle or in fact nonlocal reference at all. So pointers are out,
objects are largely out; structs, hashmaps and arrays (of
similarly simple types) are very much in, because they are types
that generally own their subtypes. Limiting to those types lets
you do easy, performant one-pass serialization.
If you're looking at a type that creates another class in its
constructor, calls a method on another value, or has fields that
should be excluded from serialization, then that type is probably
too complex to be automatically serialized. On the other hand,
stuff like structs that are just a bundle of public/read-only
fields with little internal logic are both easy and very common.
More information about the Digitalmars-d
mailing list