C# Documentation

More fun features in .NET, actually this time specific to C#. Documentation, though not usually the most fun thing to write, is probably one of the most valuable. C# lets you embed your documentation in your source code as XML. Visual Studio users will be pleased to know that their IDE automatically rips out the XML and creates Microsoft MSDN style files automagically. But where does that leave those of us who hack in Notepad or Eclipse? Even better off! Enter your XML documentation (more information on XML documentation within C# below) in your source code and then add a flag to your compilation statement. Here’s a sample compile statement of a class called ‘MyClass’:

csc /t:library /r:System.dll /doc:MyClass.xml MyClass.cs

Given that you entered comments in your source code, the C# compiler will then strip our your comments, package hierarchy, related classes and create an xml file, in the above case, called ‘MyClass.xml’. In and of itself, this doesn’t do you much good. But if you download NDOC from sourceforge, you can create not only Microsoft MSDN style help files, but JavaDoc help files, LaTex helps files and plain xml.

Further Resources:
C# Programmer’s Reference: XML Documentation [msdn]
C# Programmer’s Reference: Tags for Documentation Comments: [msdn]
XML Comments Let You Build Documentation Directly From Your Visual Studio .NET Source Files [msdn mag]

System/App Configuration in .NET

I mentioned I’m working with .NET stuff on my current project. One of the nicer features I’ve found so far is that .NET includes an entire package devoted to System/App Configuration. So I I’m writing an web application, I can put a web.config file in the root of my app and/or any of the subdirectories of my application. Inside that web.config file, I can set security, modify the compiler setting, specify an error handler… you get the picture. IMHO, the best part is that you can extend web.config and add your own custom settings. For instance, almost every web application worth a look uses some sort of database, which usually requires a database connection string or DSN name. You’d add something like this:

<appSettings>
   <add key=”connectionString” value=”user id=sa;password=mypassword;initial catalog=mydb;data source=mydbserver;Connect Timeout=30″ />
</appSettings>

outside of the system.web tag. To use that value in your application, you need not parse the xml file, you don’t have to worry about getting it into application scope, you don’t need to worry about locking. You only need to write one line of code:

private static String CONNECTIONSTRING = System.Configuration.ConfigurationSettings.AppSettings[“connectionString”].ToString();

Pretty simple isn’t it? It gets better. According to this document, “ASP.NET detects changes to configuration files and automatically applies new configuration settings to Web resources affected by the changes. The server does not have to be rebooted for the changes to take effect.” and more importantly, “ASP.NET protects configuration files from outside access by configuring Internet Information Services (IIS) to prevent direct browser access to configuration files.

Further Resources:

ASP.NET Configuration: [source]
Format of ASP.NET Configuration Files: [source]
Configuring Applications in .NET: [source]

WEB-INF directory security

Thanks to Maia for pointing out that my WEB-INF directory on karensrecipes.com and other jsp based sites was accessible.. I was under the (incorrect) impression that Tomcat didn’t allow requests to the WEB-INF directory by default, but apparently it’s something you have to setup in Apache, specifically:

<Location “/WEB-INF/”>
   AllowOverride None
   deny from all
</Location>

Covalent has an excellent support document on properly setting up your Apache and Tomcat installation.

On patent law and how the proliferation of patents granted by the USPTO is bad for society

Great article on Forbes.com on patent law and how the proliferation of patents granted by the USPTO is bad for society: “… too many patents are just as bad for society as too few. The undisciplined proliferation of patent grants puts vast sectors of the economy off-limits to competition, without any corresponding benefit to the public.” [source: slashdot.org]

The Slashdot piece was focused on a lawsuit brought by F5 Networks whose aim was to defend a patent on technology that “… improves the interaction of servers and desktop computers with Web browsers. Information such as shopping cart contents is often stored in files called “cookies” on desktop computers; F5 was awarded a patent that lets a Web traffic management device reunite a desktop computer with a particular server if the desktop computer user returns to the Web site.” They’re effectively saying that they own the technology that provides “sticky sessions”. I guess in an industry (software) where the barrier to entry is so low, patent law helps to brings the barriers up a notch or two. But seriously F5, how trivial is this technology? Your hardware device examines the HTTP stream, picks out the cookie and sends the user to the appropriate server. How long did it take to figure that out? 30 seconds? Innovation? No. I hope you all go to bed at night feeling like you made a contribution to the world.

Now with 50% less caffeine!