# How do you indicate that a field should be private?

**URL:** <https://discourse.julialang.org/t/how-do-you-indicate-that-a-field-should-be-private/65339>\
**Category:** General Usage\
**Created:** [July 27, 2021, 2:40am UTC](https://discourse.julialang.org/t/how-do-you-indicate-that-a-field-should-be-private/65339 "2021-07-27T02:40:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon60034542](https://avatars.discourse-cdn.com/v4/letter/a/90ced4/32.png) [@anon60034542](https://discourse.julialang.org/u/anon60034542)\
**Post date:** [July 27, 2021, 2:40am UTC](https://discourse.julialang.org/t/how-do-you-indicate-that-a-field-should-be-private/65339/1 "2021-07-27T02:40:22Z")

</div>

In C#/Java we can do so with the `private` keyword, in Python we can use the underscore. I found [this](https://github.com/JuliaLang/julia/issues/12064) discussion on Github, but it’s from 2015.

Is the accepted convention to use the underscore?

```julia
struct Example
    _this_field_is_private::Int32
     this_field_is_public::String
end 

```

---

<div class="post-metadata">

**Author:** ![jzr](https://avatars.discourse-cdn.com/v4/letter/j/eb9ed0/32.png) [@jzr](https://discourse.julialang.org/u/jzr)\
**Post date:** [July 27, 2021, 2:41am UTC](https://discourse.julialang.org/t/how-do-you-indicate-that-a-field-should-be-private/65339/2 "2021-07-27T02:41:21Z")

</div>

Some people consider all fields private by default. See [Documenting elements of a struct](https://discourse.julialang.org/t/documenting-elements-of-a-struct/64769)

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [July 27, 2021, 2:48am UTC](https://discourse.julialang.org/t/how-do-you-indicate-that-a-field-should-be-private/65339/3 "2021-07-27T02:48:18Z")

</div>

> [@anon60034542](#):
>
> Is the accepted convention to use the underscore?

That’s a pretty common convention in Julia, though by by no means universal.

---

<div class="post-metadata">

**Author:** ![hendri54](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hendri54/32/9621_2.png) [@hendri54](https://discourse.julialang.org/u/hendri54)\
**Post date:** [July 27, 2021, 12:32pm UTC](https://discourse.julialang.org/t/how-do-you-indicate-that-a-field-should-be-private/65339/4 "2021-07-27T12:32:25Z")

</div>

There is also the option of defining `propertynames(x :: Example, private :: Bool)`.
