C# versus VB.NET

I decided to post on this topic today because of an article I saw on the printer at work this morning. You can check out the entire article yourself here, but what made me decide to post was the author’s assertion that VB.NET can be “considerably less verbose than C#” because of the “with” keyword. He left out the existence of the “using” keyword in C#. The code he writes as an example could be simplified to the following:

using (TabPage tp = tabControl1.TabPages[0]){ tp.BackColor = Color.Red; tp.BorderStyle = BorderStyle.Fixed3D; tp.ToolTipText = “Click Me!"; tp.Text = “Hello world”; }

In C#, the keyword does double-duty by indicating inheritance from .NET and COM libraries. In VB.NET, another keyword (Imports) is needed for this task.

The author is right about the existence of more automatic formatting and IntelliSense code-completion in VB.NET. However, I consider it more a hindrance than a help when creating properties. In C#, if you want to create a read-only or write-only property, you write the property with just the get block or the set block. In VB.NET, you’re required to provide a ReadOnly or WriteOnly keyword to get the same effect.

The initial reason I decided to learn C# instead of VB.NET is a demo I saw from Don Box at a Guerilla.NET class in 2001. He took a MS Visual C++ sample app and used the .NET Framework to compile it. He didn’t have to change a single line of code to get this to work. He said at the time that this was the only language that trick was going to work for. He turned out to be right.

Early on, another argument in favor of C# was the number of code samples and books. It seemed heavily in favor of C# versus VB.NET, though the gap has certainly narrowed in subsequent years.

A third argument in favor of C# is what language software products are being built in. I heard plenty of rumors in 2001 about Microsoft rewriting some things in C#. But what’s certainly true is that some companies are building products with C#. Writely, a recent acquisition of Google, is written in C#. Community Server, from Telligent, is also written in C#. NUnit, an excellent unit testing tool (ported from JUnit), is also written in C#. NAnt is a C# port of the Ant build tool.

Mine is just one opinion among many as to whether you should use C# or VB.NET. But when there’s a development team involved, the language to be used should be the one the majority of developers are familiar with. That’s why I chose VB.NET when building MethResources.gov even though I personally prefer C#.

Here are some other opinions on the subject: Choosing between Visual Basic .NET and C# (by Ted Pattison) From VB.NET to C# and Back Again (by Darren Neimke and Scott Mitchell)


Open Source on the .NET Platform (part 2)

Back in April, at the end of my first post on the topic of “open source .NET”, I’d written that the next post in the series would be about Community Server. Telligent released version 2.1 of their flagship product just last week.

I first found the product at the end of 2004, when it was still Community Server: Forums. My employer was bidding on a project to provide an online forum to one of our government clients. One option they were considering was to make a copy of a custom online forum they’d already done for another client and modify it to suit the new requirements. This option reminded me of two things I dislike most about custom development:

It didn't take too many Google searches before I found Community Server: Forums and put it forward as an alternative. The next few paragraphs will discuss how I felt the product stacked up against "the four questions".

1. Is open source the best choice for this application? Because of how long online forums have been around, open source is a particularly good choice for this application. I came across a pretty large number of options for online forums when I was searching. That said, a number of them were written in languages like PHP or Perl for UNIX (which helps answer question 2).

2. What platform are your developers most skilled at building for? As a Microsoft shop, trying to deliver a customized solution on a platform the developers weren’t familiar with was far too high a risk. This eliminated a significant number of the applications I’d seen.

3. Is the best open source application on the .NET platform? In 2004, I would have said no. To me it seemed more likely that the best open source forum application would be on UNIX, simply because of longevity. But given what the developers we had were familiar with, and the alternative of cut-and-paste inheritance with a classic ASP solution, Community Server: Forums was the best for our purposes.

4. Is it our goal to re-sell an application we’ve extended? Unlike our experience with IssueTracker, the objective of making money with modified versions of this application was clear from the very beginning.

There are two “barriers to entry” with Community Server that proved significant in our case:

  • C#
  • Documentation
While I had made a deliberate choice to learn C# instead of VB.NET back in 2001, the vast majority of the developers I had to work with had moved to VB.NET from VB. The lack of familiarity with C# syntax led to a number of suboptimal choices for customizing the look, feel, and functionality of a particular instance of Community Server. The relative lack of documentation (both in the source code and stand-alone) made it a challenging platform to extend. I suspect that some of this is by design, as Telligent still makes some portion of their income from custom implementations of Community Server.

On the plus side, Community Server is quite well-built. Its naming and architecture are consistent enough that it took me relatively little time to customize a version of it for my most recent project: pushingback.com. The site is customized in a way that would make it quite easy for us to upgrade the site from Community Server 2.0 to 2.1 if requested. If the companies that currently use it are any indication (Microsoft, Dell, MSNBC), it’s one of the bigger (if not the biggest) successes of open source on the .NET platform. In my next post on this subject, I’ll discuss an issue that seems unique to open source on .NET–competing products from Microsoft.


Downtime

I haven’t blogged in awhile since finishing my latest project, pushingback.com. My employer sent me off to Cognos 8 training last week. I’ve spent the rest of the time doing what I can to fill in the void between billable projects. My boss tries to fill in the time by assigning me tasks like documentation, and creating PowerPoint presentation on this or that flavor-of-the-month technology. The latest such assignment is to lead a project to create a web application our clients can use to communicate with us about past, present, and future projects.

My employer was very cheap concerned about the impact on the budget, so when it came time to implement an internal solution for defect/issue tracking back in 2004, we chose to customize the ASP.NET IssueTracker starter kit (I’ve discussed this earlier) instead of dropping some cash on FogBugz or Bugzilla.

Now that my boss has suggested looking at COTS or open source solutions (again), I’ll be spending at least some of this downtime trying to find an improved solution.


ASP.NET 2.0 Membership

Today I’ve been spending a bit of time fiddling around with Visual Studio 2005, particularly the ASP.NET 2.0 membership functionality. When I visited 4GuysFromRolla.com to see what they had to say about it, I came across 5-part series of articles. The examples are in VB.NET, so I’ve been rewriting them in C# (my preferred .NET language) as I go along. What stood out about their information message example in part 4 of the series was that they added a label to their login page and set the text string based on the error details.

It seemed to me that there should be a property in the Login control that could be set programmatically instead of adding a label that results in two error messages for the user to look at. It didn’t take much digging before I found it. The property: FailureText.

Here’s how my revised code looks:

protected void Login1_LoginError(object sender, EventArgs e){

MembershipUser userInfo = Membership.GetUser(this.Login1.UserName);

if (userInfo == null){

//The user entered an invalid username…

SetLoginFailureText(string.Format(“No account exists with the username ‘{0}’.",this.Login1.UserName));

} else {

if (!userInfo.IsApproved){

SetLoginFailureText(string.Format(“The account with the username ‘{0}’ has not yet been approved by the site’s administrators.”, this.Login1.UserName));

} else {

if (userInfo.IsLockedOut){

SetLoginFailureText(string.Format(“The account with the username ‘{0}’ has been locked out.”, this.Login1.UserName));

}

}

}

}

private void SetLoginFailureText(string failureText){ this.Login1.FailureText = failureText; }


Effective Bug Reporting

This has been a real problem at work lately. I’ve decided to write a document to send to people who report bugs to try and stem the tide of useless “it doesn’t work” reports. I found a nice long piece on effective bug reporting by Simon Tatham here. I’ll probably use it as a reference for further reading because I envisioned something much shorter than seven pages.


Community Server 2.0 Quick Image Buttons

The blog I’m building for a client at work needed an image button to trigger searches instead of the standard link button. After my ill-advised attempts to extend CommunityServer.Controls.IButton, the consultant I’m working with recommended a far simpler solution–changing the ASP.NET LinkButton tag to enclose an HTML image tag with the border attribute set to zero (0).

If you want to use the same technique, start with this sample skin file.


A "Most Viewed Blog Posts" control for Community Server 2.0

The Code Project is one of my favorite sources for finding out how to do things on the .NET platform.  Since my blog was down for a bit a couple days ago, I thought I’d put an article there on the latest bit of customization I’ve done to Community Server.  If you’re interested in the article, visit this link to read it.


Adding static pages to Community Server 2.0

I was actually searching for information on how to add dynamic pages to a Community Server 2.0 installation when I came across this post.  While I don’t need static pages for my current project (yet), this information probably saved me hours of unnecessary work.


Changing File Upload Limits in Community Server 2.0

I wanted to see how much effort it would take to replace this RSS feed with a CS 2.0 blog. It’s currently being generated by an old ASP application that I customized with a colleague of mine. But I kept getting errors when I tried to upload MP3 files above a certain size. A bit of googling revealed this MSDN entry and the attribute “maxRequestLength”.


Browster

I came across a story about this nifty little plug-in just this morning in MIT Technology Review.  While the story was about companies trying to change the way people browse the web, Browster was the technology that interested me the most.  You install a plug-in that lets you hover over a link to preview its contents instead of having to click the link.  If

you want to change the way you browse the web, definitely give this a try.  It could be a long while before you ever have to use the “Back” button again.


Windows Vista: The Incredible Shrinking OS

According to this article, Windows Vista is losing yet another feature.  Reading further, PC-to-PC Sync doesn’t sound like much of a feature, since it only works between machines running Vista that have the same user account.  But add it to the removal of WinFS, Monad scripting shell, and other bits, and the remainder is an OS that requires more hardware resources (for a prettier GUI, whoopee!) without any discernable improvement in areas like performance or functionality.

Since Vista will probably be behind what Apple users now get with Mac OS X Tiger (not to mention Leopard when that finally comes out), perhaps Microsoft should quit kidding themselves.  A Windows XP Service Pack 3 release this year might help make up for Vista being so late.  Then they can target the Leopard feature-set so that they’re actually releasing something competitive in 2008.


RSS Publishing

It shouldn’t be a big deal at all with apps like Community Server 2.0 or WordPress available, but budget and/or personnel constraints often conspire against us using either one. So lately, we’ve spent more time (and money, but salaries apparently don’t count) putting together custom applications to generate RSS feeds.

I always check to see if a solution to my problem already exists before building my own, so when it came time to develop the MethResources.gov RSS feed, I simply reused the example from this article by Scott Mitchell. Behind the ONDCP podcast (I did the database work, a colleague did the rest) is a classic ASP application with the most basic admin functionality.

To cut down on this sort of one-off RSS app building, I’ve been hunting around for any bits of code or fully-formed toolkits that could be reused easily. The latest interesting bit of code I came across is the ASP.NET 2.0 RSS Toolkit. It’s from a Microsoft employee, and most comments I’ve read on it have been positive. Of course, when I tried to get the samples to work, I had all kinds of problems. The solution was to create a new website project (with location = “File System”) , browse to the samples directory of the toolkit, and open the existing website. Once I did this, and added RssToolkit.dll to the GAC, all six scenarios worked perfectly.  The two examples I tried from Scott Guthrie’s blog entry on the toolkit worked also.

The only things I haven’t found in this toolkit so far are support for enclosures and an easy way to syndicate a database.


Dad wants an MP3 player, but not an iPod :-(

Since I own 2 iPods (the 2GB nano that came with my new Passat, and a 20GB I bought myself), I hope to dissuade him from a non-Apple music player purchase.

He wants something to use during his workouts, and he wants a radio tuner.  He’s put off by the cost Apple’s music player offerings.  I haven’t looked at the Apple Store website in awhile, so I completely missed the re-pricing of the iPod shuffle.  The 512MB one is just $69, while the 1GB is $99.  While this doesn’t solve his desire for a radio tuner, it should meet his price.

Looking around for competitors to the iPod shuffle, I came across Dell’s DJ Ditty. It’s small and light, and manages to integrate an FM tuner.  It’s $84, $15 more than the iPod shuffle of the same capacity (512MB).  You’d also have to use MusicMatch Jukebox instead of iTunes.

Searching through PC Magazine revealed another option: the Samsung Yepp YP-T5. It’s an old review, but this player includes a screen, an FM tuner, and voice recording for under $60.  The catch: it only has 256MB of space for music.  Samsung has similarly sized (i.e. larger) offerings to the iPod shuffle that cost around $100.  None of the ones I’ve seen offers more capacity than the 1GB shuffle, and some offer less capacity at a higher price.

I’ll keep hoping he goes with an iPod instead of something else.  So far I’m underwhelmed by the iPod’s competition.


ASP.NET Calendar Customization

My latest assignment is to help redesign this website into a true blog for the office of the drug czar. We’re using Community Server 2.0, and one of our requirements is to customize the calendar. Since the CS 2.0 calendar is a wrapper around the stock .NET framework one, I put together a Word document to explain the customization process to the graphic designers who are actually responsible for the look-and-feel of the calendar. My hope is that they’ll understand it well enough to reduce my workload when it comes time to implement this.

The document applies pretty well to calendar customization in general for ASP.NET 1.1 projects.

I created an RTF version and an HTML version of the content as well.


A general theory of design

“Design consists of creating things for clients who may not know what they want, until they see what you’ve done, then they know exactly what they want, but it’s not what you did.” – Brian Sooy Read Mr. Sooy’s entire blog post.  I’m not a designer, but having spent most of the past 10 years working with them to build database-driven websites and applications, I definitely agree with him.  My most recent project (an extranet for the nation’s AMBER Alert coordinators) didn’t launch until 6 months after its originally scheduled launch date in large part because of the client’s uncertainty over what they wanted.


Community Server 2.0 Patching

Telligent sent out an e-mail last Friday afternoon about a critical security patch. These were the patch instructions:

Directions for installing the patch:
These are the contents of the readme.txt file:
Steps for installing the Community Server 2.0 SP1 Patch.

1. Make a copy of the CommunityServer.Components.dll found in the bin folder of your web site. 2. Replace the existing CommunityServer.Components.dll with the new one you just downloaded and unzipped.

If you have questions or problems, please email support@telligent.com

We have also included the updated source files. If you have modified any of the code in the Community Server Components project you will need to apply these fixes and redeploy your assemblies.

I wish the readme file had said exactly where the updated source files go. I don't like the idea of having to hunt around files to replace when the patch has to do with security. So here's what the readme file should include:
ComponentsHttpModuleCSHttpModule.cs

ComponentsComponentsHtmlScrubber.cs

ComponentsComponentsTransforms.cs

Telligent has an announcements blog with a post about this security patch.

Paging in Microsoft SQL Server stored procedures

Today I found out that an old boss of mine at Ciena Corporation has a blog (thanks to Plaxo).   I learned a lot about  ASP.NET, C#, and Plumtree through the work he assigned to me.  From looking at the posts he’s got in there so far, if you’re looking to overclock a PC or find out more about Vista, it’s worth checking out. An older post of his has a good example of how to implement paging in a SQL Server stored procedure.


IntelliSense for SQL Query Analyzer

Red Gate Software is giving away a tool called SQL Prompt until September 1, 2006.  If you work with SQL Server at all, definitely visit Red Gate and grab this.


Amazon "1-Click" Patent Challenge

According to this article, Amazon’s patent is being reviewed because it looks like the U.S. Patent & Trademark Office granted a similar one 18 months before Amazon’s filing.  It will be interesting to see what fallout there would be from a decision invalidating Amazon’s patent.

That aside, this brief story does a nice job of pointing out how profoundly broken the patent system is.  The prior patent wasn’t found by a USPTO employee, but an actor from New Zealand who was angry about a slow book delivery and wanted to get back at Amazon.  If Amazon hadn’t made one of their customers upset, who knows if this would have ever been found.  The patent review will probably revisit these requirements:

  • is 1-click new
  • is 1-click useful
  • is 1-click nonobvious
At the time Amazon got the patent, I felt it clearly failed the nonobvious requirement.  The existence of an 18-month-old patent on the same idea only confirms that.

Stored Procedures vs. Ad-hoc SQL

I saw this insightful article on the subject in a “most popular articles” list. The author, Douglas Reilly, acknowledges at the beginning of the article that he uses stored procedures virtually all the time, but still does a great job of describing the pros and cons of each approach.

The most useful thing the article taught me was that as of version 7, SQL Server keeps execution plans for all statements, not just stored procedures. This reduces the advantage of stored procedures for basic CRUD (create, read, update, delete) operations substantially. I’ve certainly touted the superior performance argument in comparing stored procedures to ad-hoc SQL before, so I’m glad I learned the real deal now. That said, I still hold a bias in favor of stored procedures. Once upon a time, I worked for Sybase Professional Services as a DBA, and they were definitely pro-stored procedure. Nearly every shop I’ve worked in since then has been similarly inclined. Anytime an employer has used ad-hoc SQL, it’s been absolute murder to maintain. In my experience, the maintenance advantage of stored procedures over ad-hoc SQL is substantial, not slight (as Reilly concludes).

One issue the article doesn’t bring up that might be interesting is source code control for stored procedures and other database elements (views, user-defined functions, etc). While SQL Server does have backup and restore, it’s not nearly as granular or convenient as the check-in/check-out model of today’s source code control systems. On my projects, I tend to generate a script with just the stored procedures in it and store that in SourceSafe. I’d certainly like a better solution, but haven’t found one yet. I’m curious to see what SQL Server 2005 is like, since it will allow you to write stored procedures in C# or VB.NET.