# Structure and performance questions from a Fortran programmer: functions, global variables, array allocations, input files, and structs

**URL:** <https://discourse.julialang.org/t/structure-and-performance-questions-from-a-fortran-programmer-functions-global-variables-array-allocations-input-files-and-structs/137409>\
**Category:** New to Julia\
**Tags:** question, performance\
**Created:** [June 2, 2026, 5:41pm UTC](https://discourse.julialang.org/t/structure-and-performance-questions-from-a-fortran-programmer-functions-global-variables-array-allocations-input-files-and-structs/137409 "2026-06-02T17:41:18Z")\
**Posts on this page:** 1\
**Showing post:** 32

<div class="post-metadata">

**Author:** ![ryofurue](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ryofurue/32/24531_2.png) [@ryofurue](https://discourse.julialang.org/u/ryofurue)\
**Post date:** [June 7, 2026, 1:12pm UTC](https://discourse.julialang.org/t/structure-and-performance-questions-from-a-fortran-programmer-functions-global-variables-array-allocations-input-files-and-structs/137409/32 "2026-06-07T13:12:04Z")

</div>

@ducksoverip I’m in the same boat as you, except that I started a few years earlier than you. So, my experience might be of some help to you. Instead of answering all your questions, I’ll answer the easiest one (to me) first:

> [@ducksoverip](#):
>
> 1. Other than conveniently bundling a bunch of parameters to pass to a function, what is the point of structs? I believe they are a feature of more recent Fortran versions, but as they never appeared in any of the Fotran90 code I’ve written or used, I’m completely unfamiliar with them. They seem to get regular mention as a means of improving performance, but I don’t understand how.

First of all, the struct is less “necessary” in Julia than in most other languages including F90, C, C++, Java, etc.

In a fully object oriented programming style, the struct (or “class”) is essential to bundle multiple variables to treat them as a single object. In a not fully object oriented style, bundling multiple variables can be useful, for example, if you want to handle a point in a 3D space as a single object:

```fortran
type Point
    real:: x, y, z
end type Point
type(Point):: p
! use p.x, p.y, p.z

```

In other languages than Julia, you may also want to bundle “a bunch of parameters to pass to a function”, as you say, but in Julia, the `NamedTuple` is more flexible and easier to use:

```julia-auto
function myfunc(; x, y, z)
   # . . . use x, y, z and produce a, b, c
   a = . . . 
   b = . . .
   c = . . . 
   return (; a, b, c)
end

# call myfunc with an explicit bundle
pars = (; x = 3.14, y = 2.0, z = -999.9) # NamedTuple
ret = myfunc(; pars...) # "expand" it as arguments
# . . . use ret.a, ret.b, ret.c

# call myfunc with implicit NamedTuple
ret = myfunc(; x = 3.14, y = 2.0, z = -999.9)
# . . . use ret.a, ret.b, ret.c

# Same, except the returned NamedTuple is expanded:
(; a, b, c) = myfunc(; x = 3.14, y = 2.0, z = -999.9)
# . . . use a, b, c

```

`NamedTuple` is a light-weight mechanism to create a struct-like object. It can be used like a struct: `println(pars.x)`, for example. Yet, unlike the real struct, it doesn’t need a formal definition such as `type Point; real:: x, y, z; end type Point`.

Moreover, you can choose between expanding it or not doing so each time you use the function: You don’t force the user of your function to formally create a struct.

So, I recommend using structs only where you would use structs in Fortran. In other situations, you can just use `NamedTuple`s.

---

_[View the full topic](https://discourse.julialang.org/t/structure-and-performance-questions-from-a-fortran-programmer-functions-global-variables-array-allocations-input-files-and-structs/137409)._
