
CShell: A simple, yet powerful, C# scripting IDE - rayvega
http://cshell.net/
======
jasonkester
Well presented. I clicked the link and spent my loading-spinner time thinking
thoughts along the lines of "This is silly. Why would anybody build a C# IDE
to compete with VS.NET + ReSharper? Surely nobody would ever use anything but
that??? I can't believe that anybody would be cheap enough to..."

... and then I arrived at a page that spent ten seconds clearly explaining
exactly why I would want to use this thing even though I have VS.NET already
installed on my machine.

A lot of open source & developer-facing small product sites in the world would
be well served to read the contents of this page and study exactly what the
author did there.

Well done!

~~~
codexon
The title would have been better if it said C# REPL. Then you wouldn't have
experienced that confusion.

------
blunte
I guess I'm old. My first thought was
[http://en.wikipedia.org/wiki/C_shell](http://en.wikipedia.org/wiki/C_shell)

~~~
jjoergensen
It probably should have been named CSShell :-)

~~~
egeozcan
But I read it as CSS hell. Maybe SharpShell? Anyways, both are better than the
original IMHO.

By the way, this is really useful. Loaded all our app libraries and works like
a charm. I feel much more productive now except for the fact that it made me
comment on HN =)

~~~
Pxtl
SharpShell would be a great name - fun alliteration and pretty clear what it's
for.

~~~
lukebuehler
I like it, will consider it. The naming is a bit unhappy, I agree.

------
j_s
Nice to see another entrant in this space, offering functionality beyond
LINQPad⁰ and the old SnippetCompiler¹. Microsoft has experimented with a REPL
of their own² but there's nothing official yet.

Mono's REPL³ (MIT X11/GNU GPL; 2008) still has some rough edges on Windows.
CS-Script⁴ (MIT; 2009) seems to have received the widest use but was hampered
by a weird license until recently. Microsoft MVPs have stepped into the ring
with scriptcs⁵ (Apache; 2013) based on the brand new Roslyn tech.

