SAF(NET) = STEPHEN A. FUQUA operating on the Web since 1995

Stephen is a web developer, Bahá'í, and interfaith activist in St. Paul, Minnesota. He likes to write about religion, social justice, sustainability, science, programming, &c.

What about uint? August 18, 2010

I’m writing a class with several methods that take integer input. The input values cannot be less than zero. Since we’re not on .Net 4.0 yet, I’m manually writing code contracts (that is, my functions check preconditions, i.e. before doing anything else, I write something like…

if (sequenceNumber < 3)
{
throw new ArgumentOutOfRangeException(
"sequenceNumber", "Sequence number must be 3 or greater");
}

This got me thinking: why don’t we ever use unsigned integers? Seems like have a uint would better communicate the requirement, and would simply not allow a negative number. The main answer seems to be that casting between uint and other data types, which is inevitable, is ugly. And that uint is not CLS compliant. Even though I’m not trying to write CLS-compliant code at the moment, I think I’ll stick with int – because that is our existing convention, and I don’t see enough reason to change the convention.

Posted by Stephen at 8:38 PM | Comments (0)

Diagnosing Production Problems: Zeroth Law August 14, 2010

Stephen's first law of diagnosing problems in production should have been: make sure you actually know the scope of the problem. We have a process that checks for duplicates in an inbound file. Records marked as duplicates are not moved into production. A refinement of the process was installed this week. All the sudden, e-mails showed that thousands of records were being marked as duplicates. I came over to help investigate, and found people looking at code, trying to figure out what was going on, because they knew without doubt that these records were not in fact duplicates.

But we needed to step back and ask what is the scope of the problem? We looked at the e-mail with the duplicates, picked a name or two from the list, and looked in the original input files and confirmed that they were not in the files. So how/why were they reported? But then let's set that aside, and ask: did all of today's records make it into production? If yes, then we have a problem but not a crisis. The answer was yes: we could see a 1-1 match between inbound file and outbound production data. Therefore, we have a minor reporting problem, but the core of the system was working just fine. Panic averted.

So what was the cause? A staging table that had not been truncated after a previous file was processed. All those records were being reported as duplicates.

Posted by Stephen at 10:26 AM | Comments (0)

DbMail - A use for global temp tables in SQL August 7, 2010

"global temporary tables are visible to all sessions," says the MSDN documentation. I have occasionally wondered when this would be helpful. This week I finally found a use, albeit limited: I want a quick-and-dirty process that will e-mail a CSV file to me every day for a week. I wouldn't do this for a full on production system (without dwelling on it, it just strikes me as too error prone and inelegant), but for some testing I want to do over the course of a week, it makes sense.

I run a query that populates a temp table, and I want to e-mail the contents of the query using sp_send_dbmail. Again, the documentation tells something important: "Note that the query is executed in a separate session, so local variables in the script calling sp_send_dbmail are not available to the query." This applies not just to a table variable, but also a local temp table (i.e. #temp). But a global temp table (i.e. ##temp) is a different story: works just fine. So there you go, quick and dirty way to e-mail yourself some query results when you don't want to just pass the raw query directly to the send command.

Posted by Stephen at 9:01 PM | Comments (0)

Diagnosing Production Problems: First Law June 11, 2010

Stephen's first law of diagnosing problems in production: try to replicate in test. (Assumptions: you have a test environment, you use it regularly, and it is reasonably close to production). Sometimes you just can't replicate the problem – for instance, it might be due to an oddity in a customer data file that you're not allowed to run outside of production. In those cases, see if you can use a proxy. For instance, try copying the file and masking the sensitive data, then running it in the test environment (of course, the masking process might cover up the error that is causing all the problems).

Production needs to stay clean, and as developers we need to keep our hands out of it as much as possible. This is particularly true in a highly secure environment with strong separation of duties, wherein you might have to drag a sys admin into the picture just to get to obscure log files, for instance. Replicate the issue, solve it, document it, and make sure everyone else in the company is able to share in the lessons learned.

Posted by Stephen at 3:32 PM | Comments (0)

Moles Free Download Without Pex May 19, 2010

I wonder how many others didn't think to scroll down further on the Pex download page, and find this link? Visual Studio 2010 Moles - Isolation Framework for .NET. Moles is available for free, while the full Pex environment requires MSDN.

Posted by Stephen at 11:10 AM | Comments (0)

Change HostType["Pex"] to HostType["Moles"] May 19, 2010

Once again I've learned the hard way that it pays to read the release notes. After installing Pex v0.91.x, suddenly I was having trouble running my tests in a particular solution. It has been driving me nuts - Visual Studio was throwing "object reference not set to an instance of an object" errors every time I tried to run tests, and the Test View was refusing to load any test names.

Finally, I noticed that I had a few tests that were still instrumented with HostType "pex" instead of "moles". I changed these around, and still got the error. Closed Visual Studio, restarted, and voìla, the tests can run, and Test View is populated again.

Pex and Moles - Release Notes

Posted by Stephen at 10:48 AM | Comments (0)

Why did they remove Promote Local Variable refactor? May 8, 2010

Can someone please tell me why Visual Studio 2010 no longer has the "Promote Local Variable to Parameter" refactoring? I use this every day. Thankfully CodeRushXpress has it, but the current version is a bit unstable, causing VS2010 to crash periodically.

Posted by Stephen at 8:15 PM

AccuRev - Review and Practices May 7, 2010

I've been using AccuRev, including AccuBridge integration in Visual Studio, for close on two years now. And I like it. I don't know anything about the licensing fees, but for the enterprise that is interested in spending some money, it is certainly a good option. So, for anyone considering using AccuRev for source code control, and who happens to stumble across this site, here are a few points to consider:

Continue reading "AccuRev - Review and Practices"

Posted by Stephen at 8:27 PM | Comments (0)

deprecated

On safnet.com

Other sites managed or developed by S.A.F.

S.A.F. elsewhere on the web

  • LinkedIn
    LinkedIn can actually be useful when looking for prospective hires and business or organizational partners
  • GoodReads
    A fun and relatively-unknown social networking site geared towards one's book list
  • Live Journal
    Mirror of the blog at safnet.com, so that a few LJ friends can more easily read and comment there