Hi,
I have checked the Stackoverflow topic Difference between @with_kw and Base.@kwdef in Julia? , whose last update is from Oct, 18, 2021, and would like to know whether there should be any drawbacks due to my current preferred use of the package Parameters.jl
(with the corresponding macro @with_kw
) instead of the default Julia’s Base.@kw_def
; in fact, it seems to me the package still has (some/many?) more resources than the default base macro. Is this correct?
Raf
February 22, 2023, 9:26pm
2
We have property destructuring in Base now, so @unpack
isn’t needed:
(; x, y) = someobj
This combined with @kwdef
and I’m not sure how much you get from Parameters.jl anymore.
@kwdef
is exported now too:
promote_type,
instances,
supertype,
typeintersect,
typejoin,
widen,
# syntax
esc,
gensym,
@kwdef,
macroexpand,
@macroexpand1,
@macroexpand,
parse,
# help and reflection
code_typed,
code_lowered,
fullname,
functionloc,
3 Likes
I think that this syntax:
@with_kw mutable struct Settings @deftype Float64
my_float = 2.0
end
still needs Parameters.jl
As far as I know Base.@kwdef does not support default types for the fields of a struct.
lmiq
February 22, 2023, 10:30pm
4
Compatibility with Julia 1.6? (for @unpack
)
Raf
February 22, 2023, 10:59pm
5
Sure, but this is a since 2021 update
1 Like
lmiq
February 22, 2023, 11:23pm
6
Yeah, but I keep using it because 1.6 is still the LTS.
Have the features mentioned by @mauro3 at the thread https://github.com/JuliaLang/julia/pull/29316#issuecomment-424091405 been merged to Base.@kwdef ? I list them here for convenience as well:
Four bits which are “missing” are:
allow @assert
s in the type body which then get included in the positional inner constructor.
different show
method.
type-specific unpack macros
automatic documentation of the type-fields with their defaults
I don’t think the first three are suitable for Base. The last would be nice though, but maybe for another PR.
Raf
February 24, 2023, 5:54pm
8
type-specific unpack macros
This is what I meant by property destructuring. Do you use the other things?