A Brief Look into .Net Interactive in Visual Studio Code
In this week's Writer's Room blog, Andela Community member Haymanot Tamrat explores using .NET interactive in Visual Studio Code.
In early 2020, to get started and explore dotNET REPLs, a NET developer had to install Anaconda, Jupyter, and Python. Now, all a developer has to do is install a single Visual Studio Code extension (keeping in mind that they already have VSCode and NET SDK in their toolbox).
First, let's create a .NET Interactive notebook in VSCode. We can create ipynb or dibformat notebooks. ipynb is the default and most widely known format on Jupyter notebook. dib format is designed to be used in VSCode and only used in .NET interactive notebook.
Ctrl + Shift + P opens the command pallet; from the pallet, we can simply create .NET Interactive: Create a new blank notebook.
Cells in the notebook can be of any type (C#, MarkDown, JS, HTML's —). Each language supported by .NET Interactive has IntelliSense support. Multiple languages can be combined in a single notebook. A cell with a different language can also use the variables and properties of another cell with a different language.
.NET Interactive has magic commands that can boost productivity. Unlike Jupiter notebooks, magic commands in .NET Interactive Notebooks have a prefix #!. For instance, #!DateTime. Some magic commands take an argument like #!csharp -h.
Let's recap polyglot - mixing or combining multiple languages in a single notebook with the ability to access the variable of another language between cells is possible in .NET Interactive. This polyglot behavior enables developers to extend the notebook to a different level.
Visualizing charts, and diagrams are smart ways to interact with educational notebooks. By extending .NET Interactive using the NuGet package extension lab, we can create a diagram and chart with a popular language called Mermaid.
This installs Microsoft.DotNet.Interactive.Extensionlab to our notebook project.D3.js library, and can also be used for custom visualization in our notebook projects. With the magic of polyglots, we can bind CSharp language with the HTML and JS cells to mutate the visualization and render SVG in real-time.
Even though .NET is not as extensive regarding machine learning compared to python, .NET Interactive narrow downs this gap by offering a rich, interactive approach to practicing ML in .NET. We can use NuGet packages to leverage ML.Net to create supervised and unsupervised training models. Regarding ML, .Net interactive is like a Jupyter notebook with ML.Net to practice and train models.
Imagine not creating a full scaffold web API project to only include a REST request on a notebook for educational purposes, or even wanting to explore an API from a different REST client? This is possible! With .NET Interactive, we can use a single cell in the notebook to practice the ASP.NET application without creating a full project.
In this article, we've explored .NET Interactive in VScode. Its simplicity in hooking the notebook in a developer workstation is fascinating (we only have to install a single extension). NET Interactive offers full educational support within its Net education pack, and having kernel support for multiple languages makes it the favorite notebook for .NET developers. I hope this article gets you excited to explore.NET Interactive!
Want to be part of the Andela Community? Then join the Andela Talent Network!
With more than 175,000 technologists in our community, in over 90 countries, we're committed to creating diverse remote engineering teams with the world's top talent. And our network members enjoy being part of a talented community, through activities, benefits, collaboration, and virtual and in-person meetups.
While synchronous collaboration was the preferred method for many global organizations, remote work has increased the popularity of asynchronous communication. But which is more beneficial, both to employees, and to business?
What will the tech industry look like in 2024? Read our predictions on how work structures, African tech talent, human-GenAI collaboration, and diversity and inclusion will shape the future of technology and your team.