jw3126 / StructHelpers.jl

Automate common struct definition boilerplate
MIT License
14 stars 0 forks source link

Reconsider self constructor #10

Open jariji opened 8 months ago

jariji commented 8 months ago

https://github.com/jw3126/StructHelpers.jl/blob/560b49442c361fcb8dbe65b622844566cf242074/src/StructHelpers.jl#L66

julia> x = []
Any[]

julia> y = Vector(x)
Any[]

julia> x === y
false
# Batteries
julia> mutable struct Foo 
           x
       end

julia> @batteries Foo
Foo

julia> x = Foo([])
Foo(Any[])

julia> y = Foo(x)
Foo(Any[])

# Normal

julia> struct Bar
           x
       end

julia> Bar(Bar([]))
Bar(Bar(Any[]))

Because this constructor behaves in unusual ways, I don't think it should be enabled by default. I'd lean toward just removing the option.

jw3126 commented 8 months ago

It is a good point, people might have different expectations of a selfconstructor. I agree, that selfconstructor=false may be the better default. But I am hesitant to do that breaking change.