develooper Front page | perl.perl5.porters | Postings from May 2013

Re: Proposal: initial type annotation in SV

Thread Previous | Thread Next
From:
Aristotle Pagaltzis
Date:
May 6, 2013 17:16
Subject:
Re: Proposal: initial type annotation in SV
Message ID:
20130506171558.GB18355@fernweh.plasmasturm.org
* Dave Mitchell <davem@iabyn.com> [2013-05-06 13:15]:
> For this scenario, there would have to be some reliable method for the
> programmer to force the serialiser to use floats; there are many
> posibilites, depending on circumstances. For example:
>
>     * the serialiser documentation could state that for things to be saved
>       as floats, you must do *= 1.0 shortly before saving;
>     * the serialiser could have a global setting saving whether it
>       preferred int or float or string when more than one was valid;
>     * the serialiser could have some sort of format specifier;
>     * etc.
>
> This is not of course to preclude the possibility of making
> serialisers "better behaved" in the absence of explicit programmer
> request, e.g. by recording the initial state, or by doing more clever
> things with the public/private flags.

The thing is, if serialisers could use the initial type for this, then
the programmer can signal her intent to the serialiser in-band but
unobtrusively. With other approaches, you have to maintain some form of
parallel data structure, or you have to deform the data structure under
serialisation to signal intent structurally, or you have to meddle with
the values in ways that are visible to other code (such as swapping in
JSON::true and JSON::false values). In contrast, after using `+= 0.0`
to signal serialise-as-float, you can keep right on using the same data
structure in the rest of your code – an in-band unobtrusive signal.

Regards,
-- 
Aristotle Pagaltzis // <http://plasmasturm.org/>

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About