www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Split D class file

reply B.Schulte <Aldioric gmx.de> writes:
Hi!

Is it somehow possible to store some methods of a class in another D file? The
class is really getting too big.

Well, maybe some of you suggest me to split the class in multiple ones, but
this class is important to be one part. The only way would be to have many many
friend classes. But that's also very strange.
Sep 22 2007
next sibling parent reply BLS <nanali nospam-wanadoo.fr> writes:
B.Schulte schrieb:
 Hi!
 
 Is it somehow possible to store some methods of a class in another D file? The
class is really getting too big.
 
 Well, maybe some of you suggest me to split the class in multiple ones, but
this class is important to be one part. The only way would be to have many many
friend classes. But that's also very strange.
... answering without thinking too much... probabely Mixin templates. Bjoern
Sep 22 2007
parent reply redsea <redsea gmail.com> writes:
code coverage report can not support mixin template :(

BLS Wrote:

 B.Schulte schrieb:
 Hi!
 
 Is it somehow possible to store some methods of a class in another D file? The
class is really getting too big.
 
 Well, maybe some of you suggest me to split the class in multiple ones, but
this class is important to be one part. The only way would be to have many many
friend classes. But that's also very strange.
... answering without thinking too much... probabely Mixin templates. Bjoern
Sep 22 2007
parent BLS <nanali nospam-wanadoo.fr> writes:
redsea schrieb:
 code coverage report can not support mixin template :(
Well that's not a big deal IMO. In case that it is "mission critical" write adequate intermediate functions instead. Or do I miss something ?
 
 BLS Wrote:
 
 B.Schulte schrieb:
 Hi!

 Is it somehow possible to store some methods of a class in another D file? The
class is really getting too big.

 Well, maybe some of you suggest me to split the class in multiple ones, but
this class is important to be one part. The only way would be to have many many
friend classes. But that's also very strange.
... answering without thinking too much... probabely Mixin templates. Bjoern
Sep 23 2007
prev sibling next sibling parent reply Jari-Matti =?ISO-8859-1?Q?M=E4kel=E4?= <jmjmak utu.fi.invalid> writes:
B.Schulte wrote:

 Hi!
 
 Is it somehow possible to store some methods of a class in another D file?
 The class is really getting too big.
 
 Well, maybe some of you suggest me to split the class in multiple ones,
 but this class is important to be one part. The only way would be to have
 many many friend classes. But that's also very strange.
Inheritance, composition and mixins are quite common design patterns in OO languages. D also has hybrid member/free functions. If none of those help, you probably have a major problem in the program design.
Sep 23 2007
parent BLS <nanali nospam-wanadoo.fr> writes:
Jari-Matti Mäkelä schrieb:
 B.Schulte wrote:
 
 Hi!

 Is it somehow possible to store some methods of a class in another D file?
 The class is really getting too big.

 Well, maybe some of you suggest me to split the class in multiple ones,
 but this class is important to be one part. The only way would be to have
 many many friend classes. But that's also very strange.
Inheritance, composition and mixins are quite common design patterns in OO languages. D also has hybrid member/free functions.
If none of those help,
 you probably have a major problem in the program design.
Was my first idea too. Means having a fat class is more an design issue than an language related prob. But since I am going to translate a MFC like GUI using a lot of GDI wrapper functions I am not that sure. ;-) Bjoern....
Sep 23 2007
prev sibling next sibling parent reply Robert Fraser <fraserofthenight gmail.com> writes:
redsea Wrote:

 code coverage report can not support mixin template :(
I'll need to see how the code coverage ABI works, but it might be more than possible that code coverage for those lines are tracked but there's no way to display it. If that's the case, some IDE might someday be able to expand the templates inline and ho coverage, or alternatively aggregate this data and show coverage for an entire template (and maybe use pretty colored lines to do so if you ask nice). "someday" being the keyword.
Sep 23 2007
parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"Robert Fraser" <fraserofthenight gmail.com> wrote in message 
news:fd6odt$14qt$1 digitalmars.com...
 redsea Wrote:

 code coverage report can not support mixin template :(
I'll need to see how the code coverage ABI works, but it might be more than possible that code coverage for those lines are tracked but there's no way to display it. If that's the case, some IDE might someday be able to expand the templates inline and ho coverage, or alternatively aggregate this data and show coverage for an entire template (and maybe use pretty colored lines to do so if you ask nice). "someday" being the keyword.
It keeps what amounts to a large static array of ints (longs?), and inserts an "inc [address of counter that corresponds to this line]" instruction after each line of functional code. To that end, it'd have to keep track of every instantiation of a template, be it mixed in or whatever, and count all those instantiations' lines separately. It'd probably also have to indicate which instantiation of the template each line count was for.
Sep 23 2007
parent reply Robert Fraser <fraserofthenight gmail.com> writes:
Jarrett Billingsley Wrote:

 "Robert Fraser" <fraserofthenight gmail.com> wrote in message 
 news:fd6odt$14qt$1 digitalmars.com...
 redsea Wrote:

 code coverage report can not support mixin template :(
I'll need to see how the code coverage ABI works, but it might be more than possible that code coverage for those lines are tracked but there's no way to display it. If that's the case, some IDE might someday be able to expand the templates inline and ho coverage, or alternatively aggregate this data and show coverage for an entire template (and maybe use pretty colored lines to do so if you ask nice). "someday" being the keyword.
It keeps what amounts to a large static array of ints (longs?), and inserts an "inc [address of counter that corresponds to this line]" instruction after each line of functional code. To that end, it'd have to keep track of every instantiation of a template, be it mixed in or whatever, and count all those instantiations' lines separately. It'd probably also have to indicate which instantiation of the template each line count was for.
I _was_ assuming it already did these things, but now I'm assuming not...
Sep 23 2007
parent "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"Robert Fraser" <fraserofthenight gmail.com> wrote in message 
news:fd6osr$15j1$1 digitalmars.com...
 I _was_ assuming it already did these things, but now I'm assuming not...
Don't know about all possible cases, but a simple test using a templated function shows that it collapses the counts for all instantiations of the template into one. So if you call three separate specializations of the templated function, it'll show (in the listing) the templated function having been called three times, instead of splitting up the specializations.
Sep 23 2007
prev sibling next sibling parent Chad J <gamerChad _spamIsBad_gmail.com> writes:
B.Schulte wrote:
 Hi!
 
 Is it somehow possible to store some methods of a class in another D file? The
class is really getting too big.
 
 Well, maybe some of you suggest me to split the class in multiple ones, but
this class is important to be one part. The only way would be to have many many
friend classes. But that's also very strange.
Just to make sure it's clear, here's how it's done with mixins: // file 1, main.d or whatever import std.stdio; import second; void main() { Big biggy = new Big(); } class Big { this() { writefln(getDescription()); } mixin BigPeice!(); // getDescription() ends up defined here. } // file 2, second.d template BigPeice() { char[] getDescription() { return "Big is a hypothetically very big class and must be split."; } }
Sep 23 2007
prev sibling parent =?ISO-8859-1?Q?Julio_C=E9sar_Carrascal_Urquijo?= writes:
Hi

B.Schulte wrote:
 Hi!
 
 Is it somehow possible to store some methods of a class in another D file? The
class is really getting too big.
 
 Well, maybe some of you suggest me to split the class in multiple ones, but
this class is important to be one part. The only way would be to have many many
friend classes. But that's also very strange.
I think you need Partial Class Definition. It has been requested before but hasn't got much traction: http://www.digitalmars.com/d/archives/digitalmars/D/14513.html http://www.digitalmars.com/d/archives/digitalmars/D/Partial_class_implementation_55745.html I think it's a very useful feature for external code generators. For example: * GUI code generated by a form designer stored in a Form.designer.d file. * Record structures generated from official specs (Something I've wonders). * Model classes generated from a Database Schema. Very useful when the schema changes and you have to update your database. * etc... I would really love to hear how difficult it would be to implement on DMD or GDC because I really have no idea. Adding it to the language is another matter. Cheers. -- Julio César Carrascal Urquijo http://jcesar.totumo.net/
Sep 24 2007