I developed a decent workflow when I started working with Julia Language about two years ago. I wrote about it a while back in this blog article, "My preferred Julia IDE after 3 months of coding."
Since then, I have polished my workflow so that it is as frictionless as possible for my research project. I still love VSCode and use it exclusively to write my code. However, I learned that using Jupyter Notebook from within VSCode (instead of the web version) is even more convenient. I now use VSCode not only on my own laptop (MacBook Pro M1) but also on my workstation on campus. That way, I can use the 'remote ssh' function of the VSCode to log in to my computer at uni and develop and run any GPU code I need on the workstation while having VS editor open locally on my MacBook.
I abandoned the use of Pluto.jl notebook for Julia because I could not use it from within VSCode, even though I loved some of its features, mainly how it displays the data structures of the cell output.
I was pleasantly surprised recently to discover that there is now an extension for Pluto.jl in VSCode, that allows me to use and run it from within the editor. That way, I can use it on both computers, locally on my Mac and remotely on the GPU workstation.
So, let's see how this works.
First, if you are new to using Julia, here is a brief overview of what it is and how to use it. Otherwise, please feel free to skip to the section about Pluto in VScode.
JuliaLang and how to write Julia code
Julia is a high-level, high-performance programming language for numerical and scientific computing. It was designed to be fast, dynamic, and user-friendly.
There are several ways to use Julia. First of all, you need to install it on your computer. You can download the latest version of Julia from the official website (julialang.org).
Using Julia REPL
Start the REPL: REPL stands for Read-Eval-Print Loop and is the Julia interactive shell that allows you to enter and execute Julia commands. Plain and simple but not efficient for larger projects.
Using a code editor
Writing Julia code using a code editor is a great way to improve your productivity and efficiency when programming in Julia. Here are the steps to get started:
Choose a code editor: There are many code editors available that support Julia, including Visual Studio Code and Sublime Text. Choose an editor that you are comfortable with and that meets your needs. I personally love VSCode! In this article, we will talk about it in more detail.
Install Julia extension: If using Visual Studio Code, you need to install the Julia extension to add Julia language support to the editor. For other editors, there may be a similar process to install a plugin or package that adds Julia support.
Create a new file: In your code editor, create a new file with a
.jl file extension to indicate that it is a Julia file.
Write code: Start writing your Julia code in the file. Your code editor will provide syntax highlighting and code completion to help you write code quickly and correctly. VSCode also lets you hover over any function and provides a popup window with documentation and usage examples, which is very handy.
Run code: you can run the code directly from your code editor. Visual Studio Code has integrated terminal support, so you can run Julia code from within the editor.
Using a Jupyter Notebook from within VSCode
Using a Jupyter Notebook from within Visual Studio Code can be a powerful way to interact with and explore data in Julia. This is what I have done for a while now. Here are the steps to get started with using a Jupyter Notebook in VSCode:
Install Jupyter: You will need to have Jupyter installed on your system. If you don't already have it, you can install Jupyter by following the instructions on the Jupyter website (jupyter.org).
Install Jupyter VSCode extension: To use Jupyter in VSCode, you will need to install the Jupyter VSCode extension. You can do this by searching for "Jupyter" in the VSCode extensions marketplace and installing the Jupyter extension.
Open a Jupyter Notebook: Once the Jupyter extension is installed, you can open a Jupyter Notebook in VSCode by clicking on the "Jupyter" icon in the VSCode activity bar and selecting "Open a Jupyter Notebook." Alternatively, you can create a new file with the
.ipynb extension and then choose the Julia kernel in the top right-hand corner of the notebook so that it uses Julia Language. Jupyter, by default, starts with the Python kernel.
Write and run code: Once your Jupyter Notebook is open, you can start writing and running code in Julia. You can use the Jupyter interface to create cells, write code, and run your code. The output of your code will be displayed directly in the Jupyter Notebook.
Using a Pluto.jl Notebook from within Visual Studio Code
Pluto.jl is a Julia programming language package that provides an interactive computing environment. It is designed to be easy to use and to provide a notebook-style interface for data exploration and analysis, just like the Jupiter Notebook, but specific to Julia.
With Pluto.jl, you can write and run Julia code in a web-based environment, allowing easy sharing of code and results with others. The package also provides features such as automatic outputs, rich media embedding, and support for multiple languages.
Or, as of recently, you can also use Pluto.jl from within the VSCode editor. Yay!
It is still under development and will undoubtedly improve over time, but it's there, and it's working; I tested it.
To use Pluto.jl in VSCode, you will need to install the Pluto.jl extension in VSCode.
You can run your code in a Pluto notebook by using the "Pluto: Open in Browser" command from the Command Palette or by using the key binding Cmd+Shift+P
and choosing "Pluto: Open with Pluto.jl" from the drop-down option (need to scroll) on top of the window.
This integration makes it possible to use the power and convenience of Pluto.jl within the VSCode editor, giving you the best of both worlds - the ease of use of an interactive notebook with the power and flexibility of a full-fledged code editor.
So, if you prefer to use Pluto instead of Jupyter notebooks to prototype your code, now you can do so from within a VSCode editor!