Wednesday, August 15, 2007

Bloomington not yet a'Twitter

Lots of interesting stuff going on in the Bloomington scene this week. James Boyd, who I've written about before, sat down to watch and interpret the 36 hours in three days of Monroe County budget hearings, and posted them on a dedicated comment thread on the newspaper's web site...I mentioned that on Twitter. Some of my coworkers wandered off to the Agile2007 conference and sent reports back on speakers they liked; I added a couple of people to my Twitter list and blogroll due to that. My kid started kindergarten, so I've been ramping up my list of educators as well (too bad there are no local ones as of yet!).

While James was posting his updates, I tried to follow along with his numbers on a Google spreadsheet, with only a fair amount of success. (Of course, my job was easy since all I did was read the comment threads. James had to try to interpret everything and post and try to keep up with details on the numbers - all in real time.) My goal was fairly self-centered: I wanted to understand exactly what they were voting on and why. But certainly if what I was doing was useful at all I wanted to share it - why keep it private? (A former boss asked me that once. Why did I blog about my trip instead of putting it in an email and sending it to the six or seven people in my group? All I could do was stare at him blankly.) All in all, I'd say that my, and probably a lot of other people's, information stream had gotten a lot wider this week.

Thinking along many of the same lines, only way more articulately than I could ever be, Kevin Makice wrote an piece on the future of local social networking. Kevin wants everyone to center around Twitter, which I doubt will happen. The Herald-Times has taken a real leadership role in this process, and they of course have a vested interest in bringing people to their site instead. Councilmember Sophia Travis pointed out that it was way too tough for her to actively participate in the discussion as well as listen to the issues, although she did manage a couple of notes.

So where do we go from here? Here are a few things I notice:

  • It took a professional, not a blogger, to (a) generate interest and (b) pull off the budget updates with the right amount of elan to keep everyone interested. Is this a requirement? I'd say no, but the fact is that I wasn't about to take several days off work to go down there and watch. It's a lot easier to do it if someone will pay you.
  • With the exceptions of Councilmembers Travis and Marty Hawk (who posts to the HT occasionally) there are few enough politicians in the general conversation, to expect that there will be many in the live conversation (by which I mean Twitter, or the running comment thread). It would be nice if this changed.
  • I had to ask early on in the process for copies of the spreadsheets the council was using. Apparently the auditor was running around with them on a thumb drive, handing out copies to whoever needed them. It would have been nice to just stick them on a web page at the beginning.
  • I want a budget expert available to answer questions from the public. I probably had a dozen questions over the three days - granted, I always have questions, it's because I don't know anything - but many of them James couldn't answer, and probably many he could have but didn't because he didn't have time. Wouldn't it have been cool if the auditor's office could have somebody sit and monitor the thread and explain stuff?
  • Let's not wait for next year's budget to do this again. Send the junior copy editor to update us on the Redevelopment Commission meeting. Let's get a volunteer blogger to liveblog the Planning Commission. Let's keep the government exposed!
  • Budget hearings are a really moronic way of doing things. A bunch of exhausted people sitting in a room voting yea or nay at random on a couple of grand so they can get it over with and get some lunch? Tell you what, next time let's get all the line items out on a nice wiki page and hash it out that way. I realize I'm text-centered and maybe others prefer the face-to-face, but then how about over NetMeeting or something?
  • Now, I'm not trying to grouse and say that things should have been done differently. Or to be more precise, of course they should be done differently, but we never know precisely how until afterwards. This has been a great learning week for me, and I hope, for everyone else as well.

Sorry, Kevin, I didn't get that Bloomingpedia article on the budget written; the hazards of citizen journalism :) But maybe now we all see a little bit more of the possibilities that are opening up before our eyes. Hey, follow me on Twitter!

Monday, August 06, 2007

Dare Obasanjo on Open Social Networks

Dare writes on Open Social Networks. One thing he doesn't bring up, though, is the existence of specialized social networks and how they fit into the whole. He uses Flickr and YouTube as examples of sites that have good API's for getting and setting data, but part of the point of those is that they exist solely to allow users to push around specific types of content: images on Flickr, movies on YouTube. Facebook and MySpace have lots bigger fish in mind, wanting to take over your whole mindshare. It's an interesting evolution, isn't it? For a long time we talked about Microsoft and how they wanted to control everything on your desktop; then Google came along and we talked about how having everything in your browser was better than having everything in your desktop. Now it's not enough to have everything in the browser; we have to have it all on our social networking site. The one thing this really points out to me, though, is the fragility of these sites - for a while MySpace was the hot toy, but now it's Facebook. Is there any reason to think Facebook will be the place to be in six months or a year? I don't see one.

I learned via TechMeme, though, that Jeff Pulver is leaving LinkedIn for Facebook. I think it's a mistake, Jeff. LinkedIn is specialized; it exists for business contacts. It will probably be around in a couple of years, linking up business contacts. Facebook will probably be gone as people move on to the Next Big Thing.

To sum it up, it appears to me that the real evolution of social networking is going to be LinkedIn for business contacts; Flickr for pictures, LibraryThing for books, and then maybe a few small sites like Facebook and MySpace that aggregate all this data into a coherent whole for people who aren't interested in creating their own websites that aggregate all this data, or are nervous about being outside of the walled garden. But Facebook ain't the future. Don't expect it to be.

Saturday, August 04, 2007

Your code is suboptimal!


Check out Eric Sink's blog for a nice, and almost free, T-shirt. Eric runs SourceGear, a version control company, which I'm sure is very nice software, but I've never used it. But the T-Shirt is good quality, and the package comes with a copy of the SourceGear comic book, which is hilarious. And like I said, it comes almost free. In payment, take a picture of yourself wearing the shirt in an appropriate pose, post it on your blog, and give them permission to use it, which I hereby do. This picture is on the Indiana University campus alongside a statue of chancellor Herman B Wells, who, as you can see, is doing the comic book pose too. Thanks, Eric!

Friday, August 03, 2007

Out of the Theater, Into the Courtroom

Boy, doesn't this stink? (Thanks, Vorlath). As a rule, I don't like commenting on outrageous stuff; yes, it's outrageous, yes, those darned company/government/media droids, there oughta be a law. Or a law repealed, or something. What makes this one a bit different is that there oughta be protests. Can't someone get a group together outside the theater and picket, or something? This is a clear clase - assuming the facts in the Post are correct - of an overreaction and the movie theater in question ought to be the target of a big negative publicity blitz. That's what I'd be doing if I were the girl's lawyer. I hope Indiana movie theaters have more sense, though.

Wednesday, July 25, 2007

Javadoc Clutter

Ed Gibbs, one of my favorite bloggers, writes on the usefulness of javadoc comments. (I meant to write on Alfred Thompson's thoughts on the issue last month as well, but didn't get to it.) Here's my take: If you're coding properly, you have lots of little methods, as Ed says, and they should be just about self-documenting and not really in need of comments. But, when you have code organized like this, it becomes even more important that the big picture be kept in mind somewhere. This partly means working on good class-level documentation - how the class is intended to be used for example, but it also means having good diagrams of the entire application. With this, you may realize not only how the class is intended to be used, but how it's being used in an unintended way, or how it's duplicating the functionality of this other class over here and they need to be merged into a single class.

So where do the diagrams come from? As Alfred mentions, you can use class designers like the one in Visual Studio, but my feeling is that that is only a starting point. There are so many different diagrams you can make: dataflow, inheritance, etc., but you have to keep in mind that the point of any diagram is to help the reader grok the system. What I like to do is keep a documentation wiki around, and generate some diagrams that can be added as pictures, and as a starting point for some user-defined text to help explain them.

But when you do that, eventually you're going to want hyperlinks in the text that lead back to the class, and its description, and its methods. And this is where Javadoc comes in. In the build, throw in a step that generates HTML pages from the Javadocs, and make them available to the users of the project wiki. I think this gives you the nicest combination of high-level overviews and class-level references, both of which are essential to a well-managed project.

Monday, July 23, 2007

The 20 Dumbest Words in Software Development

Brandon McMillon writes on doing it right. (Thanks to Alfred Thompson for the link.) He doesn't touch on the agile side of software development - although I can guess his opinion by his planned article "Pair Programming is for Morons" - and so the article has a lot of stuff about Objectives and Requirements and Spending Design Time Up Front. The tricky bit about commenting on this sort of article is that I don't really disagree; his straw man comparison is that one group who just goes off and starts coding so they can get it done faster. That is bad. He does mention how getting sign-off and buy-in from users and stakeholders is valuable, and here's where we might differ: getting this sort of data is important throughout the life of the project, not just somewhere near the front. Because once a user gets some working software in his her hands, she's immediately going to have ideas to improve it, and they'll probably be good ones. So, while it's nice to do some designing up front, it's more important to have your code in a state where you can make changes easily and quickly, to respond to the inevitably changing user requirements.

What I have written here is short, and therefore oversimplifies the many issues. But the full range of agile practices can answer most objections, in my experience.

Saturday, July 21, 2007

Should Newspapers Become Local Blog Networks?

Scott Karp at Publishing 2.0 writes about newspapers jacking up their blog count. I think the thing that most people are missing when it comes to whether newspapers should be more like blogs, or should bloggers be more like reporters, is that we, as blog readers, are really, really interested in who's writing the story we're reading. It's why there are columnists. After a while, people would read anything Dave Barry wrote because, as soon as they saw his name on the column, they knew they were in for a funny article.

But it's the same thing with real news. Our local paper just had a bunch of articles on the competence of the county auditor, many written by a reporter named James Boyd. They're good, if controversial, articles, and ended with the online version having dozens of comments along the lines of, "the real story is...", "what the paper needs to do is...", "why on earth didn't they report on...", and finally Mr. Boyd, possibly tired of all this, chimed in with his side of the story and explained just why he reported on what he did, and what kind of feedback he got from the auditor. The comments immediately became much nicer.

Why? Because people then realized they weren't just trashing a corporation, they were trashing a real person, and one willing and able to defend his actions. It created a conversation rather than a soapbox. So, even though Mr. Boyd is a reporter, I think what I'd really like to see on the site is his pseudo-blog: maybe nothing more than a list (with, of course, RSS feed) of all the stories he writes. When we know who's on the other side of the pen, the story becomes a lot more interesting.

Friday, July 20, 2007

Learning from Joel Spolsky (and Dave Winer)

Here are my comments on Joel's comments on Dave Winer's comments concerning comments. I think Dave is dead-on, but the whole issue is really more of an A-List issue than it is a general concern. I bet there's some sort of law that states that the amount of garbage increases exponentially to the number of participants; if there isn't, there should be. If you have a small blog where just a few people comment - or none, like this one - the quality of the discourse tends to be pretty high, but when you start having thousands of readers, the number of people who have their own agenda to push starts to outweigh the number with interesting feedback. I have comments enabled, and I expect to have them for the foreseeable future :)

But I still want some way to do trackbacks. I don't think the existing trackback system is able stop spam well enough to be useful, but the fact is, no one who reads Joel's post will ever find out about this one, as far as I can see; especially the casual reader who only stops by for a few seconds.

Thursday, July 19, 2007

Jobs of the future, #1: Online Community Organizer

Seth Godin suggests that an up-and-coming job description will be Online Community Organizer; that would be someone who can gather together everyone in an industry and make them feel like they have to be part of the conversation in this forum. I could see it coming someday, but my feeling right now is that all of the successful online communities are happening more or less by accident. Facebook, MySpace, Twitter. What makes Twitter a more dynamic online community than Pownce? Not much, I hear; maybe some sort of first- or second-mover advantage? But is there really somebody out there capable of moving from one job of this type to another and being successful at both? I have my doubts.

