> bad style. this code would invalidate all of your constructors if you
> change the number of fields in STfields. and changing the API for an entire
> class of objects is generally frowned upon by your users

That is true, but before reaching version 1.0 things like that will
happen.  None of my code has ever gotten close to 1.0 ;-)

The same caveat would apply to "abstract types with fields"
https://github.com/JuliaLang/julia/issues/4935, right?

Anyway, the way you suggest below seems good, thanks.

> if you expect to be sharing several common fields, the suggestion has been
> to create a type that aggregates them together and use the has-a rather
> than isa relationship
>
> type STfields()
> a::Int
> b::String
> end
> abstract ST
> type MyST <: ST
>   common::STfields
>   c
>   d
> end
>
> On Fri, Jun 20, 2014 at 9:03 AM, Mauro <[email protected]> wrote:
>
>> What about using a macro to define the common types? That would avoid the
>> problem of having to visit each subtype declaration when more common fields
>> are added. Is that good or bad style?
>>
>> julia> macro STfields()
>>        quote
>>        a::Int
>>        b::String
>>        end
>>        end
>>
>> julia> abstract ST
>>
>> julia> type MyST <: ST
>>        @STfields
>>        c
>>        d
>>        end
>>
>> julia> names(MyST)
>> 4-element Array{Symbol,1}:
>>  :a
>>  :b
>>  :c
>>  :d
>>
>>

Reply via email to