# Properties with default values are always initialized before the body of any init(), even for Decodable.init — why is this?

**URL:** <https://forums.swift.org/t/properties-with-default-values-are-always-initialized-before-the-body-of-any-init-even-for-decodable-init-why-is-this/59507>\
**Category:** Discussion\
**Tags:** codable, swift\
**Created:** [August 7, 2022, 4:23am UTC](https://forums.swift.org/t/properties-with-default-values-are-always-initialized-before-the-body-of-any-init-even-for-decodable-init-why-is-this/59507 "2022-08-07T04:23:12Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![1-877-547-7272](https://avatars.discourse-cdn.com/v4/letter/1/278dde/32.png) [@1-877-547-7272](https://forums.swift.org/u/1-877-547-7272)\
**Post date:** [August 7, 2022, 5:10am UTC](https://forums.swift.org/t/properties-with-default-values-are-always-initialized-before-the-body-of-any-init-even-for-decodable-init-why-is-this/59507/2 "2022-08-07T05:10:16Z")

</div>

I think this is definitely worth addressing — it's caused a lot of [performance problems](https://forums.swift.org/t/what-is-a-variable-initialization-expression/52132) and [general confusion](https://forums.swift.org/t/why-does-my-explicit-init-crash/52984) over the years.

The Core Team considers this behavior a bug.

> [@SE-0242: Synthesize default values for the memberwise initializer](https://forums.swift.org/t/se-0242-synthesize-default-values-for-the-memberwise-initializer/20618/98):
>
> The proposal review also discussed an interesting behavioral quirk with initial values and side-effects, for example:
> 
> ```swift
> struct Foo {
> var i: Int = getDefaultValue()
> }
> 
> struct Bar {
> var i: Int = getDefaultValue()
> init(i: Int) { self.i = I }
> }
> 
> let x = Foo(i: 1) // No side effects
> let y = Bar(i: 1) // Yes side effects
> 
> ```
> 
> The Core Team felt that this was a bug in the compiler's implementation of initializers. The failure here is that Bar calls the side effect, and it is not the right behavior. Addressing this would likely require an evolution proposal, or at least an assessment of whether or not fixing this would break existing code.

---

_[View the full topic](https://forums.swift.org/t/properties-with-default-values-are-always-initialized-before-the-body-of-any-init-even-for-decodable-init-why-is-this/59507)._
