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
Copy file name to clipboardExpand all lines: lectures/software_engineering/tools_editors.md
+29-12Lines changed: 29 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -26,17 +26,18 @@ kernelspec:
26
26
27
27
While Jupyter notebooks are a great way to get started with the language, eventually you will want to use more powerful tools. Visual Studio Code (VS Code) in particular, is the most popular open source editor for programming - with a huge set of extensions and strong industry support.
28
28
29
-
While you can use source code control, run terminals and the REPL ("Read-Evaluate-Print Loop"), without VS Code, we will concentrate on using it as a full IDE for all of these features.
29
+
While you can use source code control, run terminals and the REPL ("Read-Evaluate-Print Loop") without VS Code, we will concentrate on using it as a full IDE for all of these features.
30
30
31
31
## Installing VS Code
32
32
33
33
To install VS Code and the Julia Extension,
34
34
35
35
1. Follow the instructions for setting up Julia {ref}`on your local computer <jl_jupyterlocal>`.
36
36
2. Install [VS Code](https://code.visualstudio.com/) for your platform and open it
37
+
- On Windows, during install under `Select Additional Tasks`, choose all options that begin with `Add "Open with Code" action`. This lets you open VS Code from inside File Explorer folders directly.
37
38
3. Install the [VS Code Julia](https://marketplace.visualstudio.com/items?itemName=julialang.language-julia) extension
38
39
- After installation of VS Code, you should be able to choose `Install` on the webpage of any extensions and it will open on your desktop.
39
-
- Otherwise, open the extensions with `<Ctrl-Shift-X>` or selecting extensions in the left-hand side of the VS Code window. Then search for `Julia` in the Marketplace
40
+
- Otherwise, open the extensions with `<Ctrl-Shift-X>` or selecting extensions in the left-hand side of the VS Code window. Then search for `Julia` in the Marketplace.
40
41
41
42
See the [Julia VS Code Documentation](https://www.julia-vscode.org/docs/dev/gettingstarted/#Installation-and-Configuration-1) for more details.
42
43
@@ -60,7 +61,7 @@ denote opening the command palette and searching for a command with things like
60
61
your most recent and common commands.
61
62
### Optional Extensions and Settings
62
63
63
-
Open the settings with `> Preferences: User Settings` (see above for opening the command palette with `<Ctrl-Shift-P>`).
64
+
Open the settings with `> Preferences: Open User Settings` (see above for opening the command palette with `<Ctrl-Shift-P>`).
64
65
65
66
As a few optional suggestions for working with the settings,
66
67
@@ -83,7 +84,7 @@ A key benefit of VS Code is that you can use terminals and command-line interfac
83
84
84
85
Furthermore, in the case of julia (and other languages such as python) this will activate the project automatically. See the [documentation](https://code.visualstudio.com/docs/editor/integrated-terminal) for more details.
85
86
86
-
To start a terminal, you can use the `View > Terminal`in the menus, type``Ctrl+` ``, or click on the bottom bar in VS Code.
87
+
You can open the terminal panel with `> View: Toggle Terminal`, typing``Ctrl+` ``, or by clicking on the list of warnings and errors bottom bar in VS Code. If no existing terminal exists, it will create a new one.
87
88
88
89
89
90
(vscode)=
@@ -118,7 +119,7 @@ Type some code as such `f(x) = x + 1` into the file, into the `.jl` file, save i
118
119
:width: 100%
119
120
```
120
121
121
-
At this point, the function is available for use within either the code or the REPL. You can get inline results by adding more code to the file and executing each line with `<Shift=Enter>`.
122
+
At this point, the function is available for use within either the code or the REPL. You can get inline results by adding more code to the file and executing each line with `<Shift-Enter>`.
@@ -138,6 +139,12 @@ Because the REPL and the files are synchronized, you can modify functions and si
138
139
139
140
Next we will go through simple use of the plotting and package management.
140
141
142
+
```{note}
143
+
VS Code typically activates the current project correctly. However, when choosing to enter the package mode, if the prompt changes to `(@v1.6) pkg>` rather than `(hello_world) pkg >` then you will need to manually activate the project. In that case, ensure that you are in the correct location and choose `] activate .`.
144
+
145
+
You can always see the current package location and details with `] st`. See [Julia Environments](jl_packages) for more details.
146
+
```
147
+
141
148
The REPL. First, type `]` to enter the package management mode, then `add Plots`. Depending on whether you have done similar operations before, this may download a lot of dependencies. See below for an example
@@ -152,6 +159,8 @@ Add code in the `.jl` file for a simple plot, and it will be shown on a separate
152
159
:width: 100%
153
160
```
154
161
162
+
To exit package management mode and return to the REPL, type `Ctrl+C`. To then go from the REPL back to the VS Code terminal, type `Ctrl+D`.
163
+
155
164
### Executing Files
156
165
157
166
First we will reorganize our file so that it is a set of functions with a call at the end rather than a script. Replace the code with
@@ -180,7 +189,7 @@ You can execute a `.jl` file in several ways.
180
189
181
190
Within a terminal, you can provide the path to the file. For example,
182
191
```{code-block} none
183
-
julia --threads --project auto hello.jl
192
+
julia --threads auto --project hello.jl
184
193
```
185
194
186
195
See the [REPL](repl_main) section for more details on the commandline options.
@@ -193,12 +202,16 @@ Alternatively, within VS Code itself you can use the `<Ctrl-F5>` to run the new
193
202
194
203
To debug your function, first click to the left of a line of code to create a breakpoint (seen as a red dot).
195
204
196
-
Next, use `<Ctrl-Shift-D>` or select the bug tab on the left in Julia to see
205
+
Next, use `<Ctrl-Shift-D>` or select the run and debug tab on the left in Julia to see
197
206
```{figure} /_static/figures/debugger_1.png
198
207
:width: 100%
199
208
```
200
209
201
-
Then choose the `Run and Debug` option and it will execute `plot_results()` at the bottom of the file, and then stop inside at the breakpoint.
210
+
Then choose the `Run and Debug` option and it will execute `plot_results()` at the bottom of the file, and then stop inside at the breakpoint.
211
+
212
+
```{note}
213
+
Some users may see other options like `Run active Julia file` instead of `Run and Debug` in the run and debug tab.
214
+
```
202
215
203
216
```{figure} /_static/figures/debugger_2.png
204
217
:width: 100%
@@ -226,9 +239,13 @@ There are several ways to start the REPL.
226
239
227
240
The command line options for starting Julia are set to decent defaults for terminals running within VS Code, but you will want to set them yourself if starting the REPL otherwise.
228
241
229
-
One common choice is to choose the number of threads that Julia should have available. By default it is only a single thread, while `--threads auto` will tell Julia to create one for each processor on your machine. VS Code uses `--threads auto` by default.
242
+
As an example, the argument `--threads` determines the number of threads that Julia starts with. If starting `julia` on the command line without specifying any arguments, it will default to 1 (or check an environment variable). To have Julia automatically choose the number of threads based on the number of processors for your machine, pass the `--threads auto` argument.
243
+
244
+
```{note}
245
+
VS Code sets the number of threads automatically based on the number of cores on your machine, but the value can be modified in its `> Preferences: Open User Settings` and then search for `Julia: Num Threads`.
246
+
```
230
247
231
-
The most important choice is the `--project` toggle which determines whether you want to activate an existing project (or create a new one) when starting the interpreter. Since a key feature of Julia is to have fully reproducible environments, you will want to do this whenever possible.
248
+
The most important choice is the `--project` toggle which determines whether you want to activate an existing project (or create a new one) when starting the interpreter. Since a key feature of Julia is to have fully reproducible environments, you will want to do this whenever possible.
232
249
233
250
```{note}
234
251
A key difference between Julia and some other package managers is that it is capable of having different versions of each package for different projects - which ensures all projects are fully reproducible by you, your future self, and any other collaborators. While there is a global set of packages available (e.g. `IJulia.jl` to ensure Jupyter support) you should try to keep the packages in different projects separated. See the documentation on [environments](https://docs.julialang.org/en/v1/manual/code-loading/#Environments-1) and the [package manager](https://pkgdocs.julialang.org/v1/getting-started/) for more.
@@ -279,10 +296,10 @@ As we saw before, `]` brings you into package mode. Some of the key choices are
279
296
280
297
*`] instantiate` (or `using Pkg; Pkg.instantiate()` in the normal julia mode) will check if you have all of the packages and versions mentioned in the `Project.toml` and `Manifest.toml` files, and install as required.
281
298
- This feature will let you reproduce the entire environment and, if a `Manifest.toml` is available, the exact package versions used for a project. For example, these lecture notes use [Project.toml](https://github.com/QuantEcon/lecture-julia.notebooks/blob/main/Project.toml) and [Manifest.toml](https://github.com/QuantEcon/lecture-julia.notebooks/blob/main/Manifest.toml) - which you likely instantiated during installation after downloading these notebooks.
282
-
*`] add Expectations` will add a package (here, `Expectations.jl`) from the activated project file (or the global environment if none is activated)
299
+
*`] add Expectations` will add a package (here, `Expectations.jl`) to the activated project file (or the global environment if none is activated).
283
300
* Likewise, `] rm Expectations` will remove that package.
284
301
*`] st` will show you a snapshot of what you have installed.
285
-
*`] up` will upgrade versions of your packages to the latest versions possible given the graph of compatibility used in each
302
+
*`] up` will upgrade versions of your packages to the latest versions possible given the graph of compatibility used in each.
286
303
287
304
```{note}
288
305
On some operating systems (such as OSX) REPL pasting may not work for package mode, and you will need to access it in the standard way (i.e., hit `]` first and then run your commands).
0 commit comments