# 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:** 1\
**Showing post:** 24

<div class="post-metadata">

**Author:** ![Eben60](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eben60/32/13475_2.png) [@Eben60](https://discourse.julialang.org/u/Eben60)\
**Post date:** [August 12, 2023, 5:33pm UTC](https://discourse.julialang.org/t/workflow-challenges-with-redefining-structs-from-why-i-still-recommend-julia/83593/24 "2023-08-12T17:33:38Z")

</div>

Sometimes I use a workflow similar to what @Ralph_Smith suggested (instead of or in addition to the Revise-based workflow).

```julia
module MM

a = 1
b = 2
foo(x) = x + 1
struct Coord
	x
	y
end

end

a = MM.a
b = MM.b
Coord = MM.Coord
foo = MM.foo

c = Coord(a, foo(b))

```

```julia
julia> 
WARNING: replacing module MM.
Main.MM.Coord(1, 3)

```

After any changes in the module just re-run the script. One of the reasons to use such workflow is the possibility to re-define structs. Another one - I may start with calculations in the global scope and move them into functions bit by bit.

An annoying aspect of the approach is that either I have to always prefix my `a`, `b`, `foo`, `Coord` with the module name, or define variables in the `Main` scope as in the example above.

Now I went a step further and automated the Main scope variables binding:

```julia
module DraftsModule

a = 1
b = 2
foo(x) = x + 1
struct Coord
	x
	y
end

allnames = names(DraftsModule; all=true)
end # DraftsModule

for n in DraftsModule.allnames
    if Base.isidentifier(n) && n ∉ (:DraftsModule, :eval, :include)
        eval(Meta.parse("$n = DraftsModule.$n"))
    end
end

```

Herewith I just have the following code saved as a template:

```julia
module DraftsModule

# put your code here

allnames = names(DraftsModule; all=true)
end # DraftsModule

for n in DraftsModule.allnames
    if Base.isidentifier(n) && n ∉ (:DraftsModule, :eval, :include)
        eval(Meta.parse("$n = DraftsModule.$n"))
    end
end
# work with the variables defined in DraftsModule

```

I can imagine putting this code into a macro and use it like following, but that appears beyond my competence.

```julia
@do_it_somehow begin
module MyModule
#put your code here
end #module
end #macro
# work with the variables defined in MyModule

```

---

_[View the full topic](https://discourse.julialang.org/t/workflow-challenges-with-redefining-structs-from-why-i-still-recommend-julia/83593)._
