Thursday, October 19, 2006

I want an Immediate Window now!

You know the Immediate Window in Visual Studio? If you don't, I hope you'll start working with it right after reading this post - it's a MUST for debugging. Simply put (and it's simple, really), it allows you to evaluate expressions about the currently running application. These expressions are written in simple (say C#) code syntax and can be much more elaborated than just querying a property (like the Watch Window). It's almost like a scripting tool that is available while you're debugging, which compiles on the fly.

That's exactly where my problem is - it's only available at run-time. What I would like is a scripting engine that would receive C# code, compile it on the fly, and give me the output. And I want it from the command line (with intellisense and all)!!!

I know, I know, there is Powershell and a whole bunch of other scripting tools. There is also SnippetCompiler, which is as close as you can get if you want to stick to C# syntax.

I am lazy, and I don't like to have to learn yet another scripting tool to get things done. I have been using Matlab a lot lately, which made me feel how nice and simpler life is when you can use the same syntax for scripting and for writing applications. Matlab is a scripting language. With the command line of Matlab you can do anything you can also do in m-files (files holding Matlab code). So when you just want to test a few things, you can check it with the command line, and once you got the results you like, you can copy-paste it into some persistent files (which you can then embellish and structure). When you have a lot of testing going on, it's a real cool feature. It's also nice if you just want to see the result of something, without needing to persist it into a file at all.

I want this, and I want it now!!!


Ayende Rahien said...

You can try Boo.
It has a tool called booish which gives you just that (but with no intellisense).
I use it all the time.

Ilan Assayag said...

I could, but I don't really want to. Since most of my codebase is in C# (apart for the Matlab stuff), I won't be able to move code from my scripting tests to the code base as easy as I would like it. This leaves me with using it only when I need ad-hoc scripts, and that's not enough.
I could start using Boo in my code base, but that's not really an option right now (not that I know if it's worthwhile frankly).

Really - I want something simple: let me script in C#!
Am I the only one who thinks this makes sense?

Jeffrey Snover said...

Your requirements read like the Powershell documentation. What about it doesn't met your needs?

Jeffrey Snover [MSFT]
Windows PowerShell/MMC Architect
Visit the Windows PowerShell Team blog at:
Visit the Windows PowerShell ScriptCenter at:

Ilan Assayag said...

Well Powershell is indeed a very powerful scripting tool, probably the most powerful of all.
Yet it is not C# - so you have to master another language, and more importantly, you can't easily take code you used to test something with a script and copy it into your C# codebase.
So for ad-hoc scripting, it's excellent (once you get to learn it), but not to mix with C# code.
I know you can call C# code from scripts and vice versa, but that's not what I need - I need the whole code base to be C#. There are also tools that translate from the one to the other, but it becomes cumbersome.
With Matlab, for example, you use the exact same syntax for coding and scripting, so you can take part of a script and put it in your code, or run using the script engine a portion you copied from some module.