C# Kicks Our Ass

Ovid on 2008-01-25T10:10:28

When I first started here, our project manager commented to me that when she programs in C#, she can just "click a box on a page" to make the sort of XML changes we often find laborious. Last night, my soon to be erstwhile housemate also commented that when he does C#, he just needs to specify a set of mappings in a config file. Schemas, XML, JSON and anything else he wants just happens. It's magic!

Now I know a lot of people sneer at this "magic" attitude, but those people would be wrong and my project manager and housemate are right. This is such a common problem that it deserves its own abstraction layer. If you're generating XML by hand, you're doing it wrong. If you're using libraries like XML::LibXML, there's still a good chance you're doing it wrong. As an analogy, if you're developing on an MVC codebase, you know your database handles don't belong in your controller or view. They belong in your model. In MVC, XML generators probably don't belong in your controller or model, they belong in your view and you shouldn't have to write them.

Why is it that other languages have had Bermuda-like functionality built-in to their toolsets for years and we don't? Perl doesn't earn many bragging rights here.


XML is for non-scripting

IlyaM on 2008-01-25T10:45:31

My theory is that XML related technologies (XLST, SOAP, etc) are just more popular in projects which are using non-scripting languages (C/C++, C#, Java). There are many reasons why. For example: writing custom parsers in generally harder, cannot use languages itself to specify configuration. These languages are generally just more heavyweight and cannot be quickly adapted for many tasks which we kind of get for granted in scripting languages. So they "outsource" things like configuration, templating and RPC to XML. End result is that when using these languages you rely on XML much more and you need those XML tools more often.

Practically the only time I have to touch XML in Perl is when interfacing with somebody else system.

Re:XML is for non-scripting

Ovid on 2008-01-25T13:00:34

Practically the only time I have to touch XML in Perl is when interfacing with somebody else system.

True. That's the situation I routinely find myself in. We work with many outside groups and XML is the de facto data interchange format.

With Bermuda, I would have found this much easier to handle if we had proper introspection. I could write a quick "stub" of a Bermuda island file like this pseudo Perl 6 code:

print YAML <<"END";
class: $class
name: $class.key
for: iPlayer   # allow different uses for the same class
elements:
END

for $class.HOW.properties('public') -> {
    next unless my $accessor = $property.accessor;
    my $property_name = $property.name;
    my $accessor_name = $accessor.name;
    my $type = $property.type // 'string';
    if !$accesor.signature.returns('SCALAR') {
        $property_name .= '*';
    }
    print YAML <<"    END";
    - $property_name
    - type: $type
      method: $attribute_name
    END
}

And then the programmer could go in an convert elements to attributes, add arbitrary attributes, or customize it to their heart's content. Or just take the default and run with it. Right now we have to do it the hard way :/

Re:XML is for non-scripting

Stevan on 2008-01-25T15:33:15

Perhaps while you are waiting for Perl 6, you should look at MooseX::Storage, it doesn't have an XML backend, but thats mostly cause we haven't had the need for it (if you can choose a schema it would be trivial).

- Stevan

Re:XML is for non-scripting

Ovid on 2008-01-25T16:52:22

That does look very interesting. I had also thought that in later stages of Bermuda, I'd want to have optional Moose hooks. They shouldn't be too hard to add :)

Re:XML is for non-scripting

Stevan on 2008-01-25T18:10:30

Actually it seems that Bermuda is somewhat redundant with MooseX::Storage (ignoring the fact MX::Storage only works with Moose classes for the moment). I wonder if pooling our efforts might not make sense? Interested?

- Stevan

Re:XML is for non-scripting

Ovid on 2008-01-26T10:23:12

Not just yet. For one thing, I refuse to release this until I feel much more comfortable with the design. I've screwed up with this in the past and I'm not anxious to code myself into a corner. I also am being strongly driven to solve an immediate need at the BBC, so I do need to stay focused on that right now.

C# Boasts

gmillerd on 2008-01-25T13:35:00

How much of that is the interface vs the language?

I think your giving C# too much credit in and of itself, though in the end the C# developer is more agile because of it your right.

Its a loss to Perl that we don't have the interface to do such things (or perhaps other things more worthwhile and fundamental).

Not something that a half-baked eclipse setup or emacs mode fixes obviously. The Visual Studio setup is quite powerful for that side of the fence, even if at times they are abstracting users from their code and hiding properties in metadata very frequently.

Re:C# Boasts

Ovid on 2008-01-25T13:45:04

I think a lot of it is in the language. Perl has grown up and unfortunately it's still in the clothes it wore as a teenager and they don't fit well. Many of the things the C# and Java communities can do work because the languages have a regular syntax and introspection.

Re:C# Boasts

Stevan on 2008-01-25T15:37:20

Many of the things the C# and Java communities can do work because the languages have a regular syntax and introspection

Honestly, this is where TIMTOWTDI failed us, it is a double edged sword of flexibility and inconsistency.

- Stevan

Re:C# Boasts

chromatic on 2008-01-25T19:20:49

Many of the things the C# and Java communities can do work because the languages have a regular syntax and introspection.

Similarly, many of the things the C# and Java communities have to do (in particular, dependency injection governed by voluminous XML configuration files) is because the languages have other inflexibilities.

Re:C# Boasts

Ovid on 2008-01-26T10:03:31

Oh, I certainly agree with that. Doesn't mean I don't want to steal the shiny bits :)

Re:C# Boasts

Aristotle on 2008-01-27T08:44:28

I think the obvious moral equivalent to static introspection in static languages is dynamic programming (open classes, closures, eval) in dynamic languages. Instead of clicking buttons in an IDE that generates code for you, you write code against an API that abstracts away a bunch of metaprogramming. The difference is that you are not limited by your tools in how far and fast you can go because you can always abstract out further from the basis you start with.

Of course, the flipside is that it’s expedient for 100 projects to write only the 1/15th of the abstraction functionality that for their own needs require, so in the end there’s a lot of partial duplication of work spread around and no one has a single rock-solid tool available to bootstrap future work. To a smaller extent, it is the problem Lisp faces.

Why corporate-backed language have great XML

Alias on 2008-01-25T15:51:17

In my opinion, it comes form the corporate backing.

Even if Microsoft only wrote it for themselves, they'd want great XML support for their own purposes, all the way to the tool level, and we'd get decent stuff anyways.

XML is the language of business to business conversations, and the foundation of current-buzzword-complient RPC (SOAP) and it underpins the entire industry-driven "Service-Oriented Architecture" business.

So there's massive focus from those languages on doing XML right.

Perl has seemed to lack any equivalent level of focus from someone willing to put in the effort to build a top notch XML/Perl support.

Being crippled with things like SOAP::Lite (the ghost of the past) and problems with it not being trivial to install things like Expat and other XML libraries surely doesn't help either.

Re:Why corporate-backed language have great XML

cbrandtbuffalo on 2008-01-25T17:03:13

Looks like someone is working on a fresher implementation:

http://use.perl.org/article.pl?sid=07/11/29/1432250