Herding Code 167: Glenn Block on scriptcs

This week on Herding Code, the guys talk to Glenn Block about scriptcs.

Download / Listen:

Herding Code 167: Glenn Block on scriptcs [audio://herdingcode.com/wp-content/uploads/HerdingCode-0167-ScriptCS.mp3]

Show Notes:

  • Intro
    • (00:10) K Scott asks Glenn if he’s still working with Node at Microsoft. Glenn says he’s moved from command-line tools for node and is focused on Azure Mobile Services, but he still owns the Node SDK and the Node story for Azure.
    • (01:56) K Scott scriptcs is another way to write C# code outside of the IDE as script files. It’s inspired by Glenn’s work with Node.js. It leverages Roslyn, NuGet, and some conventions to simplify scripting, such as automatically pulling in NuGet packages.
    • (03:58) K Scott comments on the ability to reference assemblies using the #r directive. Glenn says it’s even easier than that – you can use #r to reference GAC’d assemblies, but assemblies in the local bin folder are automatically referenced. K Scott asks about the hooks to support that, and Glenn explains how Roslyn supports a lot of scenarios; since it ships it as NuGet packages it can be used outside of Visual Studios. Roslyn allows for code to exist outside of a class.
    • (06:33) Jon talks about his initial experiences, and how the REPL made it really easy to get started. Glenn explains how that works and explains how, using Chocolatey you can quickly install scriptcs and a NuGet package like MongoDb and then just start writing code in the REPL.
  • Dependence on Roslyn
    • (09:35) Kevin points out that Roslyn is still in CTP and asks how that impacts scriptcs. Glenn says that since it’s a CTP Roslyn you can’t ship the binaries, but that’s not a problem for scriptcs since it pulls in the public NuGet packages. Roslyn is still evolving, it doesn’t yet support async / await or dynamic, for instance.
    • (11:13) scriptcs no longer takes a dependency on Roslyn. It uses a pluggable script executor which can use Roslyn but can potentially also use other script engines.
  • Example uses of scriptcs
    • (12:33) K Scott asks for some common use cases. Glenn says that it’s possible to build apps because you can have one script that includes other scripts, then talks about the WPF calculator sample in the scriptcs-samples repo.
    • (14:18) Glenn says another use he’s seeing is automation – basically as a replacement for PowerShell. He talks about the Fluent Automation sample which uses script-cs to automate Selenium tests.
    • (15:18) Glenn talks about a real world example at a large trucking company who is using scriptcs to automate data processing jobs.
    • (16:05) Octopus Deploy has added support for scriptcs. He used a loader script that passes configuration to user-written scripts.
    • (17:42) Glenn says it’s useful to tinker and play with libraries or services and give an example of interacting with Azure Mobile Services in the REPL.
    • (18:38) One other example is extensibility – creating hooks and allowing end users to just drop in a scriptcs script to extend behavior.
    • (19:03) Kevin says that in the past people have used JavaScript engines to support extensibility. Glenn says that touches on a common question – why scriptcs as opposed to a lot of other options such as F#, Ruby, node, etc.? He gives two reasons: you get to stay in a language you’re familiar with, and there’s a "grow up" story to migrate from scriptcs to a Visual Studio project using the same libraries, same code, etc.
    • (20:03) Jon says that the PowerShell syntax is different enough that he can’t remember it. He talks about the idea of using scriptcs for installation and initialization scripts in NuGet rather than PowerShell. Glenn says there are kind of ways to use C# with PowerShell, but it’s not the same. He mentions a sample from @beefarino which lets you talk to scriptcs from PowerShell.
    • (23:01) Kevin asks what the migration process is to move from scriptcs to a C# project. Glenn says it depends on how much you take advantage of scriptcs features like Script Packs. Script Packs bring a node-like require module syntax into scriptcs. Glenn talks about the Web API script pack which adds in proper usings and gives you an API that’s very easy to use in script, without IntelliSense. They’ve talked about creating a project exporter which could set up a project and bring in your Script Packs, etc.
    • (26:25) Kevin asks if the Script Pack / Require experience could be brought into standard C#. Glenn says the general concept could work because it’s just a DLL, although there are some incompatible things like import statements. They’ve looked at writing Script Packs as script, which could make this more useful.
    • (28:40) Kevin talks about how the Node module system handles conflicting dependencies and asks if scriptcs handles that. Glenn says not yet, but .NET is now able to handle that so it could be added in. The general idea of script modules depending on other script modules makes sense, but conflicting dependencies might not be very useful. They’re thinking of NuGet packages with no assemblies, just does as content, and talks about some implications.
    • (31:32) Jon talks about how Glenn had told him that a lot of his bizarre feature requests wouldn’t fit in the core but could be useful as extensions, then asks about the extensibility points. Glenn runs through what you can do: change the engine, use Script Packs, bring in NuGet packages, possible later REPL extensions via global NuGet packages. He says they’re following the Node team’s principles of keeping a small tight core and pushing features towards extensions.
  • Questions from Twitter
    • (34:14) Jeff Schumacher (@codereflection) asks Glenn to compare scriptcs performance vs. compiled code. Glenn says that there can be a short startup impact and potentiall
    • (35:58) Akim Boyko (@AkimBoyko) asks if it’s possible to run scriptcs without Roslyn, async/await support and in sandbox mode. Glenn talks about the Mono impact of running without requiring Roslyn support. Roslyn will be getting async/await support at some point, but it could also be added via CodeDom if people implement that. However, CodeDom doesn’t support the classless system that Roslyn does.
    • (38:04) Simon Cropp (@SimonCropp)  asks if scriptcs support plugging into the build pipeline? Eg if I wanted to plug in Fody (https://github.com/Fody/Fody/).
    • (39:41) Several questions on how scriptcs compares to Snippet Compiler, LinqPad and csscript.
    • (41:12) Dan Vanderboom (@danvanderboom) asks if scriptcs let us run a .cs code file by itself anywhere in the file system? Glenn says no and explains why he’s not sure that would be useful.
    • (42:55) Tomasz Janczuk (@tjanczuk) asks When will integration of scriptcs and edgejs be done? 😉 Glenn talks about how the projects have both grown up together and how the two would be useful together.
  • Debugging and IntelliSense
    • (45:29) Jon talks about how he messed something up in the samples and debugged it and asks about debugging support. Glenn points out that you can directly debug an EXE in Visual Studio and explains how to debug scriptcs code in Visual Studio. He also talks about MDbg which Glenn (and apparently everyone else) didn’t know existed. He also mentions a Script Pack for debugging.
    • (48:15) Jon says the REPL is great, and yet he’d sometimes like IntelliSense. Glenn talks about a lightweight WPF editor that’s in progress, but says if you get to a point where things are getting complex it’s probably time to move to move from scriptcs to a project. Jon says that for the most part Script Packs seem to really simplify the code to the point where you don’t really need IntelliSense, and Glenn agrees.
  • Shoutouts
    • (50:45) Glenn calls out the two other coordinators on the project, Filip Wojcieszyn (@filip_woj) and Justin Rusbatch (@jrusbatch) as well as some other top contributors.
  • Shell capabilities, TSR scenarios
    • (52:03) Kevin asks if there are possible changes to make it more shell-like with things like piping. Glenn says they currently have a poor story for arguments, but it’s coming. You can currently pipe text, but he’s not sure about piping objects.
    • (54:30) Jon says he’s got some AutoHotKey scripts and asks if scriptcs could handle that kind of thing.
  • Future plans
    • (56:10) K Scott asks where things are going in the future. Glenn mentions scriptcs modules, aliases, a better Visual Studio experience, export project, and saving DLLs.
    • (1:04:25) Glenn talks about some interesting ideas on GitHub, like a command to break execution into the REPL. They’ve got 20 active contributors, so things are moving fast.
    • (59:54) Glenn says he’s got a personal interest in seeing some adoption in Microsoft – such as adding scriptcs scripting to other projects.
    • (1:00:25) Glenn talks about one question that comes up: should the Roslyn team have tackled the scriptcs scenario?
  • Wrap up
    • (1:01:10) K Scott asks about Glenn’s upcoming plans, speaking engagements, etc.
    • (1:02:27) Jon makes a last minute sales pitch to try it out – you can install in seconds from Chocolatey and just start playing at the REPL. Glenn points one gotcha – scripts which run servers need to be run as admin.

Show Links:

CategoriesUncategorized