Tuesday, July 10, 2007

Marc Andreessen's Eleven lessons

Marc's disabled comments on his (excellent) blog. Marc, I see at least two issues with that: First, a lot of times I only have a sentence or two to add to a post and it hardly seems worthwhile to create a brand new article on my own blog. Second, if anything it's even easier to spam trackbacks than it is comments! Although I don't have enough readers to bother about any spam-blocking besides the Blogger default captcha, surely you could come up with some mechanism to ensure a human is the one entering the comment. And isn't it a shame to restrict comments only to those who have their own websites?

Thursday, July 05, 2007

Evaluating Javascript in an NUnit test

Adam Esterline posted his solution to javascript testing. He uses WatiN to run tests, which I wasn't excited about; I was hoping for a way to test where I didn't have to install any more software anywhere. Here's the solution I came up with:


static object Evaluator(string code )
{

ICodeCompiler compiler;

compiler = new JScriptCodeProvider().CreateCompiler();
CompilerParameters parameters;

parameters = new CompilerParameters();
parameters.GenerateInMemory = true;
parameters.GenerateExecutable = true;

parameters.ReferencedAssemblies.Add(Assembly.GetExecutingAssembly().Location);

CompilerResults results;

results = compiler.CompileAssemblyFromSource(parameters, code);
if (results.Errors.Count > 0)
throw new Exception(results.Errors[0 ].ErrorText);

Assembly assembly = results.CompiledAssembly;

MethodInfo entryPoint = assembly.EntryPoint;

return entryPoint.Invoke(null, new object[] { null } );

}

[Test]
public void EvaluatorTest()
{
Evaluator( "Context.Current.Data = \"Craig\"" );
Assert.AreEqual( "Craig", Context.Current.Data );
}


This seems elegant and able to handle a lot of things like side effects. Unfortunately I've been back on the server side for the most part and haven't really tried to put this code through its paces.

Thursday, June 07, 2007

Lawn sign in the Forbidden City

