Lambda the Ultimate

inactiveTopic Partial Types in C#
started 7/11/2003; 10:13:04 AM - last post 7/15/2003; 7:47:10 AM
Chris Rathman - Partial Types in C#  blueArrow
7/11/2003; 10:13:04 AM (reads: 2244, responses: 7)
Partial Types in C#
Partial Types were mentioned in a previous post. Can't say that I find the feature appealing - I think the enforced style of a single source file was a good thing in Java.

Be nicer if they borrowed the Category concept from Objective-C, allowing one to add methods to classes that you don't have source for - such as the base libraries. Problem with the proposed C# extension is that both parts of the class definition require the use of the Partial keyword. No way to add methods to a class that is not considerate enuf to allow extension.
Posted to OOP by Chris Rathman on 7/11/03; 10:14:05 AM

Tim Sweeney - Re: Partial Types in C#  blueArrow
7/11/2003; 10:47:56 AM (reads: 1116, responses: 0)
Gee, everyone hates the way our UI builder works by auto-generating a pile of messy code whenever you move controls around a form (unlike Visual Basic, and Delphi, and ...). I know, instead of fixing the problem, let's further obfuscate it by adding a bizarre new language feature that breaks well-known principles of encapsulation!

Isaac Gouy - Re: Partial Types in C#  blueArrow
7/11/2003; 11:32:36 AM (reads: 1089, responses: 0)
bizarre new language feature that breaks well-known principles of encapsulation!
Hmmmm I hadn't supposed that encapsulation was necessarily defined in terms of source-files.

I thought it was something to do with classes (which in Smalltalk wouldn't mean source-files) or perhaps modules (which in Ada and Modula-2 would mean 2 source-files, in Oberon-2 a single source file) or maybe even components.

In Nice, a multi-method OO language, methods can be declared in a different part of the source-file, or in a different source-file, than the class definition. The method implementation can be in yet-another source-file. (As this is the normal behaviour in Nice, there's no need for a partial keyword, and the compiler has no difficulty detecting that there's a missing method declaration and/or implementation.)

Paul Snively - Re: Partial Types in C#  blueArrow
7/11/2003; 2:04:53 PM (reads: 1074, responses: 0)
Isacc Gouy: Hmmmm I hadn't supposed that encapsulation was necessarily defined in terms of source-files.

It's true, even if largely as an accident of history. Very often, a "compilation unit" was mapped, in practice, to a source file, and that was known to be a legitimate scope. Nowadays, of course, you often have to indicate that that's the scope that you want using a keyword such as "static." But even that doesn't alter the fact that it's a legitimate scope.

I'm not surprised by this move on Microsoft's part; their design philosophy has ignored information hiding for years. I recall being shocked to my core by all of the public data members in MFC, for example. I've seen no evidence to suggest that their architectural perspective has changed since then.

Isaac Gouy - Re: Partial Types in C#  blueArrow
7/11/2003; 3:51:28 PM (reads: 1049, responses: 0)
I went back and put necessarily in bold ;-)

even that doesn't alter the fact that it's a legitimate scope
Sure - if that's what the language defines it to be.

And there are languages that by design allow methods of a class to be defined across multiple source files:

MultiJava: Modular Open Classes and Symmetric Multiple Dispatch for Java
"The open class feature of MultiJava allows a programmer to add new methods to existing classes without modifying existing code and without breaking the encapsulation properties of Java."

The Nice programming language
"Modularity
In object-oriented languages, it is possible to add a new class to an existing class hierarchy. In Nice, it is also possible to add methods to existing classes without modifying their source file."

Advantages of Dylan
"Behavior can be added to existing classes without subclassing or modifying the source code of those classes. Access to the source code is not even required. This is a direct result of the generic function object model."

If it's a good thing in "advanced" "research" languages then shouldn't it still be a good thing when Microsoft take it mainstream? (Shouldn't the complaint really be about the way it's being implemented?)

Chris Rathman - Re: Partial Types in C#  blueArrow
7/11/2003; 7:44:33 PM (reads: 1018, responses: 0)
MultiJava is in the mold of AOP where you want to isolate cross-cutting concerns into a common file. Dylan's multimethods are really about the interactions between more than the single class instance. Don't know enuf about Nice to know the motivation for their extension (though I can imagine some form of Genericity/Template where the file can be used for a specific instantatiation for a class).

Anyhow, the main thing about MultiJava and Dylan is that the methods involve more than a single class (the Visitor pattern is meant to apply a method to a range of classes - class of classes?). So it makes sense in those instances to remove the common code and place it within a single (if external) file.

The partial class extension, however, seems to only involve a single class. You can't re-use the same partial code across multiple classes. In the end, it just sounds like a convenience mechanism to allow a single class to be split into more than one file. Sounds more like they need a better code inclusion mechanism (ala Sather) rather than what amounts to a recipe to reintroduce the complexities of Make (though Ant has become indispensible in the Java world so it probably is an irrelevant point).

Isaac Gouy - Re: Partial Types in C#  blueArrow
7/12/2003; 4:20:21 PM (reads: 955, responses: 0)
it just sounds like a convenience mechanism
That's what Microsoft state:

Host: Anders (Microsoft) Q: What's the aim of partial types in C#?

A: Two reasons. First, people often ask us for include files. When we dig a little deeper, it turns out they want to split large classes into multiple files. Partial types will allow you to do that, but in a structured fashion. Second, partial classes solve the “round trip” problem with auto generated code. The code generator can create one file and the user’s additions can be placed in another file. When code is regenerated, the user’s changes aren’t lost.

I agree that the mechanisms in MultiJava, Nice and Dylan provide much much more than C# partial classes.
I don't see that splitting a class's methods across multiple source-files is a novel departure for a programming language or that it breaks class encapsulation.

Must be that Source code in files? How quaint! thang ;-)

Patrick Logan - Re: Partial Types in C#  blueArrow
7/15/2003; 7:47:10 AM (reads: 863, responses: 0)
This sounds interesting, but it also sounds like a form of "delegation" which is easy to experiment with using a dynamic language like Smalltalk, Lisp, etc. (Lieberman, 1986)

The problem I have is with languages that are so difficult to extend that they force one primary solution to a problem without enough experimentation and publication beforehand.