forge

Why We Build WSPs and Option Explicit

Recently I got called in to look at something by a client and in a part of the process it became apparent that the developer hadn’t created a SharePoint Solution (WSP) to deploy the solution. That and the lack of a centralized Visual Studio project made the problem really hard to find. The conversations were effectively … “Well, we’re going to do that when we’re ready to deploy it.”

This whole thing reminded me vividly of a conversation I had with a developer of mine that happened nearly ten years ago. At the time ASP was the name of the game. It was a huge jump forward from trying to write web applications with CGI-BIN. The problem with ASP pages is that they used VBScript for their development language. VBScript was/is a bad language. It was hard to debug and had all sorts of odd side-effects that you had to learn to expect. One of the really challenging things with VBScript is that by default it allows you to just use variables — they don’t have to be declared. This sounds like a great timesaving features. You don’t have to write the code to declare the variables.

In reality this is a pretty pesky thing. What happens is that you mistype a letter in a long variable name and they don’t see it. When the code EXPECTS that a previous line set a value and it doesn’t happen weird/bad things happen. This particular developer called me over from time-to-time to help him look at problems in his code — I was happy to do it. However, after about the fourth time I had found the issue was that he mistyped a variable name, I was tired of explaining how important it was to use Option Explicit. Option Explicit was a command you could put at the top of your file and among other things it would require variable declarations. The result is that if you do mistype a variable it will generate an error.

Help Your SharePoint User

His response was that he added Option Explicit at the end of the process — before he turns the code over. Here’s the problem with that thinking — you don’t add Option Explicit because you want to, because it’s a requirement, or because you feel like it. You add Option Explicit at the top of ASP files because it makes your life easier. It saves you hours of debugging on weird issues because a variable name was mistyped. I should say that I did get to the point that where I told him if I ever found another piece of code that didn’t have it — I’d fire him on the spot no matter what. That was finally effective at getting him to help himself. I didn’t end up firing him he left on his own.

Why did this come up? Well, because we build WSPs not because it’s easy. We build WSPs because it MAKES OUR LIFE EASIER. In this situation the problem was that the particular thing showed up in one environment but not in another. That screams to me that there was some sort of a deployment error. If we had a WSP we could have tested it in a few minutes on a blank virtual machine. (Of course the problem wouldn’t have happened in the first place if the deployments were consistent.)

So the next time you’re wondering whether you should start building WSPs at the start of your project — help yourself out and do it. (Repeating for effect… Build WSPs EVERY time.)