# Struct syntax

**URL:** <https://discourse.julialang.org/t/struct-syntax/51099>\
**Category:** General Usage\
**Created:** [December 2, 2020, 10:08am UTC](https://discourse.julialang.org/t/struct-syntax/51099 "2020-12-02T10:08:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![j2b2](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/j2b2/32/3387_2.png) [@j2b2](https://discourse.julialang.org/u/j2b2)\
**Post date:** [December 2, 2020, 10:08am UTC](https://discourse.julialang.org/t/struct-syntax/51099/1 "2020-12-02T10:08:02Z")

</div>

Hi,

I wonder why line breaks are required when defining fields of a structure, and where this is documented:

```julia
julia> struct S
       a
       b
       end

julia> struct S a b end
ERROR: syntax: extra token "b" after end of expression

julia>

```

---

<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:** [December 2, 2020, 10:27am UTC](https://discourse.julialang.org/t/struct-syntax/51099/2 "2020-12-02T10:27:13Z")

</div>

You can use `;` instead of line breaks. Also consider  
[https://github.com/cstjean/QuickTypes.jl](https://github.com/cstjean/QuickTypes.jl)

---

<div class="post-metadata">

**Author:** ![j2b2](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/j2b2/32/3387_2.png) [@j2b2](https://discourse.julialang.org/u/j2b2)\
**Post date:** [December 2, 2020, 10:40am UTC](https://discourse.julialang.org/t/struct-syntax/51099/3 "2020-12-02T10:40:45Z")

</div>

Thank you, but I find it strange, documentation (Punctuation section) says:

```julia
semicolons separate statements [...]

```

OK, it’s not a hot topic, just curiosity 🙂

---

<div class="post-metadata">

**Author:** ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)\
**Post date:** [December 2, 2020, 10:48am UTC](https://discourse.julialang.org/t/struct-syntax/51099/4 "2020-12-02T10:48:52Z")

</div>

It’s only required between the fields themselves, so one can write `struct A a end`.

I’m also interested to know why it’s required at all. Maybe the devs didn’t want to complicate parsing just to let people write code that’s harder to read 🙂

Subjective of course but `struct A b c end` is arguably less readable than

```julia
struct A
  b
  c
end

```

---

<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:** [December 2, 2020, 10:56am UTC](https://discourse.julialang.org/t/struct-syntax/51099/5 "2020-12-02T10:56:42Z")

</div>

Something like this would be hard to parse (but maybe not impossible) without new-lines:

```julia
julia> struct T
       a::T where T<:Integer
       b::U where U<:AbstractArray
       end

```

---

<div class="post-metadata">

**Author:** ![j2b2](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/j2b2/32/3387_2.png) [@j2b2](https://discourse.julialang.org/u/j2b2)\
**Post date:** [December 2, 2020, 11:05am UTC](https://discourse.julialang.org/t/struct-syntax/51099/6 "2020-12-02T11:05:06Z")

</div>

This is not a topic about readability, but about _parsing rules_. Semicolon is ok for the preceeding example:

```julia
julia> struct S a::T where T<:Integer; b::U where U<:AbstractArray end

julia> 

```
