home · projects · papers · blog · gallery · contact ·
anil madhavapeddy // anil.recoil.org


C#, F# and Other Programming Language Fun at PDC 2008

Posted by Anil Madhavapeddy Sat, 01 Nov 2008 16:17:00 GMT

My favourite session of PDC 2008 was by Anders Hejlsberg as he described the Future of C#. Anders is an excellent speaker, and it was educational watching how he made fairly complex type systems come across to an audience more used to simpler programming languages. I say this after attending ICFP recently, where that wasn't true of all the presentations!

The high-level message was exactly what I wanted to hear: in order to exploit multi-core processors more effectively, Microsoft's languages are focussing on improvements in three areas:

  • Declarative constructs: making the programmer define overall goals and constraints enables a tool-chain to more effectively scale computation across multiple processors. An example of this in C# 3.0 is the Language Integrated Query (LINQ) domain specific language for defining queries.

  • Dynamic interoperability: Although Anders is a big fan of static type systems (robust, high-performance, enable intelligent tools), he pointed out that a lot of the systems that C# programmers have to deal with are fundamentally dynamic. Examples are web interfaces such as SOAP/REST APIs, COM objects for talking to other Microsoft applications, or scripting language integration (e.g. Python or Ruby).

  • Concurrent programming: dealing with multiple cores requires splitting up computation into parallel threads, and the resulting parallel mass of code is often hard to debug (e.g. difficulties of reproducing obscure concurrency issues) and statically reason about.

An interesting aside was his assertion about "co-evolution". Microsoft have a number of languages which have recently been unified under the CLR, such as Visual Basic, C# and most recently F#. Rather than have one language race ahead of the others, they like to "borrow" features as appropriate into other languages. This is obviously made easier by having a common run-time foundation, and an example of co-evolution is the introduction of lambdas into C# 3.0 as obviously seen in F#.

Concurrency

Anders observes that all the attempts to automatically parallelize software has not yielded good results in the past, and so support needs to be built into the language to do "top-down" parallelism instead of the compiler inferring it from the bottom-up. To this end, they are introducing parallel extensions into the .NET framework. This makes use of functional features to parallelize code, including LINQ queries or CPU-intensive compute.

For an example of how this code looks, check out Jurgen Van Gael's post on using F# with the Task Parallel Library. I wanted to learn more about this, and wandered over to the Hands On Labs where F# and Visual Studio 10 were all pre-installed. I then ran into an extremely cool feature of F#... asynchronous workflows.

F# introduces an extension to the usual let ML operator in the form of let!. As Don Syme explains on his blog ), this can be interpreted as "run the asynchronous computation on the right and wait for its result. If necessary suspend the rest of the workflow as a callback awaiting some system event". So this construct lets you write straight-line code which can potentially block, without the hassle of spawning threads or encoding continuation passing style constructs in the code. Already a nice improvement over OCaml! (although to be fair I've not had a chance to check out some of the parallel OCaml extensions).

Dynamic Programming

Dynamic programming is the main focus of C# 4.0. In order to support dynamic objects as first-class citizens in a statically typed world, they introduce a dynamic static type. This forces all method resolution on that object to happen at run-time and disables static checks by the compiler (aside from looking from mixups between dynamic and static objects). The dynamic type now makes it easy to wrap support for Python, Ruby and Javascript, since the relevant dispatch functions can all be hidden away in the method resolver at run-time, leaving the programmer with a single syntax for invoking methods across these different languages.

The actual definition of method resolvers is pretty straight-forward; he demonstrated custom getters and setters (similar to Python for example) by using the IDynamicObject interface to define actions to take when properties are accessed. His example did the usual dictionary wrapper which mapped setting arbitrary properties onto an internal dictionary variable.

Another improvement in this space is the addition of optional arguments and labelled arguments. Both of these have well-defined semantics (optional arguments have to come after non-optional ones, and evaluation of arguments is left-to-right) and are purely syntactic improvements with no run-time cost. One of the best examples he showed of using these around COM interoperability. In current versions of C#, due to the lack of named arguments a common function such as "Save As" might require 12 or more stub arguments to be specified as ref missing. Now, those long, repetitive lines can be folded down to only the arguments which are required.

Sort of related to the earlier co-evolution was his demonstration of how similar Javascript and C# syntax is now with this new support. He took a Silverlight 2 code snippet written in Javascript and ported it over to C# 4.0 with some very mechanical changes. The languages are definitely converging fast!

If you're interested in checking out more on this topic, look at IronPython, the Dynamic Language Runtime (DLR), and the TL10 session on dynamic languages on .NET. The DLR is currently maintained as part of IronPython, but is being moved out to sit on top of the CLR for more languages such as Visual Basic, Javascript or COM. The DLR covers common optimizations which are useful for scripting languages, such as call-site caching, dynamic dispatch and expression trees (e.g. for LINQ). The DLR has a bunch of binders which bridge between different backends such as .NET, Silverlight, the native Python or Ruby backends, or COM applications such as Microsoft office.

Meta-programming

Later on at the Future of Programming Languages panel session, Anders talked about meta-programming as being one of the future improvement he's looking at. Currently, there is a lot of ad-hoc code generation in place when creating Windows applications, and unifying this into the language would give safety and maintainability improvements.

In order to do this, for C# 5.0 they are rewriting the compiler to be self-hosting in C#, since it has historically been a C++ application. This permits them to switch the compiler from being a traditional "black box" compiler to a hosted .NET service which can be called directly by .NET programs in order to do dynamic run-time compilation of code. Other portions of the compiler chain are also exposed to permit incremental program construction by third-party code.

He demonstrated this with a pretty nifty C# top-level, into which he directly typed Winforms code to construct a window with a few simple buttons using the C# compiler server. Not to be outdone by this, Miguel de Icaza promptly upstaged Anders at his (fantastic) Mono 2.2 session. He demonstrated the new C# shell which is present in Mono trunk builds and can essentially be used like an OCaml or Python top-level to mess around and manipulate C# code. He also talked about embedded Mono and SIMD support which pushes their compiler ahead of Microsoft's in the 3D performance game.

Summary

I'm firmly convinced about the potential of F# now. I had the opportunity at the Open Spaces area to quiz Scott Guthrie about whether or not F# was a toy language. He replied using the same arguments as Anders that the higher-level language approach (declarative, functional) was very important strategically to Microsoft to let their developer platform continue to survive in a multi-core world.

This boils down to the individual languages not being that important any more (as seen by the sharing of features between C# and F#), and the underlying execution layer (the CLR/DLR) adding efficient support. Now any old language can adopt higher-level features without having to re-do all the optimization grunt work again and again. Much like Xen offers a new golden age for innovative new OS research by freeing programmers from writing a million hardware device drivers, it looks like .NET is ushering in a new age of programming language innovation!

Inspired by the PDC talks, I've got MonoDevelop and F# up and running on my Macbook Air, and am just playing with GTK# and CocoaSharp#. If this works as well as OCaml, then it might finally be time to abandon the old stalwart and move to a new language for my day-to-day stuff!

Posted in ,  | Tags  | no comments

Working through TED videos on the train

Posted by Anil Madhavapeddy Tue, 28 Oct 2008 15:48:00 GMT

I'm over at the Microsoft PDC in Los Angeles this week, and commuting over from Anand's place in Camarillo using the Metrolink. The 3 hour commute gives me a great excuse to catch up on my TED talks on my iPhone.

The entire set of talks is available online via iTunes, and these really stood out:

  • Jared Diamond on Why Societies Collapse : he talks about lots of civilizations which have reached tipping points and have collapsed, often catastrophically. Not a funny or entertaining one, but lots of solid, well-researched facts. Also see his book which George Dunlap recommended to me but is still in my reading list.

  • Mihály Csíkszentmihályi on Creativity, fulfillment and flow : again, a really well-researched talk which categorizes human motivation into a 2D space of challenge vs skill, and the different emotions which are evoked by being in different situations (e.g. apathy requires no challenge and no skill, and anxiety results if you have low skill and a high challenge ahead of you). The "flow" he argues for is the ideal pinnacle of where we should aim to get to in our lives.

  • Finally, what I consider to be the greatest TED talk I've ever seen is by the late Paul MacCready on Nature vs Humans, and what we can do about it : he starts off slowly by showing some graphs about the impact of humanity on the population of the planet (hint: we've taken over), and finishes off with some truly awesome demonstrations of natural planes, such as Ornithopters or solar-powered tiny fliers that do not require gas to fly. Highly recommended if you only watch one TED video at all!

There are about 80 videos left on my viewing list.. this is going to take a while!

Posted in , ,  | no comments

Parsing EXIF/IPTC photo tags using pyexiv2 on Leopard

Posted by Anil Madhavapeddy Thu, 17 Apr 2008 10:58:00 GMT

I've been looking around at refreshing my current photo gallery to make it easier to update, since I'm around 1000 photos behind over the last year. Part of making it easier to use is to adopt an Aperture-based system of marking the metadata directly in the image itself, and figuring out how to render so many pictures more effectively in my gallery.

The best library I could find to do the job is Exiv2 and its associated Python bindings pyexiv2. They use the rather complex Boost.Python bindings, which are a total pain to compile on MacOS X Leopard.

In order to get it to work:

  • Use the latest Fink to install:
    • python25
    • boost1.34.python25
    • libexiv2
    • scons
  • Download the latest pyexiv2 distribution, extract it, and drop in my exiv2 Leopard Makefile into the extracted directory.
  • Type in:
    • make
    • sudo make install.
  • Test it out by running python2.5 and experimenting with importing pyexiv2 (see the pyexiv2 developer guide for more information.

I'll tidy this up into a fink package sometime, but for now I want to press on with finishing my Django experiments.

Posted in  | Tags  | no comments

Sushi, Seattle and Seahawks

Posted by Anil Madhavapeddy Wed, 11 Apr 2007 17:21:00 GMT

Random view of Redmond countryside So I'm hanging at the XenSource Redmond office for a few days, and munching on delicious sushi at Flo, and it turns out that the dude behind us was none other than Matt Hasselbeck! It seems like only two years ago that I was cheering on the Pittsburgh Steelers and the Bus as they owned the Seahawks.

Unfortunately, I only realised my brief brush with celebrity on our way out of the restaurant, which also probably saved me from saying something stupid to him. As if! But anyway, the, err, moral of this post is that you must check out Flo Sushi if you're in Seattle and eat the spider roll, it's awesome.

Posted in ,  | 2 comments

Core stability exercising

Posted by Anil Madhavapeddy Sun, 08 Apr 2007 20:57:00 GMT

It's been a wierd exercise year; I went from hard-core powerlifting (go 220lb bench!), to playing a lot of badminton and tennis, and then ending off the PhD era with breaking my knee (details not suitable for blog publication).
Ajay having a nice stretch

As anyone it's happened to knows, a knee injury is really annoying to recover from as it feels really "wobbly" for ages and can't quite be trusted. I've been doing physio on it myself for about half a year now, and can finally run around for 5km or so without too much discomfort, although yoga and Capoeria are perhaps a few more months away.

But then, the Forrest Gump-class runner and ex-officemate Alex Ho pointed out these amazing exercises by the captain of the CUH&H running team in Cambridge. They all emphasise smooth movement and core strength without the need for heavy weights, so can be done while travelling as well. So highly recommended, that even little Ajay (right) is trying them out!

Posted in ,  | no comments

Karnatik Jazz, Live Painting, and such things...

Posted by Anil Madhavapeddy Sun, 08 Apr 2007 20:28:00 GMT

Had a great evening out in San Francisco on Friday, when we visited the Red Poppy Art House on Folsom Street to check out a really unique Jazz experience.

The boys from VidyA recently took up an artist-in-residence position there, and performed their fusion of traditional Indian Karnatik music with modern Jazz pieces. They've been making some waves in the SF Jazz scene already it seems, and to top it all of, the owner of the art house did a live painting session during the performance. The audience passed out random bits of stuff, and he incorporated it into a piece done over the course of an evening. Talk about artistic overload!

Love the area as well; there's a nice friendly coffee-house down the road (which is pretty much my only criteria, apart from not getting shot and such).

My school was never this cool.
My school was never this cool.
The area was a mix of Latino and African, it seemed
The area was a mix of Latino and African, it seemed
And in the Red Poppy Art House, eclectic art abounds
And in the Red Poppy Art House, eclectic art abounds

Posted in , ,  | no comments

Trac spamming is taking down Melange

Posted by Anil Madhavapeddy Mon, 02 Apr 2007 10:15:00 GMT

After loads of reports that the Melange site keeps going 505 and crashing, I took at look at why. Turns out several spam crawlers were going mental and repeatedly adding tickets with spam links. Around 600 tickets and thousands of comments later, the process decided it had enough and terminated.

I've deleted all tickets (even the valid ones were spammed into oblivion) and turned off comment creation and modification for anonymous users. A look on the Trac Wiki shows that there are some SpamFilter extensions being developed which I'll investigate at some point.

Posted in  | no comments

Hans Rosling at TED last year on global development

Posted by Anil Madhavapeddy Sun, 01 Apr 2007 22:36:00 GMT

Having coffee with AliB and discussing lecturing reminded me of one of the best presentations I've ever seen: Hans Rosling at TED and debunking myths about the developing world.

Even if you're not interested in the subject, it's worth checking out just to see how cool his presentation of otherwise rather boring statistics is. His company, Gapminder also got bought by Google a few weeks ago, so chances are Analytics will get more interesting soon.

Posted in  | 1 comment

Older posts: 1 2 3 ... 12




Copyright © 2003-2006 by Anil Madhavapeddy. All rights reserved.
Original design used with kind permission from Jon Parise.
Valid CSS
Valid XHTML 1.0