# Workflow challenges with redefining structs (from "Why I still recommend Julia")

**URL:** <https://discourse.julialang.org/t/workflow-challenges-with-redefining-structs-from-why-i-still-recommend-julia/83593>\
**Category:** Community\
**Created:** [June 29, 2022, 8:07pm UTC](https://discourse.julialang.org/t/workflow-challenges-with-redefining-structs-from-why-i-still-recommend-julia/83593 "2022-06-29T20:07:30Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![sairus7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sairus7/32/10816_2.png) [@sairus7](https://discourse.julialang.org/u/sairus7)\
**Post date:** [June 29, 2022, 8:07pm UTC](https://discourse.julialang.org/t/workflow-challenges-with-redefining-structs-from-why-i-still-recommend-julia/83593/1 "2022-06-29T20:07:30Z")

</div>

> [@Discussion on "Why I no longer recommend Julia" by Yuri Vishnevsky](https://discourse.julialang.org/t/discussion-on-why-i-no-longer-recommend-julia-by-yuri-vishnevsky/81151/281):
>
> Yuri’s post and the enormous backslash made me doubt Julia a bit. However, after a few weeks, I realized that there is no problem. The fundamentals are still fine:
> 
> [Why I still recommend Julia (for Data Science) - Huijzer.xyz](https://huijzer.xyz/posts/recommend/)
> 
> Feedback and comments are welcome. Doesn’t have to be in this thread; feel free to contact me personally.

"_Hence, the development workflow is to start the process, get a cup of coffee while it loads for the first time and keep the process alive for the rest of the day"_. – Or take another cup of coffee each time you change structure definition… 😆

---

<div class="post-metadata">

**Author:** ![cocoa1231](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cocoa1231/32/22215_2.png) [@cocoa1231](https://discourse.julialang.org/u/cocoa1231)\
**Post date:** [June 29, 2022, 8:56pm UTC](https://discourse.julialang.org/t/workflow-challenges-with-redefining-structs-from-why-i-still-recommend-julia/83593/2 "2022-06-29T20:56:56Z")

</div>

There’s proto structs package and revise for that right?

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [June 29, 2022, 9:00pm UTC](https://discourse.julialang.org/t/workflow-challenges-with-redefining-structs-from-why-i-still-recommend-julia/83593/3 "2022-06-29T21:00:34Z")

</div>

Hmm, how many times do I change the definition of the structure? If I keep changing the structure repeatedly, I have probably not thought this through properly…

---

<div class="post-metadata">

**Author:** ![sairus7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sairus7/32/10816_2.png) [@sairus7](https://discourse.julialang.org/u/sairus7)\
**Post date:** [June 29, 2022, 9:06pm UTC](https://discourse.julialang.org/t/workflow-challenges-with-redefining-structs-from-why-i-still-recommend-julia/83593/4 "2022-06-29T21:06:04Z")

</div>

Yes, and you definitely need more coffee to think thoroughly!

---

<div class="post-metadata">

**Author:** ![liuyxpp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/liuyxpp/32/9870_2.png) [@liuyxpp](https://discourse.julialang.org/u/liuyxpp)\
**Post date:** [June 30, 2022, 12:49am UTC](https://discourse.julialang.org/t/workflow-challenges-with-redefining-structs-from-why-i-still-recommend-julia/83593/5 "2022-06-30T00:49:26Z")

</div>

I found myself often adding more fields to an existing Struct or adding parametric types as I proceed. At the very beginning, it may be hard to coin a perfect struct. I prefer starting coding as soon as I get the idea and polishing later as I go.

---

<div class="post-metadata">

**Author:** ![jar1](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@jar1](https://discourse.julialang.org/u/jar1)\
**Post date:** [June 30, 2022, 1:06am UTC](https://discourse.julialang.org/t/workflow-challenges-with-redefining-structs-from-why-i-still-recommend-julia/83593/6 "2022-06-30T01:06:26Z")

</div>

> [@sairus7](#):
>
> "_Hence, the development workflow is to start the process, get a cup of coffee while it loads for the first time and keep the process alive for the rest of the day"_. – Or take another cup of coffee each time you change structure definition… 😆

Another cause of restarts is when some function becomes unresponsive for a long time and ignores ctrl+c. This happens to me often.

---

<div class="post-metadata">

**Author:** ![aplavin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aplavin/32/222056_2.png) [@aplavin](https://discourse.julialang.org/u/aplavin)\
**Post date:** [June 30, 2022, 10:40am UTC](https://discourse.julialang.org/t/workflow-challenges-with-redefining-structs-from-why-i-still-recommend-julia/83593/7 "2022-06-30T10:40:34Z")

</div>

> [@sairus7](#):
>
> "_Hence, the development workflow is to start the process, get a cup of coffee while it loads for the first time and keep the process alive for the rest of the day"_. – Or take another cup of coffee each time you change structure definition… 😆

Pluto is great for this: change functions/structs/whatever, it’s all automatically kept up-to-date.  
When the code has somewhat stabilized, put it into a proper module/package outsides of the notebook. Struct changes tend to be much more rare afterwards.

---

<div class="post-metadata">

**Author:** ![cortner](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cortner/32/204_2.png) [@cortner](https://discourse.julialang.org/u/cortner)\
**Post date:** [June 30, 2022, 7:43pm UTC](https://discourse.julialang.org/t/workflow-challenges-with-redefining-structs-from-why-i-still-recommend-julia/83593/8 "2022-06-30T19:43:42Z")

</div>

Just develop in a module and reload the module.

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [June 30, 2022, 10:42pm UTC](https://discourse.julialang.org/t/workflow-challenges-with-redefining-structs-from-why-i-still-recommend-julia/83593/9 "2022-06-30T22:42:35Z")

</div>

Really wish that when people suggested this, they would be more specific about the way and the limitations. Modules, types, and macros aren’t as dynamic as a function’s method table is now, and though Revise.jl gets you farther, you need to do more work and can only go so far. I’ve seen a fair share of posts being confused why they “reloaded” a module but all the dependent modules still use the old version.

There really should be a citable central source of how different things reference each other in Julia, e.g. how does `f` know what `MyType` is in `f(x::MyType) = _f(x)`, with the express goal of teaching people to reason what is and isn’t affected when code is reevaluated. Obviously it should state the caveat that some information are only implementation details.

---

<div class="post-metadata">

**Author:** ![cortner](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cortner/32/204_2.png) [@cortner](https://discourse.julialang.org/u/cortner)\
**Post date:** [June 30, 2022, 10:56pm UTC](https://discourse.julialang.org/t/workflow-challenges-with-redefining-structs-from-why-i-still-recommend-julia/83593/10 "2022-06-30T22:56:53Z")

</div>

I agree - I learned by experimenting. maybe there is docs maybe not - but there should be.

---

<div class="post-metadata">

**Author:** ![liuyxpp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/liuyxpp/32/9870_2.png) [@liuyxpp](https://discourse.julialang.org/u/liuyxpp)\
**Post date:** [July 1, 2022, 12:29am UTC](https://discourse.julialang.org/t/workflow-challenges-with-redefining-structs-from-why-i-still-recommend-julia/83593/11 "2022-07-01T00:29:59Z")

</div>

What do you mean by “develop in a module” and “reload the module”?

---

<div class="post-metadata">

**Author:** ![cortner](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cortner/32/204_2.png) [@cortner](https://discourse.julialang.org/u/cortner)\
**Post date:** [July 1, 2022, 1:04am UTC](https://discourse.julialang.org/t/workflow-challenges-with-redefining-structs-from-why-i-still-recommend-julia/83593/12 "2022-07-01T01:04:43Z")

</div>

When you reload or re-evaluate the module the type can change. This is good enough for me most of the time but as Benny pointed out it doesn’t solve all problems

---

<div class="post-metadata">

**Author:** ![liuyxpp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/liuyxpp/32/9870_2.png) [@liuyxpp](https://discourse.julialang.org/u/liuyxpp)\
**Post date:** [July 1, 2022, 1:08am UTC](https://discourse.julialang.org/t/workflow-challenges-with-redefining-structs-from-why-i-still-recommend-julia/83593/13 "2022-07-01T01:08:04Z")

</div>

I mean how do you do that? Sorry for the stupid question.

---

<div class="post-metadata">

**Author:** ![Ralph\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ralph_smith/32/10344_2.png) [@Ralph\_Smith](https://discourse.julialang.org/u/Ralph_Smith)\
**Post date:** [July 1, 2022, 2:01am UTC](https://discourse.julialang.org/t/workflow-challenges-with-redefining-structs-from-why-i-still-recommend-julia/83593/14 "2022-07-01T02:01:44Z")

</div>

Do your bleeding-edge development in a project, where you have a file like

```julia
module WIP
struct DraftType
 # etc
end
function foo(x::DraftType); do_stuff(x); end

# maybe include("other_bits.jl")
end

```

Now from the REPL (i.e. the `Main` module), do  
`include("wip.jl")`  
Experiment with `WIP.DraftType` and `WIP.foo`. When you find mistakes or deficiencies, edit and `include` over again. You need to remember to recreate any `DraftType` objects. Do **not** do `using WIP` in the REPL, to avoid being haunted by ghosts.

---

<div class="post-metadata">

**Author:** ![liuyxpp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/liuyxpp/32/9870_2.png) [@liuyxpp](https://discourse.julialang.org/u/liuyxpp)\
**Post date:** [July 1, 2022, 2:39am UTC](https://discourse.julialang.org/t/workflow-challenges-with-redefining-structs-from-why-i-still-recommend-julia/83593/15 "2022-07-01T02:39:22Z")

</div>

Wow, I do not know this before. Thanks! But I feel this does not fit my workflow well. I have a relatively large package to maintain and sometimes I need to update my struct definition. I have to experiment with several ways to update the struct to find which one is better.

---

<div class="post-metadata">

**Author:** ![Ralph\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ralph_smith/32/10344_2.png) [@Ralph\_Smith](https://discourse.julialang.org/u/Ralph_Smith)\
**Post date:** [July 1, 2022, 2:59am UTC](https://discourse.julialang.org/t/workflow-challenges-with-redefining-structs-from-why-i-still-recommend-julia/83593/16 "2022-07-01T02:59:06Z")

</div>

You can take it to the extreme of

```julia
include(joinpath(ENV["HOME"] ,".julia/dev/MyPackage/src/MyPackage.jl"))

```

so your large package is an ephemeral module for the duration. I’ve found this to be productive, but it does take some extra thought and effort.

---

<div class="post-metadata">

**Author:** ![Seif\_Shebl](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@Seif\_Shebl](https://discourse.julialang.org/u/Seif_Shebl)\
**Post date:** [July 1, 2022, 3:03am UTC](https://discourse.julialang.org/t/workflow-challenges-with-redefining-structs-from-why-i-still-recommend-julia/83593/17 "2022-07-01T03:03:29Z")

</div>

You can do this in other simple ways. Create a module `structs` at the top and define all your structs inside of it. Experiment with the structs as you wish and modify structs inside the module. When you are finished, remove the `module Structs` and its `end` statements as well as all `Structs.` prefixes.

```julia
module Structs
struct Point
    x::Float64
    y::Float64
end
end

Structs.Point(1.0,2.0)
 # Main.Structs.Point(1.0, 2.0)

module Structs
struct Point
    x::Float64
    y::Float64
    z::Float64
end
end

Structs.Point(1.0,2.0,3.0)
 # Main.Structs.Point(1.0, 2.0, 3.0)

```

---

<div class="post-metadata">

**Author:** ![jishnub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jishnub/32/33620_2.png) [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Post date:** [July 1, 2022, 5:25am UTC](https://discourse.julialang.org/t/workflow-challenges-with-redefining-structs-from-why-i-still-recommend-julia/83593/19 "2022-07-01T05:25:12Z")

</div>

In this workflow, one would also need to redefine functions that accept `WIP.DraftType`:

```julia
julia> module WIP
       struct DraftType
        # etc
       end
       function foo(x::DraftType); do_stuff(x); end

       # maybe include("other_bits.jl")
       end
Main.WIP

julia> bar(::WIP.DraftType) = 2
bar (generic function with 1 method)

julia> bar(WIP.DraftType())
2

julia> module WIP
       struct DraftType
        # etc
       end
       function foo(x::DraftType); do_stuff(x); end

       # maybe include("other_bits.jl")
       end
WARNING: replacing module WIP.
Main.WIP

julia> bar(WIP.DraftType())
ERROR: MethodError: no method matching bar(::Main.WIP.DraftType)
Closest candidates are:
  bar(::Main.WIP.DraftType) at REPL[2]:1
Stacktrace:
 [1] top-level scope
   @ REPL[4]:1

julia> methods(bar)
# 1 method for generic function "bar":
[1] bar(::Main.WIP.DraftType) in Main at REPL[2]:1

julia> bar(::WIP.DraftType) = 2
bar (generic function with 2 methods)

julia> bar(WIP.DraftType())
2

```

I must say that the output of `methods` is confusing, and wish that there was a way to indicate ghosting.

---

<div class="post-metadata">

**Author:** ![rikh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rikh/32/204104_2.png) [@rikh](https://discourse.julialang.org/u/rikh)\
**Post date:** [July 2, 2022, 8:11am UTC](https://discourse.julialang.org/t/workflow-challenges-with-redefining-structs-from-why-i-still-recommend-julia/83593/20 "2022-07-02T08:11:00Z")

</div>

I‘ve never used it myself, but Stefan Karpinski said somewhere that using NamedTuples as structs during development is also possible and then swap them out by structs once you‘re done

---

<div class="post-metadata">

**Author:** ![cortner](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cortner/32/204_2.png) [@cortner](https://discourse.julialang.org/u/cortner)\
**Post date:** [July 3, 2022, 2:18pm UTC](https://discourse.julialang.org/t/workflow-challenges-with-redefining-structs-from-why-i-still-recommend-julia/83593/21 "2022-07-03T14:18:46Z")

</div>

I haven’t tried this but I can totally see how this would work a lot of the time.

[Next page](https://discourse.julialang.org/t/workflow-challenges-with-redefining-structs-from-why-i-still-recommend-julia/83593.md?page=2)
