C# Polyglot Notebooks are Here!

Written by Peter Steele

April 4, 2023

Categories: Tech News
Free code on a MacBook

Polyglot Notebooks now generally available in Visual Studio Code Marketplace

The Polyglot Notebooks extension, which allows developers to mix and match multiple programming languages within the same notebook, is now generally available in the Visual Studio Code Marketplace, according to a recent announcement by Microsoft. This feature enables a more flexible and streamlined way to write and share code across different contexts and purposes, without having to switch between separate tools or languages.

What are Notebooks and why they are useful

If you’re not familiar with notebooks, they are interactive computational files that support mixing executable code, visualizations, equations, and narrative text. Notebooks have code cells that allow code to be run in an incremental and segmented manner, unlike traditional scripts that need to be run in their entirety. Popularized by the open-source Project Jupyter, notebooks have become the de facto tool for data science and teaching, and can be used for a wide range of programming and prototyping tasks.

What are Polyglot Notebooks and why they are different

Polyglot Notebooks take the concept of notebooks to a whole new level. The philosophy behind this feature is that developers should always be able to choose the best language for the task at hand, and not be constrained by the limitations of a single language or tool. With Polyglot Notebooks, you can use multiple languages natively within the same notebook, with full language server support, and share variables between them to maintain a continuous workflow. This means you can connect to a database, run queries in SQL or KQL, create visualizations in JavaScript or HTML, and more, all within the same tool and the same notebook.

How Polyglot Notebooks work and what they support

Polyglot Notebooks in VS Code are powered by .NET Interactive, which is an innovative engine built using .NET technology that can run multiple languages and share variables between them. .NET Interactive can behave as a kernel in the context of notebooks, which means it can execute code in multiple languages, including C#, F#, PowerShell, JavaScript, HTML, Mermaid, SQL, KQL (Kusto Query Language), and more.

Key features of Polyglot Notebooks in VS Code

Some of the key features of Polyglot Notebooks in VS Code include:

  • Connecting to and querying Microsoft SQL Server databases and Kusto Clusters
  • Language server support such as autocompletion, syntax highlighting, and signature help for all languages
  • Variable sharing between different languages in the same notebook, for a continuous workflow
  • Ability to create interactive visualizations and narratives using multiple languages and data sources

How to get started with Polyglot Notebooks in VS Code

To get started with Polyglot Notebooks, you will need to install

Once you have these installed, you can create your first notebook by opening the command palette (Ctrl+Shift+P in Windows, Cmd+Shift+P on iOS) and selecting “Polyglot Notebook: Create new blank notebook”, selecting “.ipynb”, and choosing the language you’d like to start with. To change the language of a cell being used, simply click on the language picker in the bottom right of the cell and choose your desired language.

Once they have all the necessary tools installed, they can create their first notebook by opening the command palette (Ctrl+Shift+P in Windows, Cmd+Shift+P on iOS) and selecting “Polyglot Notebook: Create new blank notebook”, select ‘.ipynb’, and select the language they’d like to start with. They should see “.NET Interactive” in the top right as this indicates the kernel being used. To change the language of a cell being used, simply click on the language picker in the bottom right of the cell and choose your desired language.

Feedback

If developers would like to provide any feedback, file any bugs, or request any features, they can file an issue on the .NET Interactive GitHub repository. To learn more, they can visit the Polyglot Notebook Documentation.

Conclusion

Polyglot Notebooks in VS Code are an excellent tool for developers who want to work with multiple languages natively within the same notebook with full language server support. It allows them to share variables between different languages to maintain a continuous workflow. With its innovative engine built using .NET technology that can run multiple languages and share variables between them, Polyglot Notebooks in VS Code is definitely worth trying out for developers who work with multiple languages.

 

Source: Microsoft Blog

Related Articles

Python 3.12 Alpha 6 Released

Python 3.12 Alpha 6 Released

Python 3.12.0 Alpha 6 Released: A Sneak Peek at the Upcoming Changes Python, the popular high-level programming language, has released the sixth alpha version of Python 3.12, giving developers a preview of the upcoming changes. The new release is available for...

AI jobs and Python

AI jobs and Python

The Future of Jobs and Artificial Intelligence Artificial intelligence (AI) and machine learning (ML) have been buzzwords in the technology industry for a while now, with many fearing that AI will replace human jobs. However, the truth is that AI and ML are more...

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
Peter Steele

Peter Steele

Software Engineer/Site Owner

I am a father of 2, happily married and I also love to game! I started this site as a way to pass on what I have learned as a software engineer. Hopefully I can pass on some knowledge to those seeking it and make someone's life just a little better. Happy coding!

Pin It on Pinterest