Magical Dynamic Mystery Tour

Phil Haack is not only a good friend, he’s also a damn good writer. He has a talent for focusing sharply on a point, and then supporting it with quick wit and a fat brain – a deadly combination should you find yourself disagreeing with him or his point of view. With his last post on the new C# dynamic keyword – I found myself in just such a position – and it’s going to get ugly. Phil: you’ve been served my friend! It’s a Blog Fight – pass the popcorn! OK not really – but these discussions are fun and I was going to leave a really long comment on Phil’s blog – instead I’ll just write my own post.

Phil Haack is not only a good friend, he’s also a damn good writer. He has a talent for focusing sharply on a point, and then supporting it with quick wit and a fat brain – a deadly combination should you find yourself disagreeing with him or his point of view.

With his last post on the new C# dynamic keyword – I found myself in just such a position – and it’s going to get ugly. Phil: you’ve been served my friend! It’s a Blog Fight – pass the popcorn!

OK not really – but these discussions are fun and I was going to leave a really long comment on Phil’s blog – instead I’ll just write my own post.


Not Your Dad’s C#

Let’s get this out of the way right now: I’m not a curmudgeon, nor am I a cranky old “get your Ruby off my lawn” kind of guy (even if it leaves a pile of PHP behind it). I think I’ve established that I dig new things :) and I get accused, quite regularly, of going headlong where things shine.

So no – I’m not all twisted up or “afraid” of this infatuation with dynamic language features and I agree with those who say, essentially:

Dude you don’t have to use the dynamic keyword – it’s just there mmmmkay?

Right you are Mr. Anonymous Commenter! But to ignore its presence is almost impossible for someone like me who likes trying (and breaking) new things.

There it sits – this lovely new “dynamic” keyword – rolled up tightly in the Reflection ZigZag… burning sweetly on the C# coffee table… calling to jonesing devs who are looking for a little mellow in their long day.

For these guys, the aroma can be quite inviting. No – I’m not talking about inexperienced “Morts” (I hate that term) – I’m talking about the Big Nose guys. Guys like Phil:

C# 4 introduces the new

1
dynamic

keyword which adds dynamic capabilities to the once staid and statically typed language. … I believe the original purpose of this feature is to make COM interoperability much easier. But phooey on the intention of this feature, I want to have some fun!

Fire it up Phil!

Phil’s post (and follow up) showed off this feature which, as he caveats quite nicely, is musing at “what you could do”. Exploration is fun – it’s wonderful, but I have to ask “what’s the point?”. That’s not rhetorical – I really mean it: what is the point? Where are we going with these new dynamic features?

I really dig the dynamic brownies– they’re great when I get the Language Feature mmtbusphoto[1]Munchies and I’m feeling bored etc. LINQ – now there’s a krunky feature. It’s the Doritos of the Language Munchies and probably one of the most innovative things I’ve ever seen come along in a while.

The “var” keyword is great for the “chronic” pain in my wrists from typing  (and retyping) types on type declarations (which, typically, take up too much time). Anonymous types just flat freak me out – but in a good way.

And now “dynamic” for COM interop? COM’s been passed out in the corner for the last few years (I think it even puked on itself) – are you really suggesting that we need a keyword to work better with it? Cause I’m thinking that… well you know… the last thing in the world I want to do right now is to wake COM up – who the hell knows what’s gonna happen then.

I agree with a comment that Mark Hoffman left on Phil’s post:

Some seem to be making this out to be an issue of resisting change or resisting new keywords or being a jack of all trades. It’s not so much about adding a new keyword. It’s about the line of reasoning that thinks a statically typed language needs dynamic features. Add features. Add useful features. But this smacks of "All the cool kids are using dynamic language. We need to have some of that, too."

I will say that it definitely seems that way. A case of language envy that makes as much sense as – well as Ruby introducing variable declaration. Or type-casting. Do dynamic languages envy Java and C# features? I kinda think not.

I think it’s safe to say that dynamic languages are “more fun” – at least that’s what many people say (you can lump me in there too – I think Ruby is a fantastic language). They’re not as strict, like to stay up late and party, and don’t mind when you crash on their untyped couch.

Twaining The Meet

Bryan Watts left a comment on Phil’s post that was very well thought-out and reasoned (even if he threw big words towards the end):

I wonder about the line of reasoning that says "static is static and dynamic is dynamic and never the twain shall meet". Developing well-implemented features that enable core scenarios is what language writers are paid to do. They are not paid to maintain anachronistic lines between obviously converging paradigms.

Believe it or not – I’ve been in this situation (having the twain meet) with Kona.

I gave a presentation at MIX 09 called “There’s a Little Scripter in All of Us” and the premise was that we can do a lot for our applications by focusing on experience rather than architecture. To underscore this, I tweaked Kona a bit to have a dynamic plugin engine (something Bertrand built – which is still there and is awesome) which allowed for developers and hobbyist “scripters” to shift their focus less on architecture and more to quickly meeting customer demands.

Kona had a really interesting approach to it. I took Bertrand’s idea and thought:

What if, instead of this structured approach where I split things into separate projects and DLLs, I flexxed the idea of scripted plugins to handle the business rules?

Or to summarize: do what the other 80% of the web developers of the world are already doing with PHP.

So that’s what I did – I pushed everything into a plugin. The Order Process, tax calcs, shipping – everything. And it ran, and people liked the demo. Changing was easy and the app, I think, was incredibly flexible.

Note: I don’t know the current state of Kona – I think this feature set is still in place.

It left me in a really weird place as a developer, however. I really liked the dynamic aspect of it, but wasn’t all that sure where I should go next. Embrace it completely and turn my C#/MVC app into a PHP-style app? If I did that – what would it get me? And would people understand it?

The trick, of course, is “a balance”.

The Friends You Keep

PHP is the kind of language that stumbles into a room, hair flying in all directions, and says “duuuude where’s the Doritos! Here – take a hit of this new web app I made last night…”.

C#, on the other hand, wears Khaki’s and Power Business Casual – gets a run in before work, and is in bed by 10.

I tend to agree that these guys could probably share an apartment and I guess we’ll find out since C# is moving it’s junk into the dynamic trunk at a pretty reasonable pace.

Some might see this little arrangement as C# having a bit of a midlife crisis: he’s grown a var goatee, bought a LINQ Corvette, and (from what I hear) is dating the dynamic keyword that’s typically found in languages that are a lot younger.

Others might see this a bit more positive – C# is going deep on the Meaning of Language Life, Exploring the endless options of the Metaverse, and overall trying to “have a good time” in some new clothes.

Either way it’s a departure from what one might expect. And it’s confusing. And that’s OK (to be confused). I think – but I’m not sure … I don’t really know.

All Good, But What’s Next

Again – not afraid and this is a FUD-free zone. You go C# and let’s crank this party to a whole new level – I’m on for the ride and I’ll do like Phil did and get my dynamic freak on.

At some point, however, it would be cool to know a bit more about where we’re going because the Magical Mystery Tour didn’t end so well for the Beatles:

…an ever greater number of cars followed the hand-lettered bus, hoping to see what its passengers were up to, until a running traffic jam developed. The spectacle ended after Lennon angrily tore the lettering off the sides of the bus.

It would be nice if this wasn’t spectacle…