Class of the Day: System.IO.FileInfo

Today I learned about a class in the .NET framework that I've never used: System.IO.FileInfo. I came across it while looking up the appropriate method to determine the size of a file for a unit test. I had expected that there would be a method in the System.IO.File class for this, but I was mistaken. It turns out the proper way is to use the Length property of a FileInfo instance.

FileInfo is kind of a weird class. In fact, I'm not really sure what the design impetus behind it was. It actually duplicates a lot of the behaviour of the File class, which I use all the time. In fact, it duplicates so much so that I would have expected the two to be a single class. It appears that the distinction is primarily that File is static while FileInfo is the instance equivalent, with some of the methods moved to properties. Although it's still not clear to me why they couldn't just have it all in one class, with methods overloaded for static and instance calls.

By way of summary, the FileInfo class inherits from FileSystemInfo. Some of the interesting properties include Directory, Exists, and Length, as well as both "regular" and UTC variants of properties for file access and creation time. Interesting methods include Encrypt() and Decrypt(), CopyTo() and MoveTo(), and SetAccessControl to set ACLs on the file. I wonder how Mono implements that last one. It's supported, but undocumented.

PHP bug of the day

I came across an annoying little bug in PHP this afternoon. Nothing I can't work around, but it's another example of the general suckiness of object-oriented programming in PHP.

Here's the situation. I've been slowly refactoring LnBlog over the last few months. I'm trying to make the design more object-oriented, easier to maintian, and just generally less messy and ad hoc. I'm adding in unit tests with SimpleTest and, at least today, I was actually working with a copy of Martin Fowler's Refactoring open in front of me.

The particular problem that popped up was with a class called Path that managers the building and converting of filesystem paths. Two of its methods are get() and getPath(). Both simply join a list of path components into a single path string. The difference is that get() is an instance method and works on instance variables. The getPath() method, on the other hand, is a static method where you just pass in the path components as parameters. Since these two methods do essentially the same thing, I thought that it would make sense to combine them.

In a language like C#, I would simply do this by overloading the get() method and having an instance get() with no parameters and a static get() with a parameter list. However, there is no overloading in PHP. The typical method is simply to fake it with optional parameters. Ugly, but it works.

Well, today I thought I'd be clever. I reasoned that, when a method statically, there is no instance of the class and hence the $this variable isn't set. So I tried something like the following: function get() { if (isset($this)) { return $this->implodePath($this->sep, $this->path); } else { $args = func_get_args(); return Path::implodePath(DIRECTORY_SEPARATOR, $args); } } The problem with this is that it only sorta, kinda works. More specifically, it only works when you don't call it statically inside another class method.

If you're familiar with bug 30355, this shouldn't come as a surprise. Turns out this behavior is actually for backward compatibility with various badly broken code. I can only hope that this is a bug that got grandfathered in rather than something that was originally done by design.

At any rate, the workaround was quite simple. I should have done it the first time - just replace that isset($this) with func_num_args() == 0. problem solved.

Back home

I'm finally back home, sitting on my back porch with the laptop, sipping a diet W-up (the Wegman's-brand version of 7-up).

My class in Hartford finished up early on Wednesday afternoon, so Sarah and I spent the rest of the day walking through the rose garden in Elizaeth Park. On Thursday morning, we took the hour drive down to Mystic.We spent the morning and early afternoon at the aquarium and then browsed around the shops at the Old Mystic Village. My two big purchases were my first ever chocolate-covered frozen banana (yum!) and a decorative bokuto.

After a very nice dinner at the Steak Loft, we spent the night at the local Comfort Inn. I found it somewhat annoying that the $100 per night room at the Comfort Inn was actually much nicer than the $150 per night room at the Hartford Crowne Plaza. The Comfort Inn had more storage space, better TV channels, complimentary breakfast, and didn't charge for internet. The worst part is that I didn't find this all that surprising. For some reason, the fancy, expensive hotels always nickle and dime you to death. Apparently they can't scrape by on the higher room charges and over-priced room service.

On Thursday, we wandered around downtown Mystic and then went to the Mystic Seaport. The seaport is actually one big museum. It's a recreation of a 19th-century costal town and has a rather an active program to preserve period ships. It was actually very interesting.

After that, we headed back to New York. We stopped at my parents' house for the night, since it's on the way, and came home this morning. Of course, we had to make a stop to pick up the latest Harry potter book. By now, Sarah's probably about half-way through it. The speed at which she goes through novels is just disgusting.

Last day of ESRI class

The ESRI class is almost over. We're down to the last 2 of 16 lessons.

Today has been pretty boring for me. The instructor has been doing a great job, it's just that we're getting deeper into the details of managing a geodatabase. Since this is the first time I've ever actually worked with a geodatabase, the finer points are more or less lost on me. I can understand the concepts, but I have no frame of reference for applying them. In terms of practical knowledge, I don't even know enough to ask an intelligent question.

By way of contrast, the people from host agancy, the City of Hartford, really know their stuff. They've been to several ESRI classes, gone to the ArcGIS user conference, and work with an ArcGIS database regularly. It's clear that they have a good handle on this stuff and are really getting something out of this.

All in all, I file this experience under "pointless waste of time and money." I had a better time than I anticipated, and I now know something about ArcGIS geodatabases, but I really had no business attending this class in the first place. They should have sent someone with at least a basic knowledge of ArcGIS instead - or, at the very least, someone who isn't looking to jump ship at the first opportunity (and my supervisor does know I'm looking for work - I'm not trying to hide it).

So, to sum up, I did get something out of this experience and it was very nice to get out of the office for several days. But the benefit to my employer won't even come close to justifying the $1400 registration fee plus travel expenses. I really don't know what they were thinking.

ESRI class day 2 - boredom and web access

More live-blogging today. Unfortunately, it turns out that's the only kind I'll be doing until the class is over. I'm staying at the Crowne Plaza hotel, and while they offer WiFi service, they charge $10/day for it! That's actually worse than the $4/2-hour block that they charge for the AT&T WiFi at the Barnes & Noble back home. At that price, I could get 5 hours of service, and there's no way I'm going to be online that long here. Fortunately, the PCs in the training room for the class have web access, so I can at least check my e-mail.

Yesterday afternoon and this morning we got more into the details of managing ArcGIS geodatabases. Things like connection methods, authentication, data loading, management tools, "gotchas", and so forth. Basically, the stuff I will probably never need to know.

I'm actually a little ambivalent about this class so far. On the one hand, it's absolutely mind-numbing at times. It's not that the class is bad, it's just that it's getting into details that have absolutely no relevance for me.

On the other hand, it's actually very interesting in an academic sense. After all, we're talking about a system that scales up to clustered, multi-terabyte databases. The ArcGIS server runs under Windows, UNIX, and Linux and supports pretty much all the major DBMSs - Oracle, SQL Server, DB2, Informix, and there was even some talk of people using Postgress and Sybase. So we're really getting a closer look at the architecture of a very complex, high-end system. Plus our instructor has been around long enough that he can talk about how things have evolved over the years and the direction the architecture has taken. We're not just getting the tedious technical details, but some insight into the layers of the system, the APIs involved, and how everything interacts on various levels.

So as a case study of a major major information system, this class is actually quite interesting. However, it's really a class on managing geodatabases, not a case study on ArcGIS. So while the concrete details are putting me to sleep, the high-level stuff was definitely worth hearing. As a programmer, you tend to look at and read about things on more of a code-level. It's good to see how the "big boys" handle complicated design issues.