Archive

Archive for the ‘.NET’ Category

The Functional Future of C#?

May 23rd, 2007
Comments Off

Steve Maine wonders about the uptake of new features in C# 3.0 that could allow certain more Ruby-like constructs.

I absolutely think people will take advantage of the new functional and dynamic features available in C#. However, I don’t think we’ll see the same fevered enthusiasm surrounding these features as one sees in the Ruby community. C# carries with it the baggage of its past, including styles, idioms, practices, and methodologies, many of which speak against the dangers brought on by features like extension methods. New languages, on the other hand, bring not only their new features, but also freedom from historical baggage and traditional strictures. The vast majority of programmers first saw Ruby in the light of Rails, so there was no change for anyone to resist.

In the case of .NET, I think we may see the most radical uses of new CLR features gain popular acceptance in languages other than C#. In particular, I’m thinking of the recent example of the DLR console showing the willy nilly mixing of dynamic languages. That level of interoperation will make it very appealing to segregate sections of code by style — style which will be indicated and supported by language choice. In this manner, initial exploitation of functional constructs and looser typing can happen in languages that breath that stuff, and the techniques that prove most popular will likely filter into common C# usage more slowly.

Anthony .NET, Programming, Ruby

The Importance of a Name

May 17th, 2007
Comments Off

While I do use C# a fair bit, I’m not an early adopter of test releases of Visual Studio or new versions of the language. I try to keep up on what new features are coming, so when final releases are made I can dive right in, but I’ve fallen a bit behind on the syntax and implementation details for a few things in C# 3.0. My question now is: at what point did identifier names start trumping other indicators for semantic interpretation of code?

For a good long time now, statically typed language compilers have presented developers with a proposition that can loosely be stated thusly: you give your variables types so I know what to do with them, and then you can call them whatever you want so you know what to do with them. Now, it turns out that type annotations can be very useful for helping people understand code as well, but such information isn’t strictly necessary for productive development (e.g. dynamically typed languages and those with good type inferencing capabilities).

But now, it seems, the folks steering the C# ship are turning to identifiers to infer programmer intent in the form of object and collection initializers. The identifier-based mechanism for collection initializers is described here.

What I think is interesting about this is that such behavior is much more commonly found in dynamic languages, where there often isn’t as much developer-generated metadata available. C# let’s developers “mark up” their code with type specifications and attributes, so why aren’t we using those mechanisms instead of relying on compiler conventions and guess work? Automatic properties (also described in the first link above) can well be managed by using an attribute, which then avoids the somewhat odd issue of having a private field whose name nobody but the compiler knows. Collection initializers could benefit from having the appropriate Add method decorated with an attribute, or implementing an interface that specifically defines the interface used by the collection initialization mechanism. Object initializers… well, that one I like except for the unifying of common property names (i.e. passing a property of one object to an object initializer without assigning it to a specific property, thus relying on the compiler to equate common names). It’s just strange to me that, what seem to me to be, more idiomatic C# techniques are not being used.

All that said, I am very interested to see how this all pans out. I use reflection constantly in my C# code. I very often build base classes, or frameworks, that are sensitive to field, property, and method declarations in sub-classes. These techniques can be used to eliminate masses of boiler plate code, and, ideally, minimize developer responsibility by relying on very compact behavior declarations, rather than imperative specification of how the behavior is to be accomplished. When I do this, I very often require that a default constructor be available (because constructors that take parameters can be a pain when instantiating objects programmatically), and I often do use identifier names as part of the patterns I’m looking for to trigger the metaprogramming routines. That style of development seems like just what C# 3.0 is heading towards. Rather than constructors with positional arguments, we throw a dictionary with some number of parameters at the constructor (beware developers who assume properties have been set in the constructor!). Rather than lean on potentially complicated inheritance, let’s look for idiomatic collection definition.

I’ve never had many reservations about doing this within the scope of a single project. All the developers can agree that declaring a Connect method is going to trigger some framework-defined behavior. But does this kind of logic belong in the compiler for the underlying language? If the 80/20 rule applies to library design, does it also apply to compiler design?

Anthony .NET, Programming, Software Design

Multiple Dispatch in C#

April 12th, 2007
Comments Off

I recently encountered a situation in which I wanted double dispatch method invocation in a C# program, so I wrote a simplistic implementation of that very mechanism. I’ve written up an article describing this technique that I’m not including in the blog since it is long for a blog post and fairly technical. There is a sample program included with the article, and I encourage anyone with an interest in C#, or anyone wondering about how to get multiple dispatch in mainstream object-oriented languages, to take a look.

Update Jay Bazuzi follows up on this topic.

Anthony .NET, Programming, Software

PowerShell: Bringing it all Together?

February 16th, 2007
Comments Off

Is Microsoft’s PowerShell the a missing link between the command line and GUIs? In many ways, yes.

What I find most striking about demonstrations such as these (check out the invoke-sql cmdlet and dir Command videos) is not so much the idea of a more powerful shell as it is the integration of GUI elements with scripting. I can not comment too much on PowerShell itself — I have installed it on a few computers, it’s rather slow to start up, but it makes the noble gesture of accepting UNIX-style commands — but, watching those videos, I couldn’t help but feel a twang of jealousy.

So often while working in languages like Ruby, one runs into walls when the goal of graphical interface comes up. Sure, it can be done, but the incantations needed to bring up and populate windows always strike me as ill-favored when viewed in comparison with the concepts more readily expressed in such languages. However the chart output piping demonstrated in those PowerGadgets videos is just the sort of thing I’d love to be able to do from any language. No bothering with windows, title bars, etc. Instead, it’s just a matter of passing in some structured data and getting reasonable output. And hey, we already can do this pretty well on the web!

A huge barrier is, of course, platform differentiation. Miguel de Icaza recently defended some of Microsoft’s past actions as being necessary concessions to the goal of platform integration. He made the point that while Java may be cross-platform, any application that uses Cocoa bindings runs the risk of being tied to Apple’s platform. Yet, this is a sensible action for a couple reasons: you don’t want to reinvent the GUi wheel on every platform, and you do want to provide users with a consistent, intuitive experience. These goals lead towards platform integration, and there’s nothing wrong with that.

But where does this leave your favorite language of the month? Languages with small communities can’t really afford to be single-platform as that would further diminish their potential audience. Instead, they, for the most part, aim to be as cross-platform as possible at the expense of extensive support for the features unique to any particular platform. Which leads me back to PowerShell. PowerShell seems to be doing a few things such as component inter-operation via typed object interchange, and easy integration with existing class libraries (including GUI components), that are quite forward looking. So I wonder, are the platform-makers the only ones capable of elegantly bridging the gap between scripting and graphical interfaces? Both Apple and Microsoft have demonstrated some ability to provide such capabilities, and I look to Adobe introducing Apollo to see if the platform continues to be the key.

PS: Of course, the web is the platform many of us worry about today. I recently built what would have been a standard GUI application using Ruby and OpenLaszlo as an exercise. The outcome of that exercise was predictable: OpenLaszlo is a great library for building web applications, but it sure would have been a lot faster for me to use VS2005 to put together a Windows Form.

Anthony .NET, Microsoft, Software, Windows

Mono For The Win?

November 3rd, 2006

I’m still trying to absorb the possible ramifications from the Novell / Microsoft announcement. While there is every possibility that nothing will come from this, if it is instead Microsoft’s long-awaited acceptance of Mono, then this could be a very significant part of both companies’ futures. I have argued in the past that Mono is a critical part of Microsoft’s potential cross-platform future, and this announcement seems to suggest that they may see it that way, too.

So, ignoring the many juicy complexities, let me pick on one that I haven’t seen mentioned yet: What of XAML? I think it’s a real win for Microsoft if programmers can use .NET for all their needs, be they command-line utilities on the server or GUI apps for customers. This could encourage uptake of .NET, while creating a stage on which both Microsoft and Novell will be competing on the more genuine bases of who provides the better platform for a given technology. For so long the Microsoft suite of software has been disjoint from, well, everybody else. This has made comparison difficult, and many skills not as transferable as one would wish. Now there is a real possibility for the more apples-to-apples comparisons of

  1. On which platform do I most like to develop my .NET applications?
  2. On which platform do I most like to run my .NET applications?

To throw something out there, it’s entirely possible that we will see some programmers choosing to develop on Windows (thanks to Visual Studio) and deploy on Linux (thanks to cost, etc.).

But back to my question, if .NET is to become a truly cross-platform technology, there needs to be a better answer to GUI construction. Just as Mono’s SWF implementation is coming up to speed, Microsoft is moving to WPF, which Miguel is none too fond of. Perhaps this is a sign that WPF/E won’t be overly crippled, or perhaps this is an opportunity for the Mono camp to offer something new that could actually gain some penetration on the Windows side of the equation. Here’s hoping this all ends up being a fraction as interesting as it could be.

Anthony .NET, Microsoft, Mono