The Good and Bad of Partial Classes in VB.NET

Ok, first off, let me thank whoever decided to implement Partial Classes in VB.NET. You Rock!!

Ok, now… (for those of you who are new here) Partial classes are incredibly cool and allow developers to work in the same class without having an exclusive lock on a file that others need. We all know how painful SourceSafe is, and partial classes go a long way to alleviate this pain. I can’t tell you how many times a day I have a file checked out that someone else needs to get into, or vice versa. Thanks to Partial Classes, if you split your class code up into multiple files, this won’t be a problem (or at least as much of one.)

That’s the good side. Now for the dark side of Partial Classes, and it’s a doozy!! If you are doing Partial Classes in VB.NET, the Partial keyword is not required.

…dramatic pause while this sinks in…

Did I hear someone say “So What?”

I’ll give you “So What” buddy… it goes like this: C# requires the PARTIAL keyword. Without it, nobody can add a second file to your class. All declarations of the class must have the PARTIAL keyword. VB.NET, on the other hand, does NOT require the PARTIAL keyword. That means any doofus can come along and add code to your class without you even knowing it.

Ok, yes… this doofus would have to have access to your source code, and that means there are a million other ways he can hurt you if he was so inclined, but think about it… This joker can add a partial class file that attaches to your class, without adding any code to your original class file and you might never know why all of a sudden LOTS AND LOTS of code stops working, because this moron decides to override a function that does something important.

So I have to ask… WHY in the world would you make C# require it and not VB.NET? It should be required no matter what language you are working in. As much as I hate to say it, C# wins this round.

Tinggalkan komentar