# I don't understand Julia. From running in the command line to workflow

**URL:** <https://discourse.julialang.org/t/i-dont-understand-julia-from-running-in-the-command-line-to-workflow/114235>\
**Category:** New to Julia\
**Tags:** question, code-organization\
**Created:** [May 14, 2024, 10:00am UTC](https://discourse.julialang.org/t/i-dont-understand-julia-from-running-in-the-command-line-to-workflow/114235 "2024-05-14T10:00:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Amnesian](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/amnesian/32/209210_2.png) [@Amnesian](https://discourse.julialang.org/u/Amnesian)\
**Post date:** [May 14, 2024, 10:00am UTC](https://discourse.julialang.org/t/i-dont-understand-julia-from-running-in-the-command-line-to-workflow/114235/1 "2024-05-14T10:00:37Z")

</div>

[My code](https://github.com/AmnesianBlizzard/MD-simulation/blob/main/simulation.jl)

I’m coming from languages like C, python and mathematica (I only really use mathematica for some data handling and scripting)

I have quite a few things I’m struggling with to be honest.  
The only way I know how to run this code is typing “julia simulation.jl {args}” into cmd. I haven’t really been able to get this to accept arguments in REPL. I’ve searched online and there seems to be some hacky ways of redefining the ARGS objects before you run it to get it to accept them, but I can’t see how this is even close to the intended way.

I’ve been doing everything from VSCode, but I need to share this file with other people so that they can run and test it (this is an assignment so I need the professor to be able to run it without much hassle from his side).

I’ve seen many people recommend wrapping everything in functions, and I think I’m doing that but I can never be too sure.

I’m just at a loss on how to manage all this. Learning about functions online is an alright experience as long as it’s self-contained. But I’m finding that learning about anything on a broader (or “meta”) scope is very difficult and there’s not many sources that actually give a good overview in my opinion

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [May 14, 2024, 10:18am UTC](https://discourse.julialang.org/t/i-dont-understand-julia-from-running-in-the-command-line-to-workflow/114235/2 "2024-05-14T10:18:16Z")

</div>

Welcome to Julia Discourse.

1. Your code repository does not appear to be public, so we cannot take a look
2. Posting here is a good way to get answers to specific questions.
3. If you want something interactive, consider the [Julia Slack](https://julialang.org/slack/) or Zulip
4. The primary documentation is here:  
[Julia Documentation · The Julia Language](https://docs.julialang.org/en/v1/)
5. Try Julia Academy:  
[https://juliaacademy.com/](https://juliaacademy.com/)

Regarding your args issue, I recommend the following structure.

```julia
function main(args::Vector{String} = ARGS)
    nargs = length(args)
    arg1 = 1
    arg2 = 2
    if length(args) > 0
        arg1 =parse(Int, args[1])
    end
    if length(args) > 1
        arg2 = parse(Int, args[2))
    end
    simulation(arg1, arg2)
end
function simulation(arg1, arg2,)
    # your actual simulation
end
if abspath(PROGRAM_FILE) == @ __FILE__
    main()
end

```

This allows you to run the file from the command line or load the file via `include`. You can then either invoke `main(String["1", "2"])` or `simulation(1,2)`.

---

<div class="post-metadata">

**Author:** ![Amnesian](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/amnesian/32/209210_2.png) [@Amnesian](https://discourse.julialang.org/u/Amnesian)\
**Post date:** [May 14, 2024, 10:25am UTC](https://discourse.julialang.org/t/i-dont-understand-julia-from-running-in-the-command-line-to-workflow/114235/3 "2024-05-14T10:25:20Z")

</div>

I believe that I have changed the visibility of my project now.

---

<div class="post-metadata">

**Author:** ![kellertuer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kellertuer/32/220707_2.png) [@kellertuer](https://discourse.julialang.org/u/kellertuer)\
**Post date:** [May 14, 2024, 1:05pm UTC](https://discourse.julialang.org/t/i-dont-understand-julia-from-running-in-the-command-line-to-workflow/114235/4 "2024-05-14T13:05:49Z")

</div>

> [@Amnesian](#):
>
> I’ve been doing everything from VSCode, but I need to share this file with other people so that they can run and test it (this is an assignment so I need the professor to be able to run it without much hassle from his side).

If the professor has Julia they would run it with the same Julia command as you do.  
If they do not have Julia, this might be problematic of course.

In general for something reproducible where you want to interactively develop something maybe also Pluto.jl might be worth taking a look?

---

<div class="post-metadata">

**Author:** ![Nathan\_Boyer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nathan_boyer/32/14825_2.png) [@Nathan\_Boyer](https://discourse.julialang.org/u/Nathan_Boyer)\
**Post date:** [May 14, 2024, 2:09pm UTC](https://discourse.julialang.org/t/i-dont-understand-julia-from-running-in-the-command-line-to-workflow/114235/5 "2024-05-14T14:09:10Z")

</div>

You may find this website useful: [Modern Julia Workflows](https://modernjuliaworkflows.github.io/)

Usually in Julia you would share your simulation as a package and ask the person you share it with to install or activate it then run some function defined in your package.

Install Option:

```julia-repl
pkg> add https://github.com/myuser/MyAwesomePackage

```

Download and Activate Option:

```julia-repl
pkg> activate /path/to/MyAwesomePackage
pkg> instantiate

```

Running:

```julia-repl
julia> using MyAwesomePackage
julia> runSimulation()

```

You can also define a function named ` __init__ ()` in your package that will run as part of the `using` step. I tend to print some user instructions with it.
