www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Does anyone think C#'s partial would have any use in D?

reply Dr Machine Code <jckj33 gmail.com> writes:



* When working on large projects, spreading a class over separate 
files enables multiple programmers to work on it at the same time.
* When working with automatically generated source, code can be 
added to the class without having to recreate the source file. 
Visual Studio uses this approach when it creates Windows Forms, 
Web service wrapper code, and so on. You can create code that 
uses these classes without having to modify the file created by 
Visual Studio.
* When using source generators to generate additional 
functionality in a class.
To split a class definition, use the partial keyword modifier, as 
shown here:

source: 
https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/partial-classes-and-methods


think it was mostly implemented to make it easier the Visual 
Studio's code generator. Can't think much of it. But give D 
doesn't have even multiples inheritances, it's unlikely to be 
appreciated but just like to know you all opinions
Dec 18 2021
parent reply Rumbu <rumbu rumbu.ro> writes:
On Sunday, 19 December 2021 at 04:24:30 UTC, Dr Machine Code 
wrote:

 think it was mostly implemented to make it easier the Visual 
 Studio's code generator. Can't think much of it. But give D 
 doesn't have even multiples inheritances, it's unlikely to be 
 appreciated but just like to know you all opinions
I suppose you wanted to say that D will benefit from it. It was already discussed in the past, you can search the forum for it. The conclusion was that metaprogramming capabilities of D are enough to not mandate the use of partial classes. ```csharp partial class C { //generated code } class C { //custom code } ``` can be achieved in D using mixins: ```d class C { mixin!C //generated code //custom code } ``` As a concrete example, you can browse the libdparse source code on github, especially ast.d code where the content of AST nodes is mostly generated by mixins. An external tool like VS should generate the mixin content instead of class content. --- Now back to the principle, partial classes will not work in D, because you cannot place a class in two different modules, their fully qualified name will be different.
Dec 18 2021
parent Dukc <ajieskola gmail.com> writes:
On Sunday, 19 December 2021 at 06:30:08 UTC, Rumbu wrote:
 I suppose you wanted to say that D will benefit from it.

 It was already discussed in the past, you can search the forum 
 for it. The conclusion was that metaprogramming capabilities of 
 D are enough to not mandate the use of partial classes.
often used as namespaces for functions that are not conceptually member functions of anything, and in that case a partial class can make sense. In D, if you have such a large class that it wants more than one file, that is a code smell. Move some of the (non-overridable) member functions out of it, or split it to smaller classes and/or structs.
Dec 19 2021