Mark Hurst's great This Is Broken website gives examples of bad user interfaces, both on the net and in the meat world. You can't argue with most of the entries, but I love this sign. The grass is quietly asking us, "Please Do Not Disturb Me". The extra "Me" on the sign gives a really dreamy, tranquil, and above all Chinese feel to the landscape; much better than the harsh "DO NOT DISTURB" or "KEEP OFF THE GRASS" signs we Americans are used to. (I'm posting this here since you have to be a registered user to add comments to the site).

Sunday, May 20, 2007

Frames Per Second in birds

I had occasion to visit Hardin Ridge yesterday for the International Migratory Bird Day celebrations. They had several stations, and it was fun for the kids, but one thing I thought was interesting was during a presentation on birds of prey. They displayed a peregrine falcon and talked about its remarkable vision; here's what Steiner has to say about it:

They are equipped with full-color vision and with eyes specially adapted to permit rapid adjustment of focus while moving at speed, and from four to eight times the resolving power of the human eye. Hovering may be compared to looking into a field from a car moving at twenty miles an hour or from one which comes to a standstill every few yards. It would be possible for a human being to see an individual rabbit or large game bird at a range of 600-700-yards; a bird of prey, with about four times the resolving power of the human eye, should therefore be able to see it at a range of nearly two miles.

What particularly caught my attention, though, was when they said that the peregrine can perceive significantly more events per second than humans can. I don't know if it's exactly the same concept, but I assume we're talking about frame rate here; they commented that even when cameras have been attached to these birds as they make one of their amazing, 200 miles-per-hour dives onto some unsuspecting pigeon, all humans can see is blur.

Now, the frame rates they mentioned seemed surprisingly low to me they suggested 18-20 events per second for humans and maybe two or three times that amount for the birds. But I suppose it's an example of flicker, and syncing, where if you perceive the wrong couple of frames in a videogame the action seems all wrong, or maybe the afterimage in the eye causes the slowdown.

So I'm not sure where all this is leading, except maybe that a really cool videogame would be Peregrine: The Stoop for a Pigeon. But I suspect there's a lot of basic science to be done before any game can simulate the visual experience of this amazing animal.

Friday, May 11, 2007

Choosing a Kindergarten

It's a funny thing, but I'm pretty used to being marketed to. When I needed to get a gym membership, the gyms that I went to had someone there to give me a tour; show off the machines and the hot tub; in general make me excited about going there. Or when my wife was checking out nursing homes: she had a very similar experience with people who wanted to make her comfortable and get her interested in coming back, offering her cups of coffee and things.

So when we got the letter about coming to a kindergarten open house, that's sort of the thing I expected. I thought the people would be interested in showing us around and getting us excited - like the gym or the nursing home, trying to sell their product to us, sell us their school. I guess the first warning I should have had came straight from the informational packet, though: there was really nothing there except lots of information about "your child" - "your child" should be able to tie his shoes. "Your child" should have lots of time to read with you. "Your child" needs to be independent enough to go potty all alone. Not a word about this big, new, mysterious place he'll be going to.

So I was expecting some more information on the school at the open house. Unfortunately, what they had for us was another informational packet explaining what "your child" had to do in order to be ready for kindergarten. And who was running the open house? One kindergarten teacher. The school has two, but the other was busy - and I understand she just lost a family member, so that was okay - and the principal apparently had decided that some interviews he had to do were more important than meeting the new parents. I disagree.

So it's very clear when you leave the private sector, even for a heavily regulated industry like nursing homes. We obviously had some amount of choice over our kindergarten, but once we made the important step of purchasing a home, we were pretty much stuck with this one, and I think that the information we got reflected that. I'm not even saying it's intentional - simply that no one's ever thought twice about having to sell their school, because no one has to.

That in a nutshell is the biggest problem with the school system, IMO. It will be interesting to see if this pattern continues or whether some more wholehearted attempts will be made at engaging us.

Monday, April 30, 2007

Precociousness

Hey, dad?
Uh-huh?
How many hours are there in a day?
There are 24 hours in a day, son.
Oh.
So how many hours are there in a night?
I meant, there are 24 hours in a day and night together.
Even in wintertime?
Huh?
In wintertime the nights are longer.
Yes, but the days are shorter too.
Oh.
So there aren't 24 hours in a day in winter?

What?
Well, you just said the days are shorter.
Well, that's true, but...say, why don't you go play with your toy cars for a while?

Friday, April 13, 2007

FastTrack seminar, part 2

Second session at the seminar was on the new features of SQL Server 2005; since I was at the launch party in Indianapolis I didn't feel like there was a whole lot that was really new; but since I'm currently employed at an Oracle shop it was interesting to compare the two. This session was given by George Huey, a Microsoft "Architect Evangelist", whatever that is; but he knew his stuff. The most interesting new feature from my admittedly database-illiterate perspective is the ability to write code in .Net and turn it into stored procedures and code that runs inside the server process. You can also set the code permissions: Safe, Unsafe, or External Access, which I believe means, "hits the file system", but regardless I don't know if anyone actually uses that feature. Another interesting feature is the ability to run "recursive queries", which sounds pretty handy: he gave a demo of calculating the number of levels of management by recurring up the tree until you find the guy with no manager.

A few other features he went over were: Native XML store; Pivots; Top; and Rank; they all seem very nice but I'm not really in a position to judge how useful they would be in my work. I guess we'll see.

The final session was on "Business Intelligence". I didn't have any idea what that might involve, but it turned out to involve reporting. I wasn't aware that you can configure SQL Server to give you a project type of "Report" in Visual Studio fairly easily, and there's also a "Report Viewer" control that you can add in to your own ASP pages. I have to admit that I lost some of this lecture, as the presenter was having some trouble with his computer and the wireless was working nicely - for a change - so I took the time to mess around with some more of the AJAX demos that I was really interested in.

The seminar was held in the Glick Center, where the Indy NDA holds its meetings. It was a good venue to hold the couple of hundred people who showed up. Microsoft sprung for donuts and pizza, and I liked the idea of having a couple of arcade games for people to check out between sessions. I would have traded them for better wireless, though. There were also only power outlets on one end of the room. But there's only one really important highlight: through the door prizes, I am now the proud owner of a Zune :) Welcome to the social! (Hello? Is there anyone else in here?)

FastTrack seminar

I’m blogging today from a Microsoft FastTrack seminar. Perpetual Technologies in Indianapolis is putting this on in some sort of collaboration with Microsoft. It’s a free seminar – and I’m always up for a free seminar – with a keynote and six sessions in three time slots.

The keynote was OK. Steve Thompson from Microsoft gave a roadmap presentation of where they expect enterprise technology to go over the next several years. The majority of audience were DBA’s rather than developers, so they may have had more interest than I did. As important things, Steve brought up Office, Microsoft Server, and mobile applications; and also Microsoft Business Solutions, about which I don’t know much. The goal, I guess, is to get enterprises on the Services Oriented Architecture bandwagon, and also to move towards virtualization as an important technique for scalability. He also discussed voice and VOIP near the end of the presentation, and how our standard voice data paradigm – blinking message lights and busy signals – is really out of date. This is something I’ve known since Interactive Intelligence was trying to get everyone out of that as well; don’t know how that effort is going, but we still have the copper wires at my last couple of jobs.

First session was on the Ajax.Asp.Net control library, which looks pretty cool. It was given by a younger guy from - I think - Crowe Chizek, and he did a creditable job, although I would have happily spent a couple of additional hours learning the subject, given the opportunity. It's interesting that most of the effects it allows you to create are already implemented in Javascript in the application I'm currently working on - a tribute to the skills of the original writers of this app, I think. But, you could certainly write a lot less code to get the same effects using this library. It looks pretty easy to use, although .Net 2.0 is required: one msi to install on your machine, and one zip file with controls and demos. It'll definitely be useful in my own web applications, anyway!

Monday, April 02, 2007

Javascript testing with NUnit

I've been looking around for a good way to test Javascript functions.

There are at least two if not more versions of JSUnit, one here and the other here. But there is one fundamental requirement I have for any unit testing framework, and that is that it has to integrate into an automated build script. For example, suppose you're using CruiseControl. It's got an NUnit step in it; once you write up your tests, it's the matter of a few minutes' configuration to get them running as part of the build, and it's very satisfying to watch the test counts grow as more builds are done. 117 tests run, no failures. 123 tests run, no failures. 135 tests run, no failures.

So if the framework doesn't work with automated builds, it's no good to me. Do they? I'm not sure. Edward Hieatt's version seems primarily to require a browser, although he does provide a JSUnit Server which appears to be designed to work from Ant or Java, but doesn't have any particular support for Nant or ASP.Net that I could find. Jörg Schaible's version is even less able to work in Windows; starting from the download which is only provided in tar.gz format. The documentation states that it can be run from the command line; if so that's easily adaptable to an automated build, but I didn't even take the trouble to download it, suspecting that it wouldn't even run on Windows.

So I was looking around for other alternatives, and I ran across this post. I'm sure that not everything you can write in Javascript can be evaluated by the .Net Javascript evaluator, but when you write a lot of tests you get used to keeping functionality nicely isolated.

I'm not sure what the best way to use this is. My first couple of tests have the Javascript in the ASP.Net codebehind file, where they can be unit tested at test time and Response.Write-n at runtime; but there's a few other possibilities; keeping all the Javascript in a separate file to be read in at test time, and using it as an include at runtime perhaps.

So I have a lot of work to do on this technique. But it seems promising!

Wednesday, March 14, 2007

Sports and power ranking systems

I've had an interest for a long time in the science of sports team rankings, for various reasons, which was forcibly brought to mind when I was filling out my tournament bracket. I'm always extremely mediocre in such game-picking contests, and when one blogger whom I respect said something similar, I started to think about how rankings could be done for college basketball. I looked a little closer at the Pomeroy Rankings, which seem pretty nice, although if Ken reveals his exact formula for creating them, I couldn't determine it. IMO a ranking system can't be taken seriously if the method that is used isn't known. Take Jeff Sagarin: Everyone always prints his rankings up very seriously, but we don't know what he's doing, so he might as well be making them up and just pretending it's math.

But Ken has something much more valuable on his site than a ranking system: a game database. For the most part, this information is not available in any easy-to-get-at-form, so if you want to create the rankings, you have to get down and do the data entry every year, which is why I've never created any system that lasted more than a year. But now, with Ken's files, maybe something useful could be done.

So I did a little research, thinking that the most effective system probably was going to be some kind of balance between a single-game Pythagorean expectation and strength of the opponent, repeating until the numbers converged. I'm sure I read a paper about that some years ago, but I can't find it now. Instead, I found this, a technique which doesn't take into account the scores at all!

But it's interesting, because it's based on the age-old theory of game commutativity; to wit: my team beat team X and team X beat your team, so my team is better than yours. Yah. It's a principle that's been widely derided for years, and people make hobbies out of finding weird cycles of games proving that Prairie View A&M is really better than Michigan after all. But there's obviously a kernel of truth in it. The paper goes into a lot of detail about setting up the graphs and putting weights on things and, you know, math, but really the principle is pretty simple. It works like this:

For each game that my team wins, it gets partial credit for each win the team it beat has.
For each game that my team loses, it gets partial debit for each loss the team it lost to has.

That's it. The questions are, do you want to go deeper and credit my team for a third or fourth level, and just how much credit do you give for each "indirect win"? The second question is easier for our purposes, because the authors of the paper do a lot more of that math stuff and come up with a simple equation for us:

Let k equal the average number of games played by each team.
The credit is (2k) / ((k^2) - k ).

For a third level, you'd square the credit, etc. But do you want to do the third level? Say the credit is .1, or 10% of a win. For the third level the credit would be .01, which doesn't seem like much, but you're talking quite a few games, too. So I'm going to have to use Ken's game database and do some research on this. Any code I create will be open-source, of course. I won't be able to do anything useful before this year's games start, but next year, watch out!

Monday, March 12, 2007

Generating classes from XML in .Net

The Oracle version of SQL has some nice keywords for returning your data in an XML format. (I suppose the other servers do too, but I've not used that feature.) When I get the XML back, I want to turn the XML into a set of business objects for easy serialization. XSD is the tool for that. Write the XML to a file, run XSD on it to generate a schema, then run XSD /c to generate the C# class file, and you've got a nice class. You can muck around with the XMLElement and XMLAttribute attributes to create nice field names, and 30 seconds to put together a static Get() method that returns a class from the XML.

Except it didn't work. The serializer threw a File Not Found error. When the XMLSerializer class has a new type it needs to serialize, it just generates the code on-the-fly and throws it into a new assembly with a name like olkdzxc.dll, and returns the class from it; but when I called the serializer, it told me that olkdzxc.dll wasn't found. Very mysterious.

Luckily, I remembered Chris Sells' old tool that was made for debugging exactly this problem, XMLSerializerPreCompiler, which lets you see the compiler errors that occur while the code is being serialized, and one of those led me to the problem: When generating the class code for an array of objects, XSD was adding an extra set of brackets in. So instead of having a class member myFoo[], I had a member myFoo[][]. Why did XSD do this? I have a hard time believing it's just a silly bug. I'd love to hear if anyone knows.