# Typo in constructor, why does Julia not complain?

**URL:** https://discourse.julialang.org/t/typo-in-constructor-why-does-julia-not-complain/74495
**Category:** General Usage
**Created:** [January 12, 2022, 4:00pm UTC](https://discourse.julialang.org/t/typo-in-constructor-why-does-julia-not-complain/74495 "2022-01-12T16:00:57Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Chiil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chiil/32/27474_2.png) [@Chiil](https://discourse.julialang.org/u/Chiil)
#### Post date: [January 12, 2022, 4:00pm UTC](https://discourse.julialang.org/t/typo-in-constructor-why-does-julia-not-complain/74495/1 "2022-01-12T16:00:57Z")

</div>

I made a type in my constructor (`Tset` instead of `Test`) and noticed that Julia does not complain if there is another function in the `struct` definition that has a different name than the struct itself. What happens to this line when I run my code and why is there no error?

```julia
struct Test
    a::Array{Float64, 3}
    Test(i) = new(rand(i, i, i))
    Tset(i, c) = new(rand(c*i, c*i, c*i))
end

test = Test(2)
# test = Test(2, 3)

```

---

<div class="post-metadata">

### Author: ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)
#### Post date: [January 12, 2022, 4:28pm UTC](https://discourse.julialang.org/t/typo-in-constructor-why-does-julia-not-complain/74495/2 "2022-01-12T16:28:31Z")

</div>

I assume that it ends up as dead code. Notice that you can do things like

```julia
julia> struct Foo
           x::Int
           y::Int
           Foo(x) = new(bar(x), bar(x + 1))
           bar(x) = x^2
       end

julia> Foo(3)
Foo(9, 16)

```

so it can’t be an error to define other functions than the constructor itself.

---

<div class="post-metadata">

### Author: ![Chiil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chiil/32/27474_2.png) [@Chiil](https://discourse.julialang.org/u/Chiil)
#### Post date: [January 12, 2022, 6:35pm UTC](https://discourse.julialang.org/t/typo-in-constructor-why-does-julia-not-complain/74495/3 "2022-01-12T18:35:48Z")

</div>

OK thanks. I was unaware that such constructions were possible. Is this considered good style in Julia?

---

<div class="post-metadata">

### Author: ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)
#### Post date: [January 12, 2022, 6:42pm UTC](https://discourse.julialang.org/t/typo-in-constructor-why-does-julia-not-complain/74495/4 "2022-01-12T18:42:40Z")

</div>

no.

---

<div class="post-metadata">

### Author: ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)
#### Post date: [January 12, 2022, 6:50pm UTC](https://discourse.julialang.org/t/typo-in-constructor-why-does-julia-not-complain/74495/5 "2022-01-12T18:50:22Z")

</div>

It doesn’t seem entirely unreasonable if you need a couple different inner constructors and they can share some code. But I’ve never seen it used and I only rarely use inner constructors at all myself.
