BT
x Your opinion matters! Please fill in the InfoQ Survey about your reading habits!

CShell Brings a REPL to C#

by Jeff Martin on May 21, 2014 |

The strength of C# as a statically typed language can also be a weakness when it comes to rapid prototyping and interactively exploring code.  Users of interpreted languages like Python and Clojure have long promoted the ability to use a REPL (Read, Evaluate, Print, Loop)—as a way to rapidly develop software.

Developers with a large investment in C# finding themselves with a desire to utilize REPL functionality without losing the C# language can use CShell created by Luke Buehler from Arnova Asset Management.  In a typical development session with C#, a programmer would have to open Visual Studio and create a new Console Application project.  At that point the code could be written and executed.  CShell simplifies this process, simply open up the CShell to immediately start working on the C# statements that you want to experiment with.

The CShell environment is based on a .CShell file.  It is written using regular C# and allows the user to define activities CShell should perform on startup and shutdown.  For example, the default settings call for the tutorial and a blank scratchpad to be opened.  When CShell is closed, the same file also dictates what actions to take, which in this case is asking for these files to be saved.

    public void OnOpened(Workspace workspace)    {

        workspace.Load(workspace.CShellFileName + CShell.Constants.WorkspaceFileExtension, true);

        Shell.TryOpen("Scratchpad.csx");

        Shell.TryOpen("Tutorial.csx");

    }

    public void OnClosing(Workspace workspace) {

        workspace.Save(workspace.CShellFileName + CShell.Constants.WorkspaceFileExtension, true);

    }

 

The author notes is that the CShell environment, any loaded assemblies and evaluated code all share a common AppDomain, meaning that there is not any separation to protect the shell from errant code.  As this is a scripting environment, this is considered a feature not a bug.  CShell uses the Mono.Sharp compiler to compile and execute entered code in memory.

CShell is part of a broader field that includes scriptcs, LINQPad, and .NET Fiddle.  A Redditor also linked to the Mono project’s own REPL (which does include a functional GUI.)

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Already exists by Miodrag Milic

clojure by Dene Simpson

Clojure is a compiler. It is not interpreted

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

2 Discuss

Educational Content

General Feedback
Bugs
Advertising
Editorial
InfoQ.com and all content copyright © 2006-2014 C4Media Inc. InfoQ.com hosted at Contegix, the best ISP we've ever worked with.
Privacy policy
BT