# Annotating Types: Best practice for beginners

**URL:** <https://discourse.julialang.org/t/annotating-types-best-practice-for-beginners/50521>\
**Category:** New to Julia\
**Created:** [November 21, 2020, 1:19am UTC](https://discourse.julialang.org/t/annotating-types-best-practice-for-beginners/50521 "2020-11-21T01:19:28Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![johnmyleswhite](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnmyleswhite/32/31_2.png) [@johnmyleswhite](https://discourse.julialang.org/u/johnmyleswhite)\
**Post date:** [November 21, 2020, 1:49am UTC](https://discourse.julialang.org/t/annotating-types-best-practice-for-beginners/50521/2 "2020-11-21T01:49:58Z")

</div>

- Annotate types inside of type definitions for performance.
- Annotate types inside of function definitions to exploit multiple dispatch or to prevent duck typing.

Basically, this is good for performance:

```julia
struct Foo
    x::Int64
    y::Float64
end

```

And this is bad:

```julia
struct Foo
    x
    y
end

```

In contrast, performance is the same for either of these when called on `z` of type `Foo`:

```julia
function bar(z)
    z.x + z.y
end

```

```julia
function bar(z::Foo)
    z.x + z.y
end

```

---

_[View the full topic](https://discourse.julialang.org/t/annotating-types-best-practice-for-beginners/50521)._
