Quantcast
Channel: Category Name
Viewing all articles
Browse latest Browse all 10804

Interactive Coding with C# and F# REPLs (ScriptCS or the Visual Studio Interactive Window)

$
0
0

REPLs are great! REPL stands for Read–eval–print loop and is pronounced "REP-L" quickly, like "battle." Lots of languages and environments have interactive coding and REPLS at their heart and have for years. C# and F# do also, but a lot of people don't realize there are REPLs available!

ScriptCS

In 2013 once the Roslyn open source C# compiler started to mature, Glenn Block and many friends made ScriptCS. It now lives at http://scriptcs.net and has a great GitHub and active community. The Mono project has also had a REPL for a very long time.

The C# Interactive Shell CSI

You can install ScriptCS in minutes with the Chocolatey Package Manager or OneGet with Chocolatey on Windows 10. In the screenshot above I'm writing code at the command prompt, making mistakes, and fixing them. It's a great way to learn and play with C#, but it's also VERY powerful. You can create C# Scripts (.csx files) kind of like PowerShell but it's just C#!

Visual Studio's REPLs - CSI and FSI

The Visual Studio team meets/met with the ScriptCS folks in the open and even publishes their meeting notes on GitHub! In May of last year they got ScriptCS working in OmniSharp and Visual Studio Code, which is amazing. There's a great set of directions here on how to set up ScriptCS in Visual Studio Code and the code is moving fast on GitHub.

Visual Studio 2015 Update 1 has REPLs within the IDE itself. If you have Visual Studio 2015, make sure you've updated to Update 1. If you don't have VS, you can get the free Visual Studio Community at http://visualstudio.com/free.

VS ships a command line RELP called "CSI" that you can use to run ".csx" scripts as well. Turns out the source code for CSI is basically nothing! Check it out at http://source.roslyn.io/#csi/Csi.cs and you can see how easy it would be for you to add scripting (interactive or otherwise) to your own app.

C# Interactive REPL inside Visual Studio

There's a great C# Interactive Walkthrough by Kasey Uhlenhuth that you should take a moment and play with. She's the Program Manager on this feature and also has a great video on Channel 9 on how to use the C# Interactive REPL.

Introducing the Visual Studio 'C# REPL'

Of course, F# has always had a REPL called "fsi.exe" that also ships with VS. You may have this on your PATH and not realize it, in fact. F# script files are ".fsx" so there's a nice symmetry with scripting and REPLs available in both languages, either in VS itself, or at the command line.

The F# Interactive Shell

F#'s REPL is also inside VS, right here next to the C# Interactive Window.

C# Interactive and F# Interactive in VS

These are all great options for learning and exploring code in a more interactive way than the traditional "write, compile, wait, run" that so many of us are used to.

Let's hear in the comments how (or if!) you're using REPLs like these two make your programming life better.


Sponsor: Big thanks to Wiwet for sponsoring the feed this week. Build responsive ASP.NET web appsquickly and easily using C# or VB for any device in 1 minute. Wiwet ASP.Net templates are integrated into Visual Studio for ease of use. Get them now at Wiwet.com.



© 2016 Scott Hanselman. All rights reserved.
     

Viewing all articles
Browse latest Browse all 10804

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>