Times Are Off Again

The times are wrong on all the posts again. I feel like I’ve fixed this problem dozens of times over the lifespan of this blog. I have no idea why it keeps breaking. I post everything now from my desktop; perhaps that has something to do with it. The date on this post will explain a lot. It should be about 8:35 PM EST.

Update: Neat, every time I edit, the time advances by five hours.

The Outrage!

I can understand why I wasn’t invited to the second annual Richmond Blogger’s Day. After all, I’m just, oh, a blogger who lives in Richmond. (Well, Henrico County — but close enough.) In response to this outrageous insult, I pledge not to vote for you, Lt. Gov. Bill Bolling, and I will not consider changing my mind until such time as I, too, am treated to a free dinner at the Peking Restaurant.

P.S. I couldn’t have gone anyway ’cause, like, I have an actual job and contribute to the Virginia economy and stuff, unlike all these other pajama-clad slackers around here. :)

Keep It Simple

Ran into another post from our MVP friend Dan Wahlen: How Would You Refactor this Code? #1. I don’t normally respond to these kinds of things because it always devolves into a my-code-is-bigger-than-your-code conversation (if you know what I mean, wink, wink, nudge, nudge). But this post struck me because, again, Mr. Wahlen is using new wizbang C# 3.0 language features for no particular reason. He seems to be finding ways to shoehorn new language features into solutions that would otherwise work perfectly fine using regular old C# 2.0 features.

But on to the refactoring. Here’s his code snippet:

string name = “mc_gross_1”; //The prefix and number are variable
string[] cartNames = { “item_number_”, “item_name_”, “mc_gross_”, “quantity_” };
if (cartNames.Where(p => name.StartsWith(p)).Count() > 0)
  //process name

I like to know what code is doing at a glance, but it’s not terribly obvious what that’s doing without comments or study. So first I would want to move the arcane C# 3.0 stuff into a clearly-named function. In this case an Extension method to extend the string object seems like a good idea. The end result might look something like this:

if( name.StartsWithAny( cartNames ) ) { }

That’s much easier to grasp. The actual implementation of StartsWithAny() doesn’t make much difference, but I certainly wouldn’t use Lambdas, LINQ, or Regex. What’s wrong with, you know, a loop?

Meet The New Boss…

Since I first saw SWAC Girl’s post welcoming Spank That Donkey to the ODBA, I couldn’t help but think that there was going to be trouble in that organization. Could Spank and Shaun Kenney – bitter rivals on opposite poles of Virginia Republicanism – co-exist together in the same organization?

Eh, not so much, it seems. I’m just reading between the lines of course, but it sounds like the SWAC bloggers are hijacking the ODBA to rule it with an iron fist of intolerance, and Cat is the first victim. Daily Whackjob thinks so, too.

Anybody surprised? Me neither. That’s your Republican grassroots in action, Virginia.

P.S. Where da heck did this Richmond Blogger’s Day come from? Is this another one of those contrived political gigs where Lt. Gov. Bolling tries to glad-hand all the Virginia bloggers?

New Design Online

New blog design is online. It still has some problems which I will be addressing in due time, mostly in the area of comment style. Also, I’m aware that page loads are ridiculously slow, but that might out of my control.

MVPs Should Not Publish Bad Code Samples

Some programming blogs are informative and trustworthy. Unfortunately, most aren’t. For example, in an otherwise good post explaining new features in C# 3.0, I found this shocking sample C# 3.0 extension method among the blogs at the popular site ASP.NET Weblogs:

public static string RemoveNonNumeric( this string s )
MatchCollection col = Regex.Matches( s, “[0-9]” );
StringBuilder sb = new StringBuilder();
foreach( Match m in col )
sb.Append( m.Value );
return sb.ToString();

The trouble is: That sample method should not be emulated under any circumstances. I can’t think of any reason to use a Regex match for something as simple as stripping characters from a string. Regex matching is relatively expensive, not to mention very cryptic for most junior-level programmers to understand.

Out of curiousity, I looked up this guy’s bio. “Dan Wahlin (Microsoft Most Valuable Professional for ASP.NET and XML Web Services) is a .NET development instructor at Interface Technical Training.” Not only is he a Microsoft MVP but he’s an instructor! And he’s written books! Now I don’t know if he wrote that sample himself or not, but even if he copied and pasted it, his credentials indicate that he should have the wisdom and experience to remove that Regex.

I realize his point was to demonstrate extension methods and not the best way to strip characters from a string, but still, I don’t think people in positions of authority should ever publish bad code samples. He should revise his blog post before too many impressionable young coders see it — or revise his credentials.

P.S. I was going to leave a comment about it, but someone already did. Mr. Wahlin did add an addendum to his post, albeit somewhat indignantly. At any rate, the fact that he went with a Regex as his first choice for stripping characters indicates a certain lack of experience, in my mind. Buyer beware.

UvMoney Back to XML

Note: This has been sitting in my drafts for months.

I previously wrote that I was switching to a database backend for UvMoney. I’m not doing that anymore. :)

As I was adding in the database implementation, I started to realize that I was putting in a lot of work and adding some project dependencies for a negligable return. I also realized that I trusted the XML code completely, but I didn’t trust the new database code at all, and I just couldn’t bring myself to “flip the switch” and remove the XML functionality. (After all, this application is “in production” in the sense that I have used it daily for my household finances for almost a year now — I sure don’t want to lose that data.)

So I re-thought my strategy. Instead of abandoning the XML files, I’ve decided to revise them to support the functionality that the database would have given me.

My original XML file design revolved around what I call “Transactions.” In UvMoney, a Transaction is a balanced collection of two or more credits and debits, each of which I call a ”Line Item.” This is standard accounting stuff. The total of the credits in the transaction must equal the total of the debits, blah blah, etc. etc. Originally, I envisioned the Transaction as the central data structure.

However, while implementing the database, I found that it’s much easier to work with the data when the Line Items are the central data structure. Making that change required a slight change in the XML structure, namely moving some pieces of data from the Transaction level to the Line Item level.

Now that I’ve made that change, I can do everything I want with the XML files.

The only lingering question is concurrency. Obviously I can’t allow two people to write to the XML file at the same time, so I’ll have to implement some kind of locking scheme.