* Subtype or derived type?
@ 2017-10-07 16:19 Victor Porton
2017-10-07 16:23 ` Victor Porton
2017-10-09 21:50 ` Randy Brukardt
0 siblings, 2 replies; 4+ messages in thread
From: Victor Porton @ 2017-10-07 16:19 UTC (permalink / raw)
While developing (thick object oriented) bindings for a C library:
I have developed a package containing Term_Type type with bindings
for raptor_term type:
https://github.com/vporton/redland-bindings/blob/ada2012/ada/src/rdf-raptor-term.ads
Term_Type represents pointer C type raptor_term* (where raptor_term
is a struct).
Now I am developed bindings for librdf_node which is defined as:
typedef raptor_term librdf_node;
Now I ask advice how to define the type representing librdf_node*
pointer type.
I have two variants in mind:
1.
subtype Node_Type is Term_Type;
2.
type Node_Type is new Term_Type;
Please advise which of the two is better.
--
Victor Porton - http://portonvictor.org
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Subtype or derived type?
2017-10-07 16:19 Subtype or derived type? Victor Porton
@ 2017-10-07 16:23 ` Victor Porton
2017-10-07 16:24 ` Victor Porton
2017-10-09 21:50 ` Randy Brukardt
1 sibling, 1 reply; 4+ messages in thread
From: Victor Porton @ 2017-10-07 16:23 UTC (permalink / raw)
Victor Porton wrote:
> While developing (thick object oriented) bindings for a C library:
>
> I have developed a package containing Term_Type type with bindings
> for raptor_term type:
> https://github.com/vporton/redland-bindings/blob/ada2012/ada/src/rdf-raptor-term.ads
>
> Term_Type represents pointer C type raptor_term* (where raptor_term
> is a struct).
>
> Now I am developed bindings for librdf_node which is defined as:
>
> typedef raptor_term librdf_node;
>
> Now I ask advice how to define the type representing librdf_node*
> pointer type.
>
> I have two variants in mind:
>
> 1.
>
> subtype Node_Type is Term_Type;
>
> 2.
>
> type Node_Type is new Term_Type;
>
> Please advise which of the two is better.
I am declined to use a derived type, because I may naturally have
subprograms with the same name (as the name is derived from the name of the
corresponding C function) and then using subtype, when I "use" both modules,
the names would clash.
But I am not sure.
--
Victor Porton - http://portonvictor.org
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Subtype or derived type?
2017-10-07 16:23 ` Victor Porton
@ 2017-10-07 16:24 ` Victor Porton
0 siblings, 0 replies; 4+ messages in thread
From: Victor Porton @ 2017-10-07 16:24 UTC (permalink / raw)
Victor Porton wrote:
> Victor Porton wrote:
>
>> While developing (thick object oriented) bindings for a C library:
>>
>> I have developed a package containing Term_Type type with bindings
>> for raptor_term type:
>> https://github.com/vporton/redland-bindings/blob/ada2012/ada/src/rdf-raptor-term.ads
>>
>> Term_Type represents pointer C type raptor_term* (where raptor_term
>> is a struct).
>>
>> Now I am developed bindings for librdf_node which is defined as:
>>
>> typedef raptor_term librdf_node;
>>
>> Now I ask advice how to define the type representing librdf_node*
>> pointer type.
>>
>> I have two variants in mind:
>>
>> 1.
>>
>> subtype Node_Type is Term_Type;
>>
>> 2.
>>
>> type Node_Type is new Term_Type;
>>
>> Please advise which of the two is better.
>
> I am declined to use a derived type, because I may naturally have
> subprograms with the same name (as the name is derived from the name of
> the corresponding C function) and then using subtype, when I "use" both
> modules, the names would clash.
"declined" should be "inclined".
> But I am not sure.
--
Victor Porton - http://portonvictor.org
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Subtype or derived type?
2017-10-07 16:19 Subtype or derived type? Victor Porton
2017-10-07 16:23 ` Victor Porton
@ 2017-10-09 21:50 ` Randy Brukardt
1 sibling, 0 replies; 4+ messages in thread
From: Randy Brukardt @ 2017-10-09 21:50 UTC (permalink / raw)
"Victor Porton" <porton@narod.ru> wrote in message
news:orauq5$9tv$1@gioia.aioe.org...
...
> I have two variants in mind:
>
> 1.
>
> subtype Node_Type is Term_Type;
>
> 2.
>
> type Node_Type is new Term_Type;
>
> Please advise which of the two is better.
It depends on how you want to use the type/subtype, of course.
If you need overridding/overloading, then you probably want a new type (a
derived type), so the compiler can differentiate. If you need to convert
back and forth a lot, you probably want a subtype (so the conversions are
implicit rather than explicit). And so on...
Randy.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-10-09 21:50 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-07 16:19 Subtype or derived type? Victor Porton
2017-10-07 16:23 ` Victor Porton
2017-10-07 16:24 ` Victor Porton
2017-10-09 21:50 ` Randy Brukardt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox