Sunday, May 08, 2011

Sparklines in WPF and Silverlight

image

One seemingly-trivial-yet-recurring problem in financial software is the need for a live-updating line-chart. However, from multiple conversations with Lab49 folks, as well as from experience during my first project, I’ve learned that most WPF/Silverlight charting packages suck in various ways, especially if you’re updating their data frequently. Seems like everyone just rolls their own line chart and tailors it to each project, but doesn’t share it for some reason. I’d like to break that trend by sharing and early version of my own sparkline control for WPF and Silverlight.

http://github.com/jschementi/sparkline

Sample Usage:

It’s implementation is very basic; Sparkline.AddTimeValue constructs a point at the next time interval and adds it to a Polyline. You can control the sparkline’s visuals, including adding visible points along the line and showing horizontal lines for the latest/highest/lowest values. The source builds assemblies for both .NET 4.0 and Silverlight 4.

There are obvious features missing like rendered axis or variable x-axis (time) values, but hopefully this provides a simple starting place for anyone else needing a very simple updating line graph.

By the way, Andre de Cavaignac, a colleague of mine at Lab49, and Daniel Simon shared their own a while back: Live Updating Line Graph in WPF. Let me know if there are any others out there.

Anyways, Happy Mother’s Day!

Thursday, February 24, 2011

NYC CodeCamp 2011

This past weekend I spoke at NYC CodeCamp 2011 about the Iron Languages project and dynamic languages on .NET; here are the slides:

Most of the demos were from previous talks, so look through my previous posts on IronRuby and IronPython for relevant demos.

Thursday, October 21, 2010

Leadership of IronRuby and IronPython

Now that I’ve moved from Seattle to New York, started my new career at Lab49, got married, and just got back from the honeymoon, my public techie life can resume. And I’m happy to resume it on a positive note.

Today signifies a big step in Microsoft’s commitment to open-source: Jason Zander announced new leadership for IronRuby and IronPython, namely Miguel de Icaza, Michael Foord, Jeff Hardy, and myself. Since Microsoft has officially put the project in our hands, both languages will be open to contributions from the community, not just the core team members. Also, any previously unreleased work as been released, include the IronRuby tools for Visual Studio and groundwork towards IronPython 2.7 and 1.9. You can find the appropriate releases on both IronRuby and IronPython’s CodePlex sites.

Though Microsoft is no longer directly resourcing these projects, there are definitely companies providing support. Lab49 has been tremendously supportive of my participation in the project, and is interested in supporting the project in substantial ways going forward. Those details will become clearer in the future, but it’s great to see my company taking a proactive role in the projects I’m part of. Also, Miguel is a big-shot at Novell, but I’ll let him comment on how his company is supporting the projects. =)

The reality of open-source software is that corporate sponsorship and funding comes and goes. I'm grateful to Microsoft for starting IronPython and IronRuby, funding it up until this point, and passing the torch to individuals who will continue to progress the languages forward. I’d specifically like to thank Bill Chiles, Dino Viehland, and Tomáš Matoušek, who did the hard work to make this transition happen.

If you’re interested in the future of these projects, please subscribe to their mailing lists (IronRuby, IronPython) and help us to continue making a great dynamic language experience on .NET.

Friday, August 06, 2010

“Start spreading the news”: the future of Jimmy and IronRuby

Though Frank Sinatra says it best, “I’m leaving today” isn’t exactly accurate; my last day as a Microsoft employee was July 23rd, 2010. This post is almost two weeks delayed as Felicia and I have been on the road since the 26th, driving cross-country to the east coast; we also decided to leave Seattle in favor of New York, our home state.

Both decisions were extremely difficult to make, as I will miss all the brilliant people I worked with. Just being in their presence made me feel smarter, and we accomplished some amazing things together. Many were also my friends, making this a very heart-wrenching decision too. However, I joined Microsoft to bring Ruby and other open-source programming languages to the .NET framework, as well as to promote open-source practices in general, and I promised myself to ensure the truth of that statement throughout my Microsoft career. So, when my manager asked me, “what else would you want to work on other than Ruby,” I started looking for a new job outside Microsoft.

While Microsoft’s commitment to dynamic languages on .NET has been questioned many times, my tiny team has been excellent at suppressing those fears with quality implementations of Ruby and Python for .NET, compiler services and language embedding API called the Dynamic Language Runtime, and integration with .NET application frameworks like Silverlight and ASP.NET. And most recently the beginnings of IDE support for dynamic languages in Visual Studio. And all this released under an well-known open-source license, the Apache License (Version 2). This was only possible because my team had the freedom to do what we needed to do to counter those fears and run an effective open-source project

However, a year ago the team shrunk by half and our agility was severely limited. I’m omitting the internal reasons for this, as they are the typical big-company middle-management issues every software developer has. In short, the team is now very limited to do anything new, which is why the Visual Studio support for IronPython took so long. IronRuby’s IDE support in Visual Studio hasn’t been released yet for the same reasons. While this is just one example, many other roadblocks have cropped up that made my job not enjoyable anymore.

Overall, I see a serious lack of commitment to IronRuby, and dynamic language on .NET in general. At the time of my leaving Tomas and myself were the only Microsoft employees working on IronRuby. If this direction for dynamic languages on .NET is a path you do not want Microsoft to take, I strongly suggest you provide feedback to the team’s management directly. Also, Jason Zander runs the Visual Studio team, which IronRuby, IronPython, and the DLR happen to be a part of, and is a big proponent of these dynamic languages efforts, so provide him with your thoughts as well.

That being said, I am still interested in implementing dynamic languages on .NET, so I will remain a IronRuby core-team member, ironically making me the first non-Microsoft core contributor. The bad-news is I will no longer be working on IronRuby full-time, but in the near future I’m definitely staying active. Also, Tomas will definitely continue working on IronRuby when he can; we weren’t the last two people left for no reason. :-)

Given that Tomas and I will only be working part-time on IronRuby now, I invite the Ruby and .NET communities to come help us figure out how to continue the IronRuby project, assuming that Microsoft will eventually stop funding it. I’ll start a thread on the IronRuby Mailing List shortly, so keep an eye on that if you’d like to help. [Update: here’s the thread about the next steps for IronRuby. Join the list and discuss.]

While moving to New York is mainly a personal decision, as both my fiancée and I grew up there and our immediate families are still there, it was also for professional reasons; I’ve accepted a new position at Lab49, a financial technology consulting firm in New York City. I chose the financial industry not just because its dominance in New York, but because I see a lot of similarities between financial software and developer tools. Financial software serves a very technical user, much like programmers, but unlike programmers I know nothing these users, making it a challenging new space. It will be familiar as well, as Lab49 has done work with the new Technical Computing team, which many people who once worked on dynamic languages moved to. Lab49 was also very interested in my IronRuby and IronPython background, so it’s a great next step for me.

I’m grateful to have worked on compilers full-time, outside of academia, while still contributing to open-source, especially at a company that hardly showed up on the open-source radar just 4 years ago. And at least one dynamic language at Microsoft is getting love; IE9’s JavaScript engine, and Microsoft has awesome intentions with it. I’m totally a supporter of most things Microsoft is doing, and I look forward to working closely with them on financial problems. I’m just extremely disappointed with their decisions around dynamic languages on .NET. As one former-teammate’s email signature read, “If your ideas are any good, you'll have to ram them down people's throats.”

I’m looking forward to this new chapter in both my life and my career. Not only am I living in the city that never sleeps, but I hope to build upon my dynamic language work and use it in an area completely new to me. While I expect to still be Ruby and .NET oriented, my posts will be about solving new problems, and should make for some good reading. Stay tuned, and thanks for all the support thus far.

Monday, July 26, 2010

ASP.NET dynamic language support is open source

I'm happy to finally announce that the ASP.NET dynamic language support is now open source:

Download IronPython and ASP.NET integration

For a full IronPython release with the Python standard library, download IronPython 2.7 Alpha 1.

This release contains the source code to Microsoft.Scripting.AspNet.dll, located in the src directory, licensed under the Apache License (Version 2). It will be available in the source repository for IronPython in the very near future, but don't hesitate to start sending in patches. This release is compatible with IronPython 2.7 Alpha 1.

Background

This download enables IronPython as an ASP.NET programming language. To create a new IronPython ASP.NET WebForms project, simply copy examples\web.config and examples\bin, and use examples\hello-webforms.aspx as a reference. A redistributed copy of the IronPython 2.7 Alpha 1 binaries can be found in the examples\bin directory; all files except Microsoft.Scripting.AspNet.dll, the IronPython ASP.NET integration, are from the IronPython 2.7 Alpha 1 release.

For more detail on getting started, here’s a simple walk-through of making the “hello-webforms” app.

Package

Here's what's in the zip file:

  • /License.html - The Apache License, Version 2.
  • /dlr-aspnet.sln - VS2010 solution for examples
  • /examples - Examples of using IronPython in ASP.NET.
  • /examples/Web*.config - configures ASP.NET to use IronPython
  • /examples/bin - Microsoft.Scripting.AspNet.dll, the ASP.NET integration, and a redistribution of IronPython 2.7A1.
  • /src - C# source code that builds Microsoft.Scripting.AspNet.dll

Upgrading

This release renames the main DLL from Microsoft.Web.Scripting.dll to Microsoft.Scripting.AspNet.dll. If upgrading, you'll have to replace all occurrences of Microsoft.Web.Scripting with Microsoft.Scripting.AspNet. This will primarily be at the top of all aspx pages, as well as in your application's web.config. Also note the version number is now 1.1.0.1, which matches all the other Microsoft.Scripting assemblies.

Feedback

As always, please report issues on the IronPython issue tracker. You can also try to fix any issues yourself and submit a patch. Lastly, you can actually talk to humans on the IronPython mailing list.

Enjoy!

Monday, July 19, 2010

Summer of “Iron”: LINQ, Visual Studio tooling, and the Apache License

New releases and announcements from the “Iron” projects have come out over the last couple days, so I wanted to give you an overview of what’s happening, point out the really cool parts, and reiterate some of the motivations.

From a release perspective, both IronRuby and IronPython released new versions of the DLR-based .NET programming language implementations: IronPython 2.7 Alpha and IronRuby 1.1. Click on the respective release name for the full release notes and downloads, but I’ll summarize a bit here:

IronPython 2.7 Alpha

Install IronPython 2.7 Alpha (includes Visual Studio tooling)

This Alpha release is the first IronPython release working towards Python 2.7 compatibility, and contains a number of bug fixes and performance improvements. It also now requires .NET 4.0 or Silverlight 4; you will need to build from source for down-level frameworks. The installer now includes Visual Studio support for IronPython, rather than being a separate installer, and the source-code for the tools has been open-sourced! Keep reading for licensing information …

IronRuby 1.1

Install IronRuby 1.1

Aside from a bunch of bug-fixes, the latest release of IronRuby adds support for .NET extension methods, meaning that .NET programming patterns that are dependent on extension methods, like LINQ, the Reactive framework, Parallel.NET, etc, are now all usable from Ruby code. For example, here’s a simple LINQ example:

For more information see the 101 LINQ samples ported to IronRuby.

Also, since I never announced the IronRuby 1.0 release on my blog … consider this the announcement.

Apache License, Version 2

IronRuby, IronPython, and the DLR are now licensed under the Apache License, Version 2. To address all concerns around “why” this is changing, it is solely in reaction to feedback about the licensing terms from users and the .NET/Python/Ruby/dynamic-language communities at-large. The Apache License is a more familiar and popular license to those communities than the Microsoft Public License; using it should lower any license-related barriers people encountered in the past when considering these programming-language implementations.

Enjoy!

Tuesday, April 27, 2010

MIX10, Part 3 - Using dynamic languages in existing web-applications

This post is part of the “MIX10 – Pumping Iron on the web” series:

The original post was mistakenly removed, so it’s been reposted with the original post date, 4/27/2010. Sorry if this confuses your blog readers or causes any other inconvenience.

Up until now I've discussed how to use dynamic languages to power both the server-side as well as the client-side of your web-application, but what if you want to apply these methods to solve certain problems in an existing application?

Testing

A low-risk, high-benefit use of dynamic languages in your existing applications is for testing. This helps make the act of writing tests simpler, and quite possibly more fun, encouraging your team to actually maintain the test suite.

Before looking at how to test web-apps, let's take a brief look at what a test written with RSpec, a popular Ruby testing framework, looks like:

Note: there are Ruby testing frameworks that look a bit more like what you might be used to. The following is an equivalent test written with test/unit, and this will give you a better idea of the structure of the above example:

The RSpec snippet almost reads like english, making it very clear what the intended behavior of Stack is. Also, it shows the power of Ruby for creating internal DSLs; a "language" built out of the constructs of an existing language. describe and it look like language keywords, but in-fact they are really just methods, because Ruby has optional parameters (as we discovered earlier with Sinatra). Using actual strings as the test name, rather than a method name, allows you to describe the test accurately. Each object has a should method which makes any subsequent calls part of an assertion, making it very obvious which value is the "expected" value and which is the "actual".

The crazy thing is how little code is required to make that work; 24 lines of Ruby. The key points are that yield executes the do-end block passed to a method, and the should method is added to every object, turning any subsequent methods calls into an assertion:

However, please don't use this example as your real testing framework, and then get mad at me when it doesn't have a feature you want; RSpec, Bacon, or test/spec are much more mature testing frameworks that support this same syntax.

See my previous post about using IronRuby to test C# Silverlight applications; it’s still relevant though it’s a fairly old post.

Hosting

IronRuby and IronPython are built on-top of the Dynamic Language Runtime, which is comprised of many parts, one of which being a .NET Hosting API, allowing you to embed a scripting language in any .NET app.

Now we come to the "ah-ha!" moment of the talk; everything you've seen in the MIX10 posts is made possible by this API. Keep in mind these languages are built on .NET, so their implementations are accessible from any .NET language. C# and VB today are not built on .NET; they just compile programs to run on .NET, which is why you can't easily host those languages today.

Here's the catch; since these language engines are built on .NET, they need to run in a .NET application. So, all Ruby or Python code runs by hosting the languages inside a .NET application. We do things to make this seamless in specific environments: for example, ir.exe and ipy.exe are both .NET programs which host the language and run the code in a command-line, mimicking the behavior of ruby.exe and python.exe. Here are some other popular hosts:

  • ipyw.exe: runs scripts in a console-less program for Windows applications
  • Microsoft.Scripting.Silverlight.dll: entry-point for Silverlight applications which run HTML script tags and scripts inside the XAP
  • IronRuby.Rack.dll: run rack-based applications on IIS
  • Microsoft.Web.Scripting.dll: run Python in ASP.NET
  • System.Web.Mvc.IronRuby: run Ruby in ASP.NET MVC

However, we can't provide "runners" for every environment that will spring up, so we allow you to use the same APIs that these runners use in your own apps. These APIs have been kept very simple, as we want any .NET developer to be able to use a DLR scripting language in their applications.

But why embed a scripting language into your application? The main scenario is to scripts as an extensibility mechanism, either internally or as functionality you provide for your end-users. Here are a few concrete examples of what scripts could be used for:

  • An advanced search/filter (letting users use LINQ safely)
  • High-level business logic to computing prices of items, applying discounts, etc; any type of rules engine
  • A system which changes behavior based on external data
  • Customizing a single codebase for different clients
  • Add-ons for end-users to make your application better (eg. Facebook)
  • Making application logic simpler to read than the core of your system (polyglot)

Let's show you how to do the basics, and hopefully that will spark your imagine to think up other cool use-cases:

  1. Create a new web application project in Visual Studio 2010, and open the Default.aspx.cs page.
  2. Place a label on the page and call it “Message”.
  3. Add references to the necessary DLLs to host IronPython (IronPython.dll and Microsoft.Scripting.dll)
  4. Write the 5 lines of code to update the label’s text from Python:

There are basically three types you need to know; ScriptRuntime, ScriptEngine, and ScriptScope.

  • ScriptRuntime is a level of encapsulation for your scripts; it represents the DLR scripting runtime, and all script operations go through it.

  • ScriptEngine is the type that is returned from ScriptRuntime.GetEngine; it represents a DLR-language. In this case, we asked for the language by name, as that's the easiest way to keep it easily configurable, but the downside is you need language configuration info in your App.config. However, if you only want to depend on IronPython, you can use IronPython.Hosting.Python.CreateEngine(), which does all the setup for Python for you.

    The ScriptEngine enabled you to execute code in that language, in a variety of ways, from the basic engine.Execute method (essentally eval), or being more fine-grained engine.CreateScriptSourceFromString(code).Compile().Execute(), which parses the file, compiles it, and then executes it. Code can be executed against a ScriptScope to set initial state and share state between executions.

  • ScriptScope defines the state for your script; like what variables/methods are present. It is a dynamic object, so you can do things like scope.page = this, and that will set the page variable for scripts that execute against the scope. In downlevel .NET frameworks, you'd have to use scope.SetVariable(page, this).

Slight aside: since these APIs are .NET based, the dynamic languages themselves can consume them to run other dynamic languages! For example, here's Ruby executing Python code through the DLR Hosting APIs:

What's also interesting is the dynamic languages can communicate between each-other just as easily; here's Ruby calling Python code:

Anyway, hopefully this sparks some creativity! For more web-related information, also posted about this in relation to Silverlight applications: Scripting C# apps with IronPython.

The next post will show some cool applications of this … (coming soon).