You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
FAQ: Clarify use of PROGRAM_FILE for importable scripts (#50139)
In issue #45852, the proposed `@is_script` macro as a shorthand for
`abspath(PROGRAM_FILE) == @__FILE__` was rejected, because it was agreed that
the pattern of using the same file as a script and an importable library is
questionable, so there is no reason to make it too idiomatic.
For this reason, mention in the FAQ that while checking `PROGRAM_FILE` can be
used to check if a file is run as a script, it is not recommended to have files
double as both scripts and importable libraries.
Copy file name to clipboardExpand all lines: doc/src/manual/faq.md
+3Lines changed: 3 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -94,6 +94,9 @@ When a file is run as the main script using `julia file.jl` one might want to ac
94
94
functionality like command line argument handling. A way to determine that a file is run in
95
95
this fashion is to check if `abspath(PROGRAM_FILE) == @__FILE__` is `true`.
96
96
97
+
However, it is recommended to not write files that double as a script and as an importable library.
98
+
If one needs functionality both available as a library and a script, it is better to write is as a library, then import the functionality into a distinct script.
99
+
97
100
### [How do I catch CTRL-C in a script?](@id catch-ctrl-c)
98
101
99
102
Running a Julia script using `julia file.jl` does not throw
0 commit comments