⁰
[https://www.linqpad.net/CodeSnippetIDE.aspx](https://www.linqpad.net/CodeSnippetIDE.aspx)

¹
[http://www.sliver.com/dotnet/SnippetCompiler/](http://www.sliver.com/dotnet/SnippetCompiler/)

² [http://stackoverflow.com/questions/1187423/anders-
hejlsbergs...](http://stackoverflow.com/questions/1187423/anders-hejlsbergs-c-
sharp-4-0-repl)

³
[http://tirania.org/blog/archive/2008/Sep-08.html](http://tirania.org/blog/archive/2008/Sep-08.html)

⁴ [http://www.csscript.net/index.html](http://www.csscript.net/index.html)

⁵ [https://github.com/scriptcs/scriptcs](https://github.com/scriptcs/scriptcs)

~~~
lukebuehler
The sweet spot between a more full featured IDE like VS, LINQPad, or
SharpDevelop and a REPL environment has not been explored very much so far.
Even ScriptCS is more of one-off execution kind of setup, although they do
have a REPL.

Filling this gap is what I tried to achieve with CShell. When I started, the
Mono REPL was quite a bit ahead of Roslyn still, but now Roslyn overtook it.
I'm planning to switch to Roslyn for the execution engine and use NRefactory
for the code completion still (especially now that Roslyn is open source).

Where I want CShell to go, is it being a light-weight IDE with a focus on
iterative execution. I use LINQPad evey day for DB stuff for example, but when
I want to write progressing code, usually exploring some kind of data space -
where I test each line, plot some charts, look at the data the variables
contain - then there's no real competitor so far for C#. Either you have
Matlab, R one one side, or linear code execution environments on the other.

------
uggedal
Why don't people do a quick search before naming things:
[http://en.m.wikipedia.org/wiki/C_shell](http://en.m.wikipedia.org/wiki/C_shell)

~~~
thwarted
Maybe it really means "C Sharp Hell".

------
ahy1
A combined REPL and editor for C# looks useful. I will try it next time I have
some spare time.

The name is confusing. A C shell already exists
([http://en.wikipedia.org/wiki/C_shell](http://en.wikipedia.org/wiki/C_shell)).
An alternative name could be CSharpShell. Btw, while googling that name, I
found CsharpRepl, which seems to be a somewhat similar tool.

~~~
fish2000
These tools straddle some Venn circles, so the developer pitch can be
confusing.

For example, I make use of both ipython and bpython, both of which I refer to
as either shells or REPLs; though neither program is a proper shell (in the
/bin/chsh sense), and though people also call them “interpreters”
(technically, the python interpreter still interprets), “environments” (vague)
or even “IDEs” (wat?) – the concept behind the tools is popular and well-
understood.

Personally I think it’s particularly funny to call these Enhanced REPL Shell
Interpreter Environments (or what have you) “IDEs” and lump them in with
Eclipse or Visual Studio or those other behemoth coding tools; I like bpython
and ipython for the myriad ways they are un-Eclipse-y, and if I did C# I would
presumably get into CSharp for the same reasons. All of which, like many
bicycle-shed innovations, are mere matters of taste.

------
xedarius
Not very often you find a hedge fund behind an open source project. I guess it
makes sense really, as many quants will be happy to mess around in a python
shell, having a C# shell will probably play nicer with the rest of the
companies infrastructure.

~~~
jimmcslim
There are a few hedge funds that are quite happy to contribute open-source to
the world.

Blue Mountain Capital for example;

[https://github.com/BlueMountainCapital](https://github.com/BlueMountainCapital)

One of their projects is Deedle; an F#/C#-equivalent of the Python 'Pandas'
data frame package. Which would in fact make a nice complement to CShell I
imagine.

Jane Street would be another choice:
[http://janestreet.github.io/](http://janestreet.github.io/)

Their work on OCaml is currently trending on HN.

There are others I am sure, don't have any links handy.

Who'd a thunk it, hedge funds occasionally produce some social good ;-)

~~~
bjoerns
wow, didn't know that. thanks for putting together that list - maybe we should
start a list somewhere where people can add, this is definitely super
interesting.

~~~
echion
Agreed - here's another one (I am not affiliated):
[https://github.com/renshawbay/](https://github.com/renshawbay/)

------
ahmett
Scriptcs is out there for quite some time now.
[http://scriptcs.net/](http://scriptcs.net/) it also has the motto "Unleash
your C# from Visual Studio."

It provides you proper scripting abilities by using other libraries, writing
classes in the REPL and scripting, like proper scripting languages. CShell
just seemed like a windowed application whereas Scriptcs also runs on Unix
environment with Mono I guess.

------
QuadDamaged
A C# REPL is welcome indeed, but C# is still too verbose for its own good. The
F# REPL is much more useful when exploring dataset.

~~~
pjmlp
Although it could be improved with intellisense.

------
mojuba
The point of scripting is to do things quickly at the expense of possibly
being ugly. Most of the things we do in the UNIX shell are one-off local
stuff. I want to rename all file extensions in a directory. I want to find a
regex in files ending with _.c and_.h excluding the .svn and .git directories.
Etc etc.

So I'm sorry but a "scripting" language whose print operator is longer than 5
chars is not a scripting language :)

~~~
egeozcan

        Action<object> print = Console.WriteLine;
    

I mean, it's not perfect but you can also create a .Dump() extension method
for all objects like Linqpad does. It comes really handy.

------
lukebuehler
hey, I'm the developer of CShell, nice for this project to get some love. I'm
aware of some of the shortcomings. Will definitely read you guy's comments and
see what I can do.

------
dukeNukem64
Similar:
[https://github.com/drew-r/maverick](https://github.com/drew-r/maverick)

Provides a Lua REPL with access to the .NET framework. Also allows you to run
mini-apps made up of a combination of C# 'scripts' and Lua scripts.

------
guiomie
First of all, let me say this is something I've wanted for a while, so good
job and thank you to the author.

When I try the Tutorial.csx, I can't get this snippet to work:

static class MyMath { public static long Fibonacci(long n) { //anything more
than 48 will result in a stack overflow. if (n >= 48) throw new
ArgumentException("Enter a number less than 48"); if (n == 0) return 0; if (n
== 1) return 1; return Fibonacci(n - 1) + Fibonacci(n - 2); } }

// Now the method can be called like so: MyMath.Fibonacci(12);

It gives me : "(14,0): error CS1525: Unexpected symbol `MyMath'" in the repl,
anyone knows why?

~~~
lukebuehler
Yep, I see the tutorial is not clear, will change it.

Anyhow what you need to do is simply select line 35-45 with your cursor, then
press Alt+Enter.

And then, after that, execute MyMath.Fibonacci(12);

------
stinos
Also see
[http://www.hanselman.com/blog/ProjectlessScriptedCWithScript...](http://www.hanselman.com/blog/ProjectlessScriptedCWithScriptCSAndRoslyn.aspx)
\- no REPL though, although that would be easy to create since there's a
SrciptingEngine for C#
([http://blogs.msdn.com/b/csharpfaq/archive/2011/12/02/introdu...](http://blogs.msdn.com/b/csharpfaq/archive/2011/12/02/introduction-
to-the-roslyn-scripting-api.aspx))

~~~
jimueller
ScriptCS does have REPL. Maybe it didn't at the time of that article.
[http://scriptcs.net/](http://scriptcs.net/)

------
bruceboughton
I've just started using scriptcs
([http://scriptcs.net/](http://scriptcs.net/)) and this looks pretty similar.

I'm not sure about the name. CShell implies C not C#.

~~~
mel919
Looks like uppercased CS is a play on a file extension and a shortcut
sometimes used for C#. Personally, I read it as CS-hell.

------
V-2
I'm getting "(35,0): error CS1525: Unexpected symbol `static'" trying to run
Tutorial.csx (when MyMath is uncommented), whether running the entire script
or just the class and the MyMath.Fibonacci call alone, by Run Selection (then
it's "Unexpected symbol `MyMath'").

public static class Foo { public static string B; } Foo.B = "5";

doesn't work either ("Unexpected symbol `Foo'").

I really don't get how to use that thing.

~~~
lukebuehler
the thing is you can't really mix class definitions and straight scripting
lines in one execution. So what you need to do, is execute the class first and
then execute the other part.

For the MyMath example you'd just select the lines for that class, press
Alt+Enter. And then run: > MyMath.Fibonacci(12);

With your example, you would enter following in the REPL: > public static
class Foo { public static string B; } > Foo.B = "hi" > Foo.B hi >

~~~
V-2
Thanks for clearing that up. I believe this should be explained more
specifically in the tutorial.

------
S_A_P
I mean this as truly constructive criticism. There are several spelling errors
on the site that made me want to cringe.

It allows you to use C# without any fluff right in a console like environment
_caled_ a read-eval-print-loop (REPL).

CShell is a project sponsored and maintained by Arnova Asset Management Ltd.,
a quant _hege_ fund, which uses CShell daily for their research. The main
contributor from Arnova is @lukebuehler.

That said I like this idea and look forward to trying it.

------
xiaq
Mono has had a C# repl for quite some time: [http://www.mono-
project.com/CsharpRepl](http://www.mono-project.com/CsharpRepl)

Good to see the same thing coming to vanilla .Net!

------
Systemic33
This is exactly what i need to test out if some code behaves how i want it to,
without having to create a new test, open a new project or running code in
actual project.

------
cadab
I want this, but with nuget support. LinqPad seems about the best option, but
i don't need all the SQL/Database stuff that comes with it.

------
iamsalman
This may be useful for loading GBs of data and it's quick exploration but I am
wondering if there are any other uses for it besides that?

~~~
rtpg
well it's as useful as any other REPL ;)

Though for things like Python the REPL serves for me mainly as a 'figure out
what type this thing is here' and 'does this work'... things that static
typing solve pretty well.

------
NicoJuicy
I should look into it, but it seems to support multiple lines. So the ideal
use case would be to add a seperate window into Visual Studio

~~~
cyphax
Wouldn't that more or less be the Immediate Window that Visual Studio already
has? Other than the multiple lines you mention. :)

I took a look at this to see if it can replace LinqPad, which is similar.
LinqPad allows for more than C# alone (VB.net, SQL, C# and F#) but it has no
code completion (unless you buy it) which CShell does have.

This seems like a useful tool!

~~~
rikkus
I highly recommend buying a LINQPad licence. I use it several times a day now
and it's so much better with the extra features.

My favourite feature is the ability to point it at a DLL which has an entity
data model in it - and then work with that model 'live' as if you were inside
app code.

Normally, to do that, you'd have to put a breakpoint in your app and use VS's
Immediate window - which doesn't support useful stuff like lambdas.

------
Pxtl
... you know that whole PowerShell thing MS made?

They should've just skipped that and made this. Hot damn, neat!

------
V-2
What "I/O error occurred"? I mean the IntelliSense hint on the screenshot.

~~~
mattmanser
Looks to me like the description of `System.IO.IOException`, which is the
possible exception.

I would guess the tool tips are slightly broken in that it doesn't list the
exception class name or put it on a new line.

There you go, simple thing to contribute a fix for!

~~~
V-2
Good point, I might go ahead and make a patch.

------
ufmace
Just tried it out, and it looks pretty awesome - I always wanted a real REPL
for C#.

------
CmonDev
Seems dead - last commit ~1 year ago?

------
bjoerns
this is pretty cool, thanks for sharing! will see if I can integrate this with
Excel-DNA.

------
NKCSS
Very cool and useful, thanks!

------
rjfwhite
Unity3D port anybody?

------
mariusmg
As much as i like C#, static typed languages are inadequate when using them in
shell. You really don't want to type all that.

Powershell has access to the BCL and can do all that with a nicer syntax when
using it in the shell.

~~~
alkonaut
If your language has you type more because it has a static ype system then
it's just poor at inferring types and/or it's syntax has you write out things
that it could infer anyway. You may have to write types in C# from time to
time, but often you don't have to:

// This an array of integers.

var x = new[]{1, 2, 3};

// This is a list of integers.

var y = x.ToList();

// This is an anonymous type.

var pet = new { Age = 10, Name = "Fluffy" };

Zero type names there. Not all types can be inferred by literals though, most
annoyingly dictionaries:

var myDict = new Dictionary<string, string>{ { "test", "test" }, { "test2",
"test2" } };

although I'm sure that could also have been created without typing out the
name if you really wanted.

~~~
JoeAltmaier
Inferring types is cool, if it doesn't create bugs. But it does. Its not a lot
of work to just say it outright, and it can save your life.

~~~
nlawalker
Can you elaborate? I'm not sure what you mean.

~~~
JoeAltmaier
Unexpected conversions can add bugs. Putting a string into a table that was
implicitely integer - if your string doesn't start with digits it gets
converted to zero. Was that what you intended? Did you think the table would
hold a string?

~~~
dnissley
Type inference in C# with the var keyword doesn't work like a dynamic language
like javascript. It works by simply using var as a placeholder for whatever
type the right hand side returns, which is determined at compile time.

~~~
JoeAltmaier
So the type depends upon the initial values, which might not be representative
of your full intent? A list of strings doesn't guarantee you won't want later
to put something else in there.

I guess you'd just have to declare it explicitly in that case.

~~~
laumars
But you could explicitly declare the string table and still try to put an
integer into it. Your example isn't an issue of type inference, it's an issue
with the developer not properly tracking what variables store what types in
his/her own code.

