# Base.@kwdef for v1.0?

**URL:** https://discourse.julialang.org/t/base-kwdef-for-v1-0/21954
**Category:** Internals & Design
**Created:** [March 17, 2019, 5:08am UTC](https://discourse.julialang.org/t/base-kwdef-for-v1-0/21954 "2019-03-17T05:08:53Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![anon67531922](https://avatars.discourse-cdn.com/v4/letter/a/48db29/32.png) [@anon67531922](https://discourse.julialang.org/u/anon67531922)
#### Post date: [March 17, 2019, 5:08am UTC](https://discourse.julialang.org/t/base-kwdef-for-v1-0/21954/1 "2019-03-17T05:08:53Z")

</div>

Hi 👋

I stumbled on `Base.@kwdef` on Julia v1.1 and find it quite helpful and reduces a ton of boilerplate for my large types with lots of default values.

I started using it in my packages, but tests fail on Julia v1.0. It turns out (I guess), `Base.@kwdef` was introduced in Julia v1.1.

Is there a chance this could get backported (if that is the right word?) to Julia v1.0?

I’m hesitant to use it if it means I need to use Compat.jl or something 🤔

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [March 17, 2019, 5:56am UTC](https://discourse.julialang.org/t/base-kwdef-for-v1-0/21954/2 "2019-03-17T05:56:57Z")

</div>

FWIW, I think you should just depend on 1.1, eg specify something like

```nohighlight
[compat]
julia = "1.1"

```

in your `Project.toml`. This is what I am doing for almost all of my packages (yes, I love `Base.@kwdef` too, and I am removing a lot of workarounds as the 1.1 compiler is so much smarter than 1.0).

Generally, it is my impression that features will not be backported, just critical bug fixes. Which is as it should be: with a lot of backports, one could hardly commit to keep a branch “stable”.

See the [some discussion starting here](https://discourse.julialang.org/t/proposed-release-process-and-schedule/15623/35).

---

<div class="post-metadata">

### Author: ![tk3369](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tk3369/32/2824_2.png) [@tk3369](https://discourse.julialang.org/u/tk3369)
#### Post date: [March 17, 2019, 6:01am UTC](https://discourse.julialang.org/t/base-kwdef-for-v1-0/21954/3 "2019-03-17T06:01:11Z")

</div>

@anon67531922 - according to [semantic versioning](https://semver.org), a minor release is backward compatible. So there is no reason not to upgrade to 1.1 🙂

> Given a version number MAJOR.MINOR.PATCH, increment the:
> 
> 1. MAJOR version when you make incompatible API changes,
> 2. MINOR version when you add functionality in a backwards-compatible manner, and
> 3. PATCH version when you make backwards-compatible bug fixes.

---

<div class="post-metadata">

### Author: ![anon67531922](https://avatars.discourse-cdn.com/v4/letter/a/48db29/32.png) [@anon67531922](https://discourse.julialang.org/u/anon67531922)
#### Post date: [March 17, 2019, 6:09am UTC](https://discourse.julialang.org/t/base-kwdef-for-v1-0/21954/4 "2019-03-17T06:09:14Z")

</div>

Thanks @Tamas_Papp 👍

That is an interesting trail of posts. This [comment](https://discourse.julialang.org/t/proposed-release-process-and-schedule/15623) here is particularly interesting:

> [@Proposed release process and schedule](https://discourse.julialang.org/t/proposed-release-process-and-schedule/15623/1):
>
> Once 1.1 comes out, 1.0 will be the new LTS branch since it’s the only other release branch; but after 1.2 comes out, we have a choice between keeping 1.0 as the LTS branch for longer or making 1.1 the new LTS branch. We’ll have to see how people feel and what the demand is.

I think we can hope that when 1.2 comes out that 1.1 becomes the new LTS branch and then we get all the benefits of 1.1 without needing to worry about 1.0 🙏

---

<div class="post-metadata">

### Author: ![anon67531922](https://avatars.discourse-cdn.com/v4/letter/a/48db29/32.png) [@anon67531922](https://discourse.julialang.org/u/anon67531922)
#### Post date: [March 17, 2019, 6:11am UTC](https://discourse.julialang.org/t/base-kwdef-for-v1-0/21954/5 "2019-03-17T06:11:07Z")

</div>

Hi @tk3369 👋

Yeah. I am already working on v1.1 and love it. The issue is there are features in v1.1 that I want to use, e.g. `Base.@kwdef`, that work on v1.1. but NOT on v1.0 so if I use those features, I need to worry about people still using v1.0 😊

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [March 17, 2019, 6:35am UTC](https://discourse.julialang.org/t/base-kwdef-for-v1-0/21954/6 "2019-03-17T06:35:10Z")

</div>

> [@anon67531922](#):
>
> I need to worry about people still using v1.0

I think that’s the wrong way to think about it. You are writing free software, effectively donating your time and effort to other people who use the result. Your time and resources are finite, so you should be economizing on them.

If using new features of Julia makes your life a bit more convenient, you will have time to work on _other_ stuff that benefits your users. Sensible users would recognize that they should do their part by keeping up with the latest stable release (with a reasonable lag, eg 1-2 weeks).

---

<div class="post-metadata">

### Author: ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)
#### Post date: [March 17, 2019, 8:01am UTC](https://discourse.julialang.org/t/base-kwdef-for-v1-0/21954/7 "2019-03-17T08:01:03Z")

</div>

I totally agree with Tamas. However, if you _must_ have 1.0, then you can use Parameters.jl whose `@with_kw` is essentially the same as `@kwdef`. You could require Parameters for 1.0 and do `const @kwdef = Parameters.@with_kw` and in 1.1 `const @kwdef = Base.@kwdef`.

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [March 17, 2019, 8:43am UTC](https://discourse.julialang.org/t/base-kwdef-for-v1-0/21954/8 "2019-03-17T08:43:26Z")

</div>

`Base.@kwdef` definitely exist in 1.0:

```julia
help?> Base.@kwdef
  @kwdef typedef

  This is a helper macro that automatically defines a keyword-based constructor for the type declared in 

...

  Examples
  ≡≡≡≡≡≡≡≡≡≡

  julia> Base.@kwdef struct Foo
             a::Int = 1 # specified default
             b::String # required keyword
         end
  Foo

...

julia> versioninfo()
Julia Version 1.0.0

```

but maybe has gotten new features / bugfixes in 1.1.

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [March 17, 2019, 8:52am UTC](https://discourse.julialang.org/t/base-kwdef-for-v1-0/21954/9 "2019-03-17T08:52:59Z")

</div>

> [@kristoffer.carlsson](#):
>
> maybe has gotten new features / bugfixes in 1.1.

It did, if I remember correctly it was for handling parametric types. The macro exists in 1.0, but it is not practically useful outside a few narrow contexts.

---

<div class="post-metadata">

### Author: ![anon67531922](https://avatars.discourse-cdn.com/v4/letter/a/48db29/32.png) [@anon67531922](https://discourse.julialang.org/u/anon67531922)
#### Post date: [March 17, 2019, 8:57am UTC](https://discourse.julialang.org/t/base-kwdef-for-v1-0/21954/10 "2019-03-17T08:57:13Z")

</div>

Ah. Ok. That makes sense 👍

I had some tests that failed due to `Base.@kwdef` on v1.0, but passed on both v1.1 and nightly.

---

<div class="post-metadata">

### Author: ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)
#### Post date: [March 17, 2019, 9:09am UTC](https://discourse.julialang.org/t/base-kwdef-for-v1-0/21954/11 "2019-03-17T09:09:22Z")

</div>

That’s the PR which extended kwdef: [https://github.com/JuliaLang/julia/pull/29316](https://github.com/JuliaLang/julia/pull/29316)

---

<div class="post-metadata">

### Author: ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)
#### Post date: [March 17, 2019, 11:26am UTC](https://discourse.julialang.org/t/base-kwdef-for-v1-0/21954/12 "2019-03-17T11:26:20Z")

</div>

I think we should use Compat more for this kind of features, just like we did before 1.0.

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [March 17, 2019, 12:03pm UTC](https://discourse.julialang.org/t/base-kwdef-for-v1-0/21954/13 "2019-03-17T12:03:41Z")

</div>

> <https://github.com/JuliaLang/Compat.jl/issues/638>
>
> \`Base.@kwdef\` was extended considerably by https://github.com/JuliaLang/julia/pu…ll/29316, would it make sense for Compat.jl to provide a backport?
