Replies: 9 comments 34 replies
-
I don't really understand your use of inheritance here. Similar to how Channels and Pipes expose distinct Reader/Writer properties, i would consider doing the same here, modeling everything as composition, not a mix of composition and inheritance. Note: to bridge wanting to treat the composed type as either of the composed members, Channels have implicit operators to the respective reading/writing forms. Seems like you could do the same here instead of trying to make this work through inheritance.
Model things differently?
I don't see how. With a few minutes of investment you can have somethign generating all your bridge methods for whenever this comes up. It would keep things up to date for you automatically as well. Seems like a reasonable return on investment. |
Beta Was this translation helpful? Give feedback.
-
That's what I crave. But how? C# does not have composition capabilities. Where are the keywords for that? What is the syntax for that? I would love to be able to create |
Beta Was this translation helpful? Give feedback.
-
I saw some samples of code generation. Can I create a placeholder like below and replace it with the source code? I don't want to create |
Beta Was this translation helpful? Give feedback.
-
As I expected, source generators are a mess. The idea is great. But:
@CyrusNajmabadi, can you please add more details regarding the channels and pipes? I don't understand what you mean. |
Beta Was this translation helpful? Give feedback.
-
Three hours of trying to add a simple line to my code. The most terrible experience a developer can get.
But returning back to the main problem. How can I compose three sets of utility methods for reading flat data, writing flat data, and reading hierarchical data? What would you do to DRY your code? |
Beta Was this translation helpful? Give feedback.
-
Learning how to do something always takes longer the first time. And source generators can be made to be general purpose, something that automatically applies based on the shape of your project or application of custom attributes, so that you only have to write it once. The community can share and reuse their generators: https://github.com/mrpmorris/Morris.Moxy Beyond that, if you want to have a discussion about traits or mixins in the language, feel free to open such a discussion. The trait conversation did evolve into default implementations. |
Beta Was this translation helpful? Give feedback.
-
I made an SG for composition/mixings/traits: |
Beta Was this translation helpful? Give feedback.
-
I don't know what 'below' means here.
Yes.
You'll need partial. It's the feature we've had for almost 20 years to support code Gen.
Yes. Source generators allow you to automatically generate code you would write yourself, while keeping it up to date. |
Beta Was this translation helpful? Give feedback.
-
@CyrusNajmabadi, apparently the Source Generation curve is too high. After almost two days I could not do it. I'm not a junior developer. Thus I consider it to be fairly complex for a composition requirement. This is what I ended up doing. I created a preprocessor (getting the idea from CSS) that runs before we get to MSBuild. I created a simple syntax for inclusion. And I combined it with the idea of partial classes (though a dirty solution IMO). So, I have this file called
Then in my
Then using my preprocessor which is written in Python and in my build pipeline before I call
I tested it and it worked. And it took less than 3 hours to be built. But I felt very bad being rejected by the .NET team and being presented with hard solutions for something that based on my 18 years of coding is absolutely necessary for the future of .NET and C#. I hope your higher-ranking managers see this post. I suffer communicating with the .NET team. If we did not have 63183 lines of code in C# I would definitely consider moving away from it. C# needs to have better composition support. C# lacks composition support. Yes, it might have some workarounds to mimic composition and mixin. Yet those workarounds are expensive, hard to implement and maintain, and hard to learn and communicate with the rest of the team. C# needs first-level keywords to support composition. Thank you all. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have a read business, that only reads data.
And I have a business that both reads and writes data. To DRY, I inherit it from
ReadBusiness<T>
to reuse the read logic:Now I want to support hierarchical structures and mix them with reading and writing. So, I need to have
ReadTreeBusiness
andTreeBusiness
.This
ReadTreeBusiness
adds hierarchical methods for readings, likeGetTree
orGetAncestorsPath
.I inherited it from
ReadBusiness
.The problem arises when I want to create the
TreeBusiness
. I need to have read, write, and read-tree all in it, and add some methods to it. How can I do that? I'm stuck at this point because of the lack of composability support in C#.I have tried many times to persuade the .NET team that we need a clean composition syntax. I don't know where to go from here.
In fact the
TreeBusiness
needs:ReadBusiness
Business
ReadTreeBusiness
CalculateNestedSets
orRemoveChildrenRecursively
What should I do? What options do I have?
HttpContext
there.ReadUtilities
and include it in bothReadBusiness
andReadTreeBusiness
. But then I have to write all of the wrapper methods to expose the methods inside theReadUtilities
.TreeBusiness
file.Beta Was this translation helpful? Give feedback.
All reactions