473,386 Members | 1,873 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Two questions about "partial classes"


Two question about the "partial classes" (in the next wersion of
..NET).
Question 1
==========
Will partial classes (in the next version of C#) have to be
declared "partial" in ALL places.

I.e. do we have to need to write:

File 1:
public partial class AB {
public int A;
}

File 2:
public partial class AB {
public int B;
}

Or will it be possible to write:

File 1:
public class AB { // Omit "partial" here
public int A;
}

File 2:
public partial class AB {
public int B;
}

Note that in the latter case, it would be possible to extend
ANY class, e.g. the ValueType class:

Some file:
namespace System {
public partial class ValueType {
public double Inverse {
get {
return 1.0/(double)this;
}
}
}
}

which would add an "Inverse" property to the types float, double,
int and so on:

2.Inverse == 0.5
4.0.Inverse == 0.25

It would definitely be nice to have some kind of mechanism that
would make already implemented classes "partial", thus making it
possible to extend them this way.
Question 2
==========
Must the interfaces of partial classes be declared in all places?

I.e. do we have to write:

File 1:
public partial class X: IA, IB, IC, ID {
// Methods of interfaces IA and IB
}

File 2:
public partial class X: IA, IB, IC, ID {
// Methods of interfaces IC and ID
}

Or, will it be possible to write:

File 1:
public partial class X: IA, IB {
// Methods of interfaces IA and IB
}

File 2:
public partial class X: IC, ID {
// Methods of interfaces IC and ID
}

The second way would definitely make implementation easier.
/Gomaw

Nov 15 '05 #1
9 2491
Answers below

--
Eric Gunnerson

Visit the C# product team at http://www.csharp.net
Eric's blog is at http://blogs.gotdotnet.com/ericgu/

This posting is provided "AS IS" with no warranties, and confers no rights.
"Gomaw Beoyr" <Go*********@no.spam.please.no> wrote in message
news:Oz**************@TK2MSFTNGP12.phx.gbl...

Two question about the "partial classes" (in the next wersion of
.NET).
Question 1
==========
Will partial classes (in the next version of C#) have to be
declared "partial" in ALL places.

I.e. do we have to need to write:

File 1:
public partial class AB {
public int A;
}

File 2:
public partial class AB {
public int B;
}

Or will it be possible to write:

File 1:
public class AB { // Omit "partial" here
public int A;
}

File 2:
public partial class AB {
public int B;
}

Note that in the latter case, it would be possible to extend
ANY class, e.g. the ValueType class:

Some file:
namespace System {
public partial class ValueType {
public double Inverse {
get {
return 1.0/(double)this;
}
}
}
}

which would add an "Inverse" property to the types float, double,
int and so on:

2.Inverse == 0.5
4.0.Inverse == 0.25

It would definitely be nice to have some kind of mechanism that
would make already implemented classes "partial", thus making it
possible to extend them this way.
Partial classes are purely a compile-time construct, and all parts of the
class must be marked with partial. They aren't intended to be used to extend
system classes. I haven't thought about this deeply, but my guess is that
there could be some security issues in doing that, along with the problem of
possibly changing system-defined behavior.



Question 2
==========
Must the interfaces of partial classes be declared in all places?

I.e. do we have to write:

File 1:
public partial class X: IA, IB, IC, ID {
// Methods of interfaces IA and IB
}

File 2:
public partial class X: IA, IB, IC, ID {
// Methods of interfaces IC and ID
}

Or, will it be possible to write:

File 1:
public partial class X: IA, IB {
// Methods of interfaces IA and IB
}

File 2:
public partial class X: IC, ID {
// Methods of interfaces IC and ID
}

The second way would definitely make implementation easier.


Interfaces can be declared on any part of the partial class.
Nov 15 '05 #2
Eric,

I know you've said this before, but I still don't
get the point of partial classes. From what I understand,
it's for situations like having Windows Forms designer
code in one file and all your implementation in another.

Is that really that big a of a deal with #region?

It seems you are adding a great deal of complexity
(and therefor potential for great abuse)
with very little return or benefit.

-c

"Eric Gunnerson [MS]" <er****@online.microsoft.com> wrote in message
news:u9*************@TK2MSFTNGP10.phx.gbl...
Answers below

--
Eric Gunnerson

Visit the C# product team at http://www.csharp.net
Eric's blog is at http://blogs.gotdotnet.com/ericgu/

This posting is provided "AS IS" with no warranties, and confers no rights. "Gomaw Beoyr" <Go*********@no.spam.please.no> wrote in message
news:Oz**************@TK2MSFTNGP12.phx.gbl...

Two question about the "partial classes" (in the next wersion of
.NET).
Question 1
==========
Will partial classes (in the next version of C#) have to be
declared "partial" in ALL places.

I.e. do we have to need to write:

File 1:
public partial class AB {
public int A;
}

File 2:
public partial class AB {
public int B;
}

Or will it be possible to write:

File 1:
public class AB { // Omit "partial" here
public int A;
}

File 2:
public partial class AB {
public int B;
}

Note that in the latter case, it would be possible to extend
ANY class, e.g. the ValueType class:

Some file:
namespace System {
public partial class ValueType {
public double Inverse {
get {
return 1.0/(double)this;
}
}
}
}

which would add an "Inverse" property to the types float, double,
int and so on:

2.Inverse == 0.5
4.0.Inverse == 0.25

It would definitely be nice to have some kind of mechanism that
would make already implemented classes "partial", thus making it
possible to extend them this way.
Partial classes are purely a compile-time construct, and all parts of

the class must be marked with partial. They aren't intended to be used to extend system classes. I haven't thought about this deeply, but my guess is that there could be some security issues in doing that, along with the problem of possibly changing system-defined behavior.



Question 2
==========
Must the interfaces of partial classes be declared in all places?

I.e. do we have to write:

File 1:
public partial class X: IA, IB, IC, ID {
// Methods of interfaces IA and IB
}

File 2:
public partial class X: IA, IB, IC, ID {
// Methods of interfaces IC and ID
}

Or, will it be possible to write:

File 1:
public partial class X: IA, IB {
// Methods of interfaces IA and IB
}

File 2:
public partial class X: IC, ID {
// Methods of interfaces IC and ID
}

The second way would definitely make implementation easier.


Interfaces can be declared on any part of the partial class.

Nov 15 '05 #3
I too am not sure if this is a good thing or not, but abuse comes very
commonly with everything(i really hope no one comes up with seriously
abusive ways to use generics, but you know as well as i do that as soon as
they come out publically there will be thousands of classes written with
them that doesn't need them), same as with all new features.
Anyway, in addition to chads comments, the problems this seems to solve
seems like something the IDE should handle more than the compiler.
I have to say, however, that i'd have rather seen an IDE that was capable of
analyzing the file, breaking the regions into virtual subsections(like
having a + in the treeview in solution explorer next to the file that drops
down into sub sections), properly decorated with class information, etc,
allowing for a developer to view the entire class, or subsections in a
virtual manner, without any distracting region labels, etc. without breaking
the files apart. If taken a step further it could potentially allow for far
greater flexibility than partial types would. Althought i'm sure that would
cause an increased amount of implementation complexity in the IDE (possibly
more than partial types adds to the compiler)

In a bit of defense, however, it would allow generators to (re)create entire
files without having to worry about wiping out user code, however why
merging the classes would have a benefit over inheriting from the generated
class is still a mystery to me.
"Chad Myers" <cm****@N0.SP.AM.austin.rr.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Eric,

I know you've said this before, but I still don't
get the point of partial classes. From what I understand,
it's for situations like having Windows Forms designer
code in one file and all your implementation in another.

Is that really that big a of a deal with #region?

It seems you are adding a great deal of complexity
(and therefor potential for great abuse)
with very little return or benefit.

-c

"Eric Gunnerson [MS]" <er****@online.microsoft.com> wrote in message
news:u9*************@TK2MSFTNGP10.phx.gbl...
Answers below

--
Eric Gunnerson

Visit the C# product team at http://www.csharp.net
Eric's blog is at http://blogs.gotdotnet.com/ericgu/

This posting is provided "AS IS" with no warranties, and confers no

rights.
"Gomaw Beoyr" <Go*********@no.spam.please.no> wrote in message
news:Oz**************@TK2MSFTNGP12.phx.gbl...

Two question about the "partial classes" (in the next wersion of
.NET).
Question 1
==========
Will partial classes (in the next version of C#) have to be
declared "partial" in ALL places.

I.e. do we have to need to write:

File 1:
public partial class AB {
public int A;
}

File 2:
public partial class AB {
public int B;
}

Or will it be possible to write:

File 1:
public class AB { // Omit "partial" here
public int A;
}

File 2:
public partial class AB {
public int B;
}

Note that in the latter case, it would be possible to extend
ANY class, e.g. the ValueType class:

Some file:
namespace System {
public partial class ValueType {
public double Inverse {
get {
return 1.0/(double)this;
}
}
}
}

which would add an "Inverse" property to the types float, double,
int and so on:

2.Inverse == 0.5
4.0.Inverse == 0.25

It would definitely be nice to have some kind of mechanism that
would make already implemented classes "partial", thus making it
possible to extend them this way.


Partial classes are purely a compile-time construct, and all parts of

the
class must be marked with partial. They aren't intended to be used to

extend
system classes. I haven't thought about this deeply, but my guess is

that
there could be some security issues in doing that, along with the

problem of
possibly changing system-defined behavior.



Question 2
==========
Must the interfaces of partial classes be declared in all places?

I.e. do we have to write:

File 1:
public partial class X: IA, IB, IC, ID {
// Methods of interfaces IA and IB
}

File 2:
public partial class X: IA, IB, IC, ID {
// Methods of interfaces IC and ID
}

Or, will it be possible to write:

File 1:
public partial class X: IA, IB {
// Methods of interfaces IA and IB
}

File 2:
public partial class X: IC, ID {
// Methods of interfaces IC and ID
}

The second way would definitely make implementation easier.


Interfaces can be declared on any part of the partial class.


Nov 15 '05 #4
Hi Chad,

|| I still don't get the point of partial classes.

Some reasons why I look forward to them:

Regions are useful, but when I have to play clicky-clicky all the
time to hide and reveal it gets to be a real pain.

I can put these-definitely-work methods into one file,
these-are-getting-there into another and work-in-progress in another.
It all cuts down the amount of hunting and scrolling.

Search and replace is easier (more predictable) with a smaller
text base.

In a big class there will be logically distinct sections. I'd be
happier with these in separate files.

In a team situation, two members can work on the same class.

In a team situation, partial class files may be made read-only to
force a developer to pause and consider, or even have to seek
permission.

And I'm sure I've got more reasons waiting to be discovered.

Regards,
Fergus
Nov 15 '05 #5
Hi Daniel,

I like your idea of the Explorer-style code window. Anything that
let's me see what I'm working on and hides the rest is welcome. I even
sometimes resent the single line that a hidden region takes (wastes) -
I'd like some other indicator (small, if not tiny).

But plenty of people don't use the IDE.

Regards,
Fergus
Nov 15 '05 #6
Chad Myers <cm****@N0.SP.AM.austin.rr.com> wrote:
I know you've said this before, but I still don't
get the point of partial classes. From what I understand,
it's for situations like having Windows Forms designer
code in one file and all your implementation in another.

Is that really that big a of a deal with #region?


Absolutely! I've seen a number of classes which are part autogenerated,
part handwritten - and not just GUIs. Keeping the autogenerated parts
of those classes separate means that a change to the autogeneration
process (or whatever) can regenerate the autogenerated part without
disturbing the other part at all. Every change in the handwritten part
of the code is guaranteed to be done by a developer, so it's more
likely to be an interesting part of the history (where some
autogeneration tools might generate subtly different but functionally
equivalent code in multiple runs, eg the order of variables may be
different - that kind of thing isn't worth looking at).

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Nov 15 '05 #7
Jon Skeet <sk***@pobox.com> wrote:
Absolutely! I've seen a number of classes which are part autogenerated,
part handwritten - and not just GUIs. Keeping the autogenerated parts
of those classes separate means that a change to the autogeneration
process (or whatever) can regenerate the autogenerated part without
disturbing the other part at all. Every change in the handwritten part
of the code is guaranteed to be done by a developer, so it's more
likely to be an interesting part of the history (where some
autogeneration tools might generate subtly different but functionally
equivalent code in multiple runs, eg the order of variables may be
different - that kind of thing isn't worth looking at).


I've read two reasons in this thread that make some sense: 1) separating
out auto-generated code and 2) team development on a single class. I
could also understand code size management, but it hasn't been a problem
for me so far, and I suspect that a class that large should probably be
restructured. I'm not sure that any of these are so vitally important as
to require a change in the language.

But I think I am siding with the poster who voiced concern that the
feature will end up being abused, in ways we haven't envisioned. Take as
an example templates in C++. When they were first introduced, we thought
it was a nice way to make generic type-safe containers, and to avoid
having many overloaded functions of the same name (max(), for instance).
Now, C++ templates have grown into a complexity monster. I've used
templates for years, but I look at some of the code in boost or Loki, and
can only say "Huh?". I can't even read the stuff. I don't consider that
progress.

Part of the appeal of our "new" languages such as Java and C# is that
they got rid of the old-school mentality of complexity over usability.
Certainly not as satisfying to the ego, if you need that, but if you want
to write good, clean (and correct) code that both you and others can
understand, they were a great step in the right direction. As we have
seen with C and C++ over many years, abusing a feature cannot be
outlawed. The C preprocessor, templates, pointers and casts -- all
features that can be either used or abused, and which, mostly, are abused
by everyone simply because it's not illegal. It hardly matters that *I*,
as an individual developer, may not abuse them, because I don't work in a
vacuum and am constantly having to interface with code written by others,
including system libraries and SDKs as well as in-house code. And like a
disease, complexity infects everything it touches.

An additional benefit of that simplicity is the rapid growth of
programming aids and tools. Java has been around for a little while now,
and there are all kinds of programming tools that have sprung up. The
language is simple and clear enough that writing a code browser is not a
major undertaking requiring a team of 20 developers. C# is a little more
complex than Java, but still nowhere near C++ in complexity. Heck, I even
wrote a C# parser myself. It was more than an afternoon project on a
rainy day, but I did it. And I would never try writing a C++ parser!

Look: Visual Studio .NET 2002, right out of the gate, had immensely
better Class View and Intellisense than the same features for C++. Fast
and virtually bug-free. Same for the C# compiler. And yet, even in VS.NET
2003, after all these years of development, MS has not been able to get
Class View or the compiler to work correctly for C++ code. That should
tell us something. Will this be C# in 5 years?

I urge Microsoft not to turn C# and .NET into another COM embarrassment.
I know you have directives to churn out new features each year, but
please -- use caution, and focus on usability over complexity!

--
harry
Nov 15 '05 #8
Harry Bosch <no**@given.com> wrote:
I've read two reasons in this thread that make some sense: 1) separating
out auto-generated code and 2) team development on a single class. I
could also understand code size management, but it hasn't been a problem
for me so far, and I suspect that a class that large should probably be
restructured.
Agreed.
I'm not sure that any of these are so vitally important as
to require a change in the language.
It's only a slight (and non-breaking, as I understand it) change, which
at least makes it easier to bear.
But I think I am siding with the poster who voiced concern that the
feature will end up being abused, in ways we haven't envisioned.


Oh I'm certainly *concerned* about that - but not necessarily to the
point of thinking it's a bad idea.

Fortunately, it's a feature which is *very* easily policed - the team
leader can much more easily search for abuses of this (as it should
rarely be used at all) than of things like C++ templates. That's part
of the reason for my tentative support - abuse of it is obvious.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Nov 15 '05 #9
Jon Skeet <sk***@pobox.com> wrote:
It's only a slight (and non-breaking, as I understand it) change,
which at least makes it easier to bear.
Yes, non-breaking would make it agreeable :-) Good point.
Fortunately, it's a feature which is *very* easily policed - the team
leader can much more easily search for abuses of this (as it should
rarely be used at all) than of things like C++ templates. That's part
of the reason for my tentative support - abuse of it is obvious.


Also agreed. I think my rant was more towards language directions in
general, and really really not wanting C# to head in that direction. I
think we're in good shape, however.

--
harry
Nov 15 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: TheLetti | last post by:
Hy! I've just downloaded the latest Java 2 SDK (j2sdk1.4.2_01). For my surprise in this version the servlet-classes are not integrated (e.g. the class javax.servlet). So I found all the...
0
by: jb_in_marietta | last post by:
I have a Dot Net project that references a COM DLL called "Crypto.dll," which is registered on my machine. I added the reference via the "Add Reference" dialog in Visual Studio Dot Net, and I am...
3
by: Phil Sherman | last post by:
What is the relationship between the snapshot elements: Log pages written Number write log IOs Number partial page log IOs There doesn't appear to be any information in my PDF System monitor...
5
by: | last post by:
Hoping someone can help with a simple but puzzling problem. I have some code that I want to build as a class method. The code works fine when I embed it in Page_Load. But when I try to generalize...
1
by: Mitan | last post by:
Hello, I'm a beginner with what appears to be a simple question for which I haven't been able to get an answer. Can someone explain what "implementation code" is in relation to VB.NET? I want to be...
3
by: Giggle Girl | last post by:
I have inherited some CSS from a former employee that has code like this: onmouseover="this.className='highlight_on standard_border'" where it appears to activate two different classes,...
169
by: JohnQ | last post by:
(The "C++ Grammer" thread in comp.lang.c++.moderated prompted this post). It would be more than a little bit nice if C++ was much "cleaner" (less complex) so that it wasn't a major world wide...
0
by: Samuel R. Neff | last post by:
We're migrating our .NET 1.1 web application to .NET 3.5 and during conversion we clicked "Convert to Web Application" on the web project. The results from this conversion were inconsistent. 1. ...
0
by: AAaron123 | last post by:
Some of my partial classes end with "_aspx" and some do not. I made some changes with cut and paste and may have made some mistakes. I do use master pages. Do all partial classes normally...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.