# Workflow when experimenting with types

**URL:** <https://discourse.julialang.org/t/workflow-when-experimenting-with-types/56483>\
**Category:** New to Julia\
**Created:** [March 4, 2021, 4:53pm UTC](https://discourse.julialang.org/t/workflow-when-experimenting-with-types/56483 "2021-03-04T16:53:10Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![basp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/basp/32/8657_2.png) [@basp](https://discourse.julialang.org/u/basp)\
**Post date:** [March 4, 2021, 4:53pm UTC](https://discourse.julialang.org/t/workflow-when-experimenting-with-types/56483/1 "2021-03-04T16:53:10Z")

</div>

Hi all, longtime lurker and irregular Julia user here.

Revise is absolutely great and I love it but I wonder if there’s a better workflow when experimenting with types.

I try to get my types defined ASAP but especially in the beginning, when taking a stab at a particular problem I frequently find myself changing definitions. Currently I just restart the interactive in order to reload Revise and my type definitions but I feel like I’m doing something wrong or that there might be a better way.

Here’s what such a session looks like in summary:

```julia
(start julia)
pkg> activate .
julia> using Revise
julia> using ThePackageImWorkingOn
(some experimentation on the julia prompt and then realize, darn my struct is wrong)
julia> exit()
(fix code, restart julia)
pkg] activate . # etc (repeating from top)

```

Maybe I’m not thinking meticulously enough about my structures, that’s a valid point. If that’s the case I’d love to know about it too.

Anyway, consider this a intro post as well, I’m perhaps not a typical Julia user since my field is not academics but I love how the language makes me think of problems differently from a programmer point of view.

Kind regards,

Bas

---

<div class="post-metadata">

**Author:** ![jonathanBieler](https://avatars.discourse-cdn.com/v4/letter/j/82dd89/32.png) [@jonathanBieler](https://discourse.julialang.org/u/jonathanBieler)\
**Post date:** [March 4, 2021, 5:30pm UTC](https://discourse.julialang.org/t/workflow-when-experimenting-with-types/56483/2 "2021-03-04T17:30:53Z")

</div>

I usually use search and replace in my project `MyStruct` → `MyStruct2`, etc. (think of it at different version of the struct). Once I’m done I rename it `MyStruct` and restart.

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [March 4, 2021, 5:33pm UTC](https://discourse.julialang.org/t/workflow-when-experimenting-with-types/56483/3 "2021-03-04T17:33:36Z")

</div>

There are some workarounds, like this:

> **[GitHub - BeastyBlacksmith/ProtoStructs.jl: Easy prototyping of structs](https://github.com/BeastyBlacksmith/ProtoStructs.jl)**
>
> Easy prototyping of structs. Contribute to BeastyBlacksmith/ProtoStructs.jl development by creating an account on GitHub.

Basically you can use named tuples until you have decided the final fields of the structs.

---

<div class="post-metadata">

**Author:** ![basp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/basp/32/8657_2.png) [@basp](https://discourse.julialang.org/u/basp)\
**Post date:** [March 4, 2021, 5:44pm UTC](https://discourse.julialang.org/t/workflow-when-experimenting-with-types/56483/4 "2021-03-04T17:44:00Z")

</div>

To be honest, I didn’t even consider macros and the idea of using named tuples instead didn’t really occur with me either. Julia doesn’t have enough parenthesis to force me into that macro-thinking mode I guess. This seems like a great workaround when just trying out things, even if just for the ideas. I will experiment with it, thanks!

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [March 4, 2021, 5:50pm UTC](https://discourse.julialang.org/t/workflow-when-experimenting-with-types/56483/5 "2021-03-04T17:50:32Z")

</div>

The pluto notebook allows you to redefine types.

---

<div class="post-metadata">

**Author:** ![basp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/basp/32/8657_2.png) [@basp](https://discourse.julialang.org/u/basp)\
**Post date:** [March 4, 2021, 5:56pm UTC](https://discourse.julialang.org/t/workflow-when-experimenting-with-types/56483/6 "2021-03-04T17:56:13Z")

</div>

From the demos I’ve seen Pluto looks absolutely amazing. I will definitely give it a try.

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [March 4, 2021, 6:01pm UTC](https://discourse.julialang.org/t/workflow-when-experimenting-with-types/56483/7 "2021-03-04T18:01:51Z")

</div>

I haven’t used that a lot. Maybe one nice way to use it is to define something like:

```julia
using ProtoStructs

@proto MyType

MyType(
   a::Int=1,
   b::Int=2,
   c::String="abc"
  ) = MyType( 
         a=a,
         b=a,
         c=c)

```

Then you have some common constructors working:

```julia
julia> x = MyType()
MyType{NamedTuple{(:a, :b, :c),Tuple{Int64,Int64,String}}}((a = 1, b = 1, c = "abc"))

julia> x.a, x.c
(1, "abc")

julia> x = MyType(3,3,"ddd")
MyType{NamedTuple{(:a, :b, :c),Tuple{Int64,Int64,String}}}((a = 3, b = 3, c = "ddd"))

julia> x.c
"ddd"

```

and, finally, when you decide what fields you will keep, if you use the `Parameters` package the conversion is very easy:

```julia
using Parameters
@with_kw struct MyType
   a::Int=1
   b::Int=2
   c::String="abc"
end

```

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [March 4, 2021, 6:10pm UTC](https://discourse.julialang.org/t/workflow-when-experimenting-with-types/56483/8 "2021-03-04T18:10:18Z")

</div>

Another option I’ve used is to put the code I’m developing into a module and then repeatedly `include()` that module’s file. This creates a new module with the same name (and all your modified type definitions inside it), so redefining types is not a problem. The biggest downside is that it can create a confusing situation if you have any old values left over from the previous iteration of your module, since they will have the same module _name_ as your current values but incompatible types.

---

<div class="post-metadata">

**Author:** ![Skoffer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/skoffer/32/378_2.png) [@Skoffer](https://discourse.julialang.org/u/Skoffer)\
**Post date:** [March 4, 2021, 6:13pm UTC](https://discourse.julialang.org/t/workflow-when-experimenting-with-types/56483/9 "2021-03-04T18:13:01Z")

</div>

But you can’t export struct names, right? At least I remember that in this case compiler complained about const redefined. So you have to use it as `MyModule.A` not just `A`

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [March 4, 2021, 6:24pm UTC](https://discourse.julialang.org/t/workflow-when-experimenting-with-types/56483/10 "2021-03-04T18:24:57Z")

</div>

That’s right. Not ideal, I agree.
