CSharpRepl Brings REPL Superpowers To C#
Written by Nikos Vaggalis   
Monday, 21 November 2022

REPL, once an inherent property of the interpreted languages, has now found its way into compiled languages too. Tools like CSharpRepl for C# and Jshell for Java make it happen.

A REPL is an interactive programming environment that takes single user inputs, executes them, and returns the result to the user; input (Read), execute the input (Evaluate), return the result to the user (Print), wait for the next input (Loop).

So what's the deal with REPL? It's all about the immediate feedback loop you get; you can enter program elements one at a time, immediately see the result, and make adjustments as needed. You can evaluate anything;variables, code blocks, functions, even define full-fledged classes and use them in the REPL console, always getting instant feedback, or even use C#/Java as a scripting language for testing purposes and running short lived utility scripts.

This comes in stark contrast with the typical workflow of working with a compiled language:

  1. Write a complete program.
  2. Compile it and fix any errors.
  3. Run the program.
  4. Figure out what is wrong with it.
  5. Edit it.
  6. Repeat the process.

A REPL gives you the option to try out code without that hassle. You can test individual statements, try out different variations of a method, and experiment with unfamiliar APIs. Which makes it great for quick tutorials and prototypes.

Furthermore modern IDE's like VSCode can do REPL without leaving the IDE for the shell which as an extra gives you color themes, autocomplete and syntax highlighting. However the CSharpRepl tool gives you these goodies out of the box in supporting intellisense, installing NuGet packages, and referencing local . NET projects and assemblies, making the need for an IDE totally optional.

As such CSharpRepl provides the following features: 

  • Syntax highlighting via ANSI escape sequences
  • Intellisense with documentation and overload navigation
  • Themes and Colors
  • Automatic formatting of typed input
  • Nuget package installation
  • Reference local assemblies, solutions, and projects
  • Navigate to source via Source Link
  • IL disassembly (both Debug and Release mode)
  • Fast and flicker-free rendering. A "diff" algorithm is used to only render what's changed. 

It also has the advantage of running multiplatform on Windows 10, Mac OS, and Linux.

You install it as a dotnet tool by running:

dotnet tool install -g csharprepl

then running csharprepl once the installation completes. 

Type some C# into the prompt and press Enter to run it. The result, if any, will be printed:

> Console. WriteLine("Hello World")
Hello World

> DateTime. Now. AddDays(8)
[6/7/2021 5:13:00 PM]

The new major release of CSharpRepl 0. 4. 0 brings: 

  • Visual Studio Dark Theme by Default
    The default theme for CSharpRepl has changed from the terminal’s default colors to the Visual Studio Dark Theme

  • New Autocompletion Menu
    CSharpRepl now has a revamped autocompletion menu, with behavior closer to Visual Studio and Visual Studio Code

  • Automatic formatting and indentation of input
    CSharpRepl has always supported multi-line editing, but the lack of automatic indentation and formatting could be frustrating. Now, the multi-line editing experience is much better: automatic indentation kicks in based on the nesting level of braces, and automatic formatting kicks in whenever a brace or semicolon is typed

  • Referencing a solution now references all projects
    Previously when loading a solution into CSharpRepl, only the final project and its dependencies were added as references. Now, all projects in the solution will be added as references. This should especially help when solutions have multiple projects that serve as entry points

  • New configuration file
    CSharpRepl now supports a configuration file that is simply a list of command-line options, one per line, with optional comments. 

 Find it in its GitHub repo

More Information

CSharpRepl GitHub repo

New major release of CSharpRepl 0.4.0

Related Articles

Fable - Write Front-End Apps For The Web In F#

Python and .NET - An Ongoing Saga

 

To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.

Banner


Microsoft Introduces Vector Abstractions Library For .NET
21/11/2024

Microsoft has announced a preview release of the Microsoft Extensions VectorData Abstractions library, which can be used to help integrate vector stores into .NET applications and libraries.



CSS Ecosystem In the Spotlight
06/11/2024

The 2024 edition of the State of CSS has been posted, revealing that the latest features of the language not only do away with extra tooling, but even start taking on tasks that previously requir [ ... ]


More News

espbook

 

Comments




or email your comment to: comments@i-programmer.info

Last Updated ( Monday, 21 November 2022 )