NDbUnit Revisited
I first wrote about NDbUnit back in 2006. Unfortunately, it doesn’t appear much new has happened with the project since then. The current version (1.2) is still a great help for unit testing when you need to put a database into a known state. If an application you’re testing uses strongly-typed datasets as its data access layer (DAL), integrating the use of NDbUnit into your existing unit tests is even easier because it uses XSD files.
I’ve revised my previous sample project using Visual Studio 2008. You can download the source as a zip file. Make sure you have NUnit (I used version 2.4.7) and NDbUnit installed before you attempt to run the sample tests.
Loading text file contents into a string
While working on some XSD validation code today, I found that I needed to load a couple of text files into strings to unit test. I’d forgotten how I’d done this before, but I googled the answer with this search term:
file to string .netThe top result (at least as of today), gave me the answer I needed. I've reproduced it as the following function:
Update: Ed Poore let me know in a comment that the .NET Framework contains a method that does this already. System.IO.File.ReadAllText(path) does the same thing, so you can completely ignore the method above.
A couple of "old-school" CS principles
Robert Martin is a guy our CEO and architects really respect when it comes to software design and development. Somehow, I managed to not have heard of the guy before this year, so I’ve started reading his stuff. Here are a couple of his older columns that may prove quite useful if you find yourself building APIs in your work:
- The Open-Closed Principle (in PDF format)
- The Liskov Substitution Principle (in PDF format)
iPhoto Archiving
When I bought my MacBook Pro a couple years ago, I didn’t get the largest hard drive available for it (in retrospect, a mistake). Between my music collection, digital photos, and Parallels PC disk image, 150 GB got close to full quite quickly. As a result, I’d been looking around for a way to archive some content (at least some music and photos) to an external drive to make more room.
I came across this old post that gives you a quick-and-dirty way to archive the photos (even if it doesn’t preserve the libraries). What’s especially convenient about Time Machine in this case is that if I find a better way to do it, I can recover the old setup from it and then archive properly.
The Giant Pool of Money
For a great explanation of the current meltdown in mortgages, definitely check out this podcast. The two reporters put together a narrative that covers everything from a homeowner with a sketchy loan, up to a Wall Street exec who creates collateralized debt obligations (CDOs).
Hello WordPress 2.5.1
Finally upgraded to the latest version, so I figured I’d change themes too. The upgrade process turned out to be far easier than I expected. If I remembered any UNIX scripting from undergrad, I’d automate it.
Strongly-typed DataSets in Subversion
Strongly-typed datasets are the default option for creating a data access layer (DAL) with the various .NET versions of Visual Studio. From the XSD file that defines a strongly-typed dataset, Visual Studio generates a [XSD].Designer.cs and [XSD].xss. They’re regenerated every time you change the XSD, even if you just change the layout. This can become a problem when working in teams and it’s necessary to merge changes. If your Subversion repository is configured to version the generated files, they’ll be marked as conflicting when you update.
These are the steps I’ve taken to merge changes in the situation above:
- Delete [XSD].Designer.cs and [XSD].xss.
- Resolve conflicts in the XSD file (and mark them as resolved). This will generate new versions of [XSD].Designer.cs and [XSD].xss.
- When resolving conflicts in the files generated in step 2, use the whole file that was just generated.
Paintball
I spent part of my Sunday running through the woods shooting at friends and strangers. The place: Outdoor Adventures Paintball. The occasion was a friend’s 29th birthday. Paintball has changed quite a bit since I first tried it as a sophomore in college. There are college and professional leagues now (my alma mater apparently has quite a good team). There are corporate sponsors. They even have TV coverage on ESPN2 and the Versus network.
For novices like us, it was a great time. We teamed up against a group of what looked like undergrads from the University of Maryland. In three rounds of matches (3 games per match), we won each 2 games to 1. Usually it was by killing all of them off, but at least a couple of times we captured their flag and moved it all the way down the field. The “center flag” variant of the game (one flag midfield that a team must capture and move forward through their opponents) was our least favorite. We had a really long field for it in the second match, and our strategy didn’t work that well at first. The one thing I would differently the next time is buy more ammunition. Even though you have to pull the trigger for each shot, I ran out of ammunition before our third match was over.
Macbeth, Teller-style
I saw this production of Macbeth this afternoon with my friends Jen and Alban. We were rewarded for our wait in the freezing cold (for standing room tickets) with actual seats for the show. Thanks to Alban (I owe you big for this one), yours truly got a front row seat to the show. Directed and produced in large part by Teller (of Penn & Teller), it was anything but your typical Shakespeare production (if there is such a thing). I’m no aficionado of magic, but they pulled some incredible tricks in this show. People appeared and disappeared before our eyes. We saw fake blood which looked uncomfortably real. I knew we were in for quite a ride when the show began with a Folger Shakespeare Library staffer stabbed through the back while reading us an announcement from the stage. This doesn’t even include the excellent acting, the great fight choreography, the sound effects and percussion.
Upgraded to Leopard
I installed it last Wednesday. My first upgrade attempt failed, so I paid a visit to the Tyson’s Corner Apple Store to get some help from the Genius Bar. Apparently the DVD wasn’t clean or something (since the guy cleaned it off), because when I tried archive+install as recommended, there were no problems. The next day, I picked up a 1TB Western Digital MyBook Home Edition at MicroCenter for $220 + tax so the Time Machine feature would have plenty of room to operate. It’s definitely as cool as advertised. I was impressed that when you plug in an unformatted drive, Leopard asks if you want to use for Time Machine. I was pretty lax about my backups before, so this will be a huge help.
Changing Primary Keys from "int" to "uniqueidentifier"
I’m in the process of doing this for a project that uses Microsoft SQL Server. One of the “gotchas” I came across was that once you’ve switched from “int” to “uniqueidentifier”, @@IDENTITY and SCOPE_IDENTITY references won’t work. The second response in this thread pointed me in the right direction. You have to call NEWID() in the context where you need it (and save the value) in order to be able to refer to it later.
Back to the trenches
Instead of management and code, I’ll just be writing code (at least for now). Today, I started a new job at a small consulting firm in Virginia with a software lab that wants to start putting out products.
Today consisted of the environment configuration and filling out of forms typical of a first day. Most of the last half of the day was taken up by a boot camp. I found it to be a very enlightening how-to on consulting, as well as an intro to the company’s culture.
Stockholm, Sweden
Yesterday, before our concert at Ekebyholmsskolan, we got to tour Stockholm. We arrived there from Finland via a Viking Line ferry named Isabella. Two other chaperones and I spent virtually the entire time touring the older parts of Stockholm, including a number of churches. Of the cities we’ve visited so far on the concert tour, Stockholm is the most beautiful. I really like the architecture. Bicycles get their own lanes. It’s a city that’s very easy to tour on foot. The fact that it’s on the water is also a big plus in my book.
We’re getting on our tour bus in another 15 minutes for the drive to Oslo, Norway.
Scandinavia Tour
I’m writing this from a school dorm at Toivonlinna, a Seventh-day Adventist school in Finland. I’m one of a number of chaperones for a high school choir giving concerts in Scandinavia. We gave a concert at the school this morning (and I really do mean “we”, since the chaperones got drafted to sing also). Our concert yesterday in Turku went well enough that the choir went back up to sing an encore. Iceland was our first stop, and despite its name, it was warmer than Finland is now. Even as I type, it is snowing.
The next stop on our tour is Sweden. We’ll be taking an overnight ferry there from Finland (assuming the weather cooperates) after lunch, a cathedral tour, and some shopping.
A More Perfect Union
Barack Obama spoke at length yesterday on the issue of race in general and his former pastor in particular. If you haven’t already seen and heard the speech, or read the transcript, I encourage you to do so. There is no soundbite that can do justice to the importance and brilliance of his message. If there was ever a politician who could legitimately argue that he’s a uniter and not a divider, it is Barack Obama. I only hope it helps him win in Pennsylvania.
$1.67
That’s how much one (1) euro cost me yesterday when I was converting currency with Chevy Chase Bank for an upcoming trip. You know things are bad when even the branch manager is surprised by the rate of exchange. The exchange rate is probably even worse today. Even if I took out the fees they charged, the exchange rate is probably 20-30 cents worse than it was when I first went to Europe in 2005.
It reminded me of economics classes in business school, and what we learned about what countries do to defend their currency. The Fed is doing the opposite of those things right now, so between that and deficits our government runs, I expect the dollar to be worth less and less in the near term.
The truth about usability
I came across this via Daring Fireball today. There’s a lot more than a grain of truth to what it suggests about how what most user interfaces look like.
Time to buy an iPhone?
I went to the barbershop on Friday. During my haircut, I ask my barber how he likes the iPhone. He doesn’t just like it, he loves it. I got quite a sales pitch from him. Then the guy getting his haircut next to me chimes in. He just got an iPhone as well. He actually said he’d been thinking about getting a laptop, but found the iPhone did what he needed.Of all the iPhone owners I’ve talked to since it came out (friends, fellow conference attendees, even a guy waiting for the bus in Seattle), I have yet to hear any complaints.I haven’t caved in and bought one (yet), for a few reasons:
- I’ve been kind of annoyed with AT&T Wireless lately over dropped calls
- Don’t really like the idea of a $70/month cellphone bill
- I’m kinda waiting for the next version of the iPhone (new hardware anyway)
Refactoring
Last night, I went to a presentation on refactoring by Jonathan Cogley. My notes are below:
refactor - improve the design of existing code incrementally
Code must:
- do the job
- be maintainable/extensible
- communicate its intent
Refactorings
- rename
- extract method
- inline method
- introduce explaining variable
- move method
- inline temp
I found a much better definition for technical debt. It makes a nice argument in favor of refactoring (though not as good as it would be with some way to quantify and measure it).
code smell - indication that something could be wrong with the code
Code Smells
- duplicated code
- long methods
- large classes
- Too many private/protected methods
- Empty catch clause (FxCop flags these by default)
- Too many static methods
- Variables with large scope
- Poorly-named variables
- Comments
- Switch statements
- Unnecessary complexity
When to refactor:
- before a change
- after all current tests are green
reduce scope - bring variable closer to where it’s used
Be sure your unit tests don’t re implement what the tested code is doing.
Eliminate double assignments (a = b = 0) for clarity.
Each method should have only one operation/concept.
If you must use code comments, they should explain the “why”. The code should be clear enough to explain the “what”.
Favor virtual instance methods where possible in your code.
Avoid using the debugger. Write unit tests instead.
Performance improvements tend to make code harder to understand. Don’t use refactoring to address application performance.
Recommended reading:
Wireless Mighty Mouse
I saw one of these as a clearance item at MicroCenter yesterday, so I picked one up to try it out. In the tiny bit of time I’ve used it so far, the only annoyance (and a minor one at that) is turning the mouse on and off. I find it challenging to move the slider on the bottom of the mouse without clicking the mouse body a few times. I like the little trackball on the top for 360 degree scrolling (though I don’t find myself scrolling sideways much with a 24" monitor). I haven’t played with the configuration tool much yet, but it appears to give you a wide variety of ways to customize the mouse’s behavior. We’ll see how the battery life is.
