Meta programming in C#


I've seen a few posts flying round between Ivan (1,2)
and Ayende (1) re: meta programming in C# and the implications of it being a statically typed / pre compiled language...

It's an interesting thought, but I can't help wondering if implementation of a rich meta-programming environment in C# - allowing changes at both a class and instance level at run-time - wouldn't go against the original spirit of the language itself, for me at least I'd be looking for a different language if I yearned for meta programming on a daily basis... one that was built from the ground up with my desires in mind.  Take a moment to consider if C# had been built with meta-programming in mind from the outset, would we have bothered with declarative attributes?... ruby seems to get on fine without them (well at least until you try to integrate ruby with Java or .Net libraries)... and what about interfaces, what's the point of them?

Language spirit is an interesting thing - I don't think it's something intangible (this is science after all), but often it's something that's difficult to put into words, because it's a feeling coming up from a rapid and subconscious judgement call as you work with a language (ah la Blink) - it's also something that's difficult to appreciate until you start sitting down and thinking about writing a programming language of your own (what you haven't? For shame!)... and it builds an immediate appreciation for languages like C# and ruby and there founders - there are lot of difficult decisions, compromises and reasonable defaults that need to be decided on - and a massive amount of jiggling to make sure it all fits well together - so that you can finally identify the essence of the language - and worst of all you're not just having to satisfy your internal subconscious judgement calls, but a large audience in the development community, so that your language will be adopted by people because it feels "right" to them.

I still gravitate towards  programming language pragmatics as a good book for examining the spirit of languages throughout the years and guises - it's definitely a book computer science student's should all be armed with on their first year, though I doubt many will be interested in the nuances of Fortran today.

Now, following up on that - I'd like to contrast meta programming with functional programming... are we in need of meta programming as we move towards a more functional approach by necessity (to reduce the overall complexity of software, and take better advantage of existing/emerging hardware by working at a higher level of abstraction, allowing for judgment to be made on our behalf i.e. about parallelization) and what makes more sense for a language like C#?

Personally I see C# moving more and more towards providing a pleasant bridge language between the imperative world and the purely functional word (weighed in favour of the imperative world, where as F# is weighed in favour of the functional world) ... and as such it makes more sense to me at least to draw inspiration from that domain, then dynamic languages and meta programming... just my opinion of course.

Given the time frames between C# versions - IronRuby should be mature enough by the time c# arrives that it should be a moot concern, and IronPython is already pretty capable in the meta programming stakes as well, if you can hack the whitespace sensitivity.

Funnily enough (and this a bold claim I know :) - but I think the pattern matching support and associated features in F# would prove far more valuable tools for solving many of my day to day problems in C# than meta programming would be, when I take a subjective look at the code I write and the goals it's generally trying to achieve combined with the existing features and practices I've already embraced in C# (IoC/DI) it looks to "click" together in a much more cohesive manor. Thoughts?

Written on November 27, 2007