Update on Base.@kwdef versus Parameters.jl

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?

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:

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.

Compatibility with Julia 1.6? (for @unpack)

Sure, but this is a since 2021 update :wink:

1 Like

Yeah, but I keep using it because 1.6 is still the LTS.

Have the features mentioned by @mauro3 at the thread at-kwdef support for parametric types and subtypes by simonbyrne · Pull Request #29316 · JuliaLang/julia · GitHub been merged to Base.@kwdef? I list them here for convenience as well:

Four bits which are “missing” are:

  • allow @asserts 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.

type-specific unpack macros

This is what I meant by property destructuring. Do you use the other things?