Monday, January 31, 2005

DateDiff in C#

This post will probably only matter to those of us who have VB roots, which I get no end of heckling from my co-workers about. But as I was working today, one of the things I had to do was calculate the span between two dates in months. Piece of cake, I thought to myself. All I have to do is use the DateDiff and specify months...except where is DateDiff in C#??? It is AWOL!

So I tried to see what else I could come up with. I did uncover this thing called System.Timespan. Apparently, Timespan will give you the difference between two DateTimes in something called 'ticks.' You can then take the ticks, and convert them to days, hours, minutes, seconds, and milliseconds. The drawback is that if you want the difference in years or months, you have to do some hoaky manual calculation that may or may not jibe with what the span really should come out to. In my research, this was the best example of how to duplicate the DateDiff in C#.

Thursday, January 27, 2005

Estimates...Need I Say More?

It’s been one of those projects. I was the one who estimated it, so how can I complain when it takes me the majority of my estimate just to figure out what it is that the specification documents is really trying to tell me to do? How can I push back that it is a change for me to be able to understand the bits and pieces of detail that don’t fit together in any logical fashion? The answer is I cannot. So that is why I have been not posting lately and instead have been working as hard as I can to meet my deadlines, even when it means extra hours that I do not bill to the project.

I have a friend, Avonelle, who is an independent. She has a very different way of dealing with estimates. Instead of giving an estimate to her client and tracking her actual hours versus her estimated time so she can bill hourly, she assigns a “value” to her projects, and bills the “value.” Although she creates an estimate to help her decide what the value should be, the actual number of hours she works is immaterial. She is encouraged to be efficient with her time since her “hourly rate” decreases with every additional hour she has to put into the project. It is still in her best interest to deliver quality solutions to her clients if she wants repeat business, so her client should not suffer for Avonelle’s efficient use of time or cutting of corners.

I wonder if a large consulting company could ever take this approach to billing clients…

Thursday, January 06, 2005

Microsoft Certification Tests

I am working on my MCSD.Net for C#. I have my MCSD for Visual Studio 6.0 and VB. I have been casually working on my certification for over 6 months. I got my first MCSD certification when I was fairly new to the field, and being certified seemed to be a very important marketing tool for a rookie. This time around, I am just having a hard time getting excited about studying and taking the tests.

I have taken and passed two tests so far. The first test I took was the 70-316 exam - Developing and Implementing Windows-based Applications with Microsoft Visual C# .NET and Microsoft Visual Studio .NET. The second test I took was the 70-320 exam - Developing XML Web Services and Server Components with Microsoft Visual C# and the Microsoft .NET Framework. Why I didn't take exam 70-315 immediately after exam 70-316, I will never know. The two exams overlap quite a bit, and now I am going to have to re-memorize all of the facts on the test.
Anyway, I passed the web service test and I have never written or consumed a production web service. I would like to. I played with web services in my studying, and felt that I did learn a lot while studying for that test. But do I know enough to be certified in web services? Maybe, I guess.

I had to study just as hard for the Windows test. I have been involved in many WinForms .Net projects in my career. I have been involved in an enterprise-level implementation of a WinForms application. In this implementation, we integrated with Office 2003. We also built a build helper to go out and crawl Visual Source Safe for us to make it easier for our three-man project team to coordinate efforts without stepping on each other's toes or having to wait for one another. It was a cool project.

So here is what I struggle with. I should have been able to quickly and easily pass a certification test on .Net WinForms with minimal studying. I should have had to pour over the Microsoft Web Services information in MSDN and done a painstaking number of hours of work to be up to snuff enough on web services in order to become certified.

But the truth of the matter is, I had to study an equal amount of time for each test. I also found each test to be very silly in the minute details that I was tested on rather than being tested on everyday uses of Visual Studio and on the far-reaching implications that your architectural decision could make. For example, there was not one question on best practices for organizing your classes in a project. There was not one question on best practices for using coding standards, commenting your code, or having project-wide standards for the user interface design. Not once was I asked about what I should do as a developer to prevent cast errors when I am trying to persist data to a database with a field type of smalldatetime. I was not asked when validation should be used, and why. I was not asked what are the best practices for creating a usable menu structure in my application.

I was asked questions about how to set up a connection string. How many of you out there know the syntax for a connection string by heart? All I have to do in the field to figure that one out is open up google.com. But I can't use google to show me how to organize my code in a manner that will make it the easiest to refactor and maintain. So why doesn't Microsoft test us on these things?

I guess my concern is that certifications mean very little if an inexperienced person who picks up a book and memorized a few facts has the same chance of passing the tests as someone who has been studying software engineering and implementing enterprise solutions, using Microsoft tools, for years.

Is it meaningful to be certified? Is it merely a marketing tool that we can use to make us look like more bona fide professionals when seeking out clients? And how could Microsoft build more meaningful questions into their exams so that skills other than syntax memorization are tested?

Wednesday, January 05, 2005

One to One Relationships

After many weeks, I am back with a question for you all. How do you feel is the best way to handle a one-to-zero or one relationship in a database? Let me explain what I mean.

First, I feel that there are two scenarios where a one-to-zero or one relationship applies. The first example represents two distinct objects, such as an employee and a computer, where a business rule states that one employee cannot have more than one computer, and one computer can only belong to one employee. I would probably argue that in time, this will turn out to be a false business rule, as when one employee leaves, the computer is assigned to another employee. Or when the computer dies, the employee gets another one. But for now, lets just pretend that the one-to-zero or one applies here. I think it makes sense for there to be an employee table and a computer table. Each table would have its own primary key, and lets just assume that they key is an auto-incremented identity. How should the tables be related? Should we add an EmployeeID field to the Computer table? Or should we add a ComputerID field to the Employee table? Here, it really shouldn't matter. We might choose to put the ComputerID in the Employee table because we feel that "employee has a computer" makes more sense than "computer has employee." Either way, it shouldn't really matter, though.

But how about in the second situation where we have a one-to-zero or one relationship to represent a supertype/subtype relationship? For example, we have a supertype of Individual with subtypes of Employee, Contact, and Owner. The Individual table has fields for the first name, middle name, last name, address, phone number, SSN, and there is an auto-incremented identity column which holds the IndividualID. Let's assume that the Employee table has fields for the employee number, title, related department, hire date, start date, and end date. The Contact and Owner table also have unique field in them. So how do we relate the Employee table to the Individual table? How do we represent the "Employee is an Individual" relationship in the database?

I have seen this handled in two ways. First, we could have the primary key of the employee table be the IndividualID. This is also a foreign key to the Individual table. So the IndividualID would exist as the primary key of four tables, the Individual table, the Employee table, the Contact table, and the Owner table. In the Individual table, Employee table, and Contact table, the IndividualID would also be a foreign key to the Individual table.

Or, we could have the primary key of the Employee table be an auto-incremented identity field called EmployeeID. We could then store this ID as a foreign key in the Individual table. So the Individual table would end up with three foreign keys, the EmployeeID, ContactID, and OwnerID. Each of these fields would allow null, and only one field should contain a non-null value.

Which solution is the better one?