Blogus Maximus

Rubbing people the wrong way since 1970...

  Home  |   Contact  |   Syndication    |   Login
  1366 Posts | 10 Stories | 2226 Comments | 1336 Trackbacks

News


Google My Blog

Catch me at: The List!


My InstallScript Utility Belt My Amazon Wishlist
My Standard Disclaimer

Tag Cloud


Archives

Post Categories

Image Galleries

Blogs

Code Camps

CTown Geeks

Geeky Webcomics

High Geek

Magenic Blogs

Microsoft Blogs

My Articles

My Sites

PodCasts

UG

XNA

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.

posted on Friday, October 14, 2005 8:11 AM

Feedback

# re: the good and bad of Partial Classes in VB.NET 10/15/2005 3:41 PM Scott Allen
The good news is the partial definitions have to be inside the same assembly. If somone is going to break your code by sneaking in a partial class definition to augment the class, at least they must be in the same office and easily reachable with a wooden bat :)

# re: the good and bad of Partial Classes in VB.NET 10/15/2005 5:18 PM Chris Williams
Believe it or not, I used to have a bat in my cube at a former job. (Hmmm, I don't think that's why it's a former job...)

# re: the good and bad of Partial Classes in VB.NET 7/7/2006 12:34 PM Jerry Robinson
Since when does someone have to be in the same office to have access to an assembly? Bottom line the Partial keyword should be required. Microsoft screwed up on this one!

# re: the good and bad of Partial Classes in VB.NET 9/29/2006 4:07 AM sarika
wanted to design classes for an inventory control system

# re: the good and bad of Partial Classes in VB.NET 1/7/2009 10:42 AM Chris
I also find it strange why they would implement it on C# and not on VB.NET (i.e. syntax strictness), why they would decide to make them different is beyond me. Could you give some more example of how partial classes can be used? I use Sourcesafe here at work and it allows people to make multiple checkouts on the same file and can merge them when the people are finished editing.

Could you give a few more examples as I can't really get my head round it, is their anymore benefits to using partial classes?

# re: the good and bad of Partial Classes in VB.NET 3/16/2010 2:37 PM Demtron
Just found this blog as I was searching for pros/cons of using partial classes as I am having a discussion of the same with another developer. I am advocating not using partial classes as I don't think the separation is important for the project, but I realize it's a coding style issue as well as a code organization issue.

To complicate matters more, partial methods are now a part of VS 2008.

# re: the good and bad of Partial Classes in VB.NET 8/24/2010 2:43 PM Geoff Gunter
One big pro I've found for using partial classes is when part of the class is being dynamically generated.

Say you have classes based on tables in a database that are regenerated every time the database schema changes, but you also have properties or methods that you want to add that are not a part of the generated code from the database. The automated code generator may not be smart enough to leave your custom code alone.

I use this all the time with LINQ to SQL data classes or with Entity Framework.

Post A Comment
Title:
Name:
Email:
Comment:
Verification: