Too Many Methods!!!

  • Thread starter Thread starter Sean
  • Start date Start date
S

Sean

with C++, I declare several functions in a class in a header file,
and I implement in several source files(cpp), then I compile it.

but how can I such thing with C#?
If I have to implement 100 methods in a class, do I write all in a cs file?

what I should do?
 
If you wanna implement 100 methods in one class, you probably have to
reconsider your design.
With an OO approach, it is highly unusual that you have 100 methods in one
class.
However, in the next release partial classes will be suported, so you can
spread them over multiple .cs files. For now, you'll have to use 1 file.

Greetz,
-- Rob.
 
Writing C code in C++? Why not refactor your methods into different classes?

So that rather than having one mega class, you have more specific
classes and methods.

regards,
Abhishek.
 
What would be the benifit of Lambada funtions (Anonymous methods)? Isnt
there a risk of making code potentially a mess?

Sure we dont have to use them but hmmm. Partial types, is nice for code
management flexability, but not critical, if you need to give out stuff,
make it into a resource DLL and ship that for localisation etc. hmmm give
out header files? Why not just documentation :D XML auto docs in .NET.
Template classes, long awaited.

Question is, what benifits does MC++ offer over C# now outside the field of
interop and existing code in c++ for porting?

Where does C# lack that MC++ succeeds? (appart from interop and existing
code needing ported, and skillset on C++).
 
JackMeyhoff said:
What would be the benifit of Lambada funtions (Anonymous methods)? Isnt
there a risk of making code potentially a mess?

They're useful for small event handler methods or delegate
implementations. But I agree, you could make a strong case for
why they're not necessary and how they just clutter things up.

Look at some source from an app using Java Swing and you'll
see what I mean.
Sure we dont have to use them but hmmm. Partial types, is nice for code
management flexability, but not critical, if you need to give out stuff,
make it into a resource DLL and ship that for localisation etc. hmmm give
out header files? Why not just documentation :D XML auto docs in .NET.
Template classes, long awaited.

As far as partial types, I'm still not sure why this is necessary.

If you have a class that's large enough to break into multiple
files, you're probably doing something wrong.

And who wants to maintain a class that large and having to deal
with that many files?
Question is, what benifits does MC++ offer over C# now outside the field of
interop and existing code in c++ for porting?

Where does C# lack that MC++ succeeds? (appart from interop and existing
code needing ported, and skillset on C++).

Good question, I haven't come up with an answer for that yet :)

-c
 
If you have a class that's large enough to break into multiple
files, you're probably doing something wrong.

Unless the class was generated by some sort of cross-language translator...
And who wants to maintain a class that large and having to deal
with that many files?

Exactly. Let's say your program was originally written in language X and
that you by far prefer to maintain the program in language X. For
marketing/speed/interoperatbility reasons you need your application to
become a .NET assembly and language X doesn't have a .NET implementation.
But you are a smart coder and realise that it's possible to hack together a
simple but effective compiler from language X to C# which, with the aid of a
runtime library, will give you what you need. Your original language is
based on functions and not classes, though, and there's no simple way to
automate the separation in classes of your hundred (thousands?) of
functions. Now you have a C# monolithic class with hundreds of methods.
Nobody maintains it. It just needs to work...
 
does MC++ have the same perf as C# as it is in the same runtime?

Would the same code made in MC++ and C# produce the same or quite similar
MSIL?
 
Yes, the performance is about the same, as the compilers produce about the
same IL that is executed.
The difference between the two won't be much, if at all there is a
difference.

Greetz,
-- Rob.
 
Hi,

Rob Tillie said:
If you wanna implement 100 methods in one class, you probably have to
reconsider your design.
With an OO approach, it is highly unusual that you have 100 methods in one
class.

True in most cases, but not always:
int qty = typeof(Convert).GetMembers().Length; // 312

qty = typeof(DataGrid).GetMembers().Length; //230

and there most be others like those!!!
However, in the next release partial classes will be suported, so you can
spread them over multiple .cs files. For now, you'll have to use 1 file.

What I do when I have a class with a lot of members either public or not is
using regions, I know that this is a VS.NET feature but it's a GREAT help
on big classes ( as those from ASP.NET ) a time ago a thread discussed the
best way to organize a class, maybe a look at it will be helpful,

Hope this help,
 
The difference between the compiled assembly langage produced by the .NET
JIT complier and the C++ compiler would probably be very similar for similar
code. But the implementation of the .NET framework is much different from
that of the STL or Standard C++ Lib, or the MFC, I imagine. Does anyone know
how the implementation of polymorphism in .NET compares to C#? And C#
generics, when the come along, may be implemented quite differently than C++
templates at an IL level.

Chris
 
Back
Top