Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

manual/workflow-tips: simplify the basic workflow (& explain _why_ we put code in a module) #48319

Merged
merged 2 commits into from
Oct 30, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/src/manual/workflow-tips.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ line. A common pattern includes the following elements:

end
```
The key here is to encapsulate the code in a module.
If it were not so, and the code was ran directly in the `Main` module of the REPL,
you would not be able to remove methods or edit `struct` definitions, without restarting Julia.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The key here is to encapsulate the code in a module.
If it were not so, and the code was ran directly in the `Main` module of the REPL,
you would not be able to remove methods or edit `struct` definitions, without restarting Julia.
The key here is to encapsulate the code in a module.
This makes the global state more isolated, so that it is not affected by prior content in the `Main` module of the REPL,
or methods and `struct` definitions added before.
This reduces the need to restart Julia in this workflow.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(changed to word this only in the positive, and to mention another benefit of this workflow tip)

Copy link
Contributor Author

@tfiers tfiers Jan 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the review and suggestion :)

The isolation from previous REPL commands is indeed another benefit.
Maybe confusing for new users that "the global state" refers to the state inside the module?

Does using a module reduce the need for restarting Julia, or (virtually) eliminate it?

I'll tag the original author of this section (4b51aef), @twadleigh, to ask them what they think.

Copy link
Contributor Author

@tfiers tfiers Jan 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually this edit changes what I meant: I think that in an "efficient interactive workflow", which this guide is about, the main advantage of a module is not having to restart Julia when editing structs or removing methods.

* **Put your test code in another file.** Create another file, say `tst.jl`, which looks like

```julia
Expand Down