On Wed, Jan 23, 2013 at 2:18 AM, Motiejus Jakštys <
desir...@gmail.com> wrote:
> On Wed, Jan 23, 2013 at 6:54 AM, Anton Lavrik <
ala...@piqi.org> wrote:
>>
>> yours. You can read more about it here:
>>
http://piqi.org/doc/piqi/#extensions
>
> Thanks. I looked at them, but didn't realize that I can extend
> multiple models at once. This completely covers my use case.
Great!
I don't know what I was thinking yesterday... Your original question
has nothing to do with structured inheritance of any sort. Moreover,
there is a native support for your use case without even using
extensions. It is as simple as this:
piqic-erlang already turns
.variant [
.name primitive-value
.option [ .type float ]
.option [ .type int ]
.option [ .type string ]
]
.variant [
.name filter-parm
.option [ .type primitive-value ]
.option [ .type order ]
]
into
-type(t_primitive_value() ::
{float, number()}
| {int, integer()}
| {string, string() | binary()}
).
-type(t_filter_parm() ::
t_primitive_value()
| {order, t_order()}
).
>> I deliberately chose no to deal with inheritance in Piqi, however
> Out of curiosity, why? (I don't suggest it's good, rather just want to
> know why).
There are several main reasons.
First of all, modeling data using structured inheritance is very hard.
It is hard to get hierarchies right -- this topic comes in various
flavors: 1) whether something should inherit another thing or include
it; 2) often times people would use inheritance in order to take a
shortcut and use inheritance even though the logical relationship
between the two objects is unclear and/or can't be established; 3) new
facts (e.g. new data structures) can change your perspective on
previous inheritance decisions; 4) overall, there's no single unified
view on inheritance among people who use it -- this makes everything
highly subjective and this is a really bad thing for protocol design.
Second of all, all those difficulties and ambiguities cause people to
constantly reconsider and refactor their specifications. Needless to
say, this is a bad idea for protocols that need to be stable, portable
and backward compatible with previous versions.
These problems don't have clear solutions other than banning
inheritance use altogether and modeling data in a very direct and
obvious way.
Anton