Replies: 8 comments 27 replies
-
This is a real example:
Is it possible for us to convert it to:
|
Beta Was this translation helpful? Give feedback.
-
An abstract class with a virtual method? |
Beta Was this translation helpful? Give feedback.
-
First of all, would saving these few characters really help you there? This real example of yours is just showing that the boilerplate is 1/15 of code written. Just make a template then ctrl-c ctrl-v and you win. How do you declare what type it is in a file? Top level file implicitly assumes it is a Program.Main. You can't just implicitly assume something like this for an arbitrary class What if there is a second method? What if method is changed to be generic? |
Beta Was this translation helpful? Give feedback.
-
@En3Tho, those what if statements are all valid. Yet for this very specific case, we know that we won't get there. We have written a lot of ETL solutions and for each over a couple of iterations we have come to this design. A simple Import method with something near 20 up to 50 lines of code in it. That's why we ask. It's not just "1/15". It's also a lot of indentations. That's another point. |
Beta Was this translation helpful? Give feedback.
-
@En3Tho, I thought of CSharp scripts. But I don't know how to reuse methods there. Maybe we can define some global methods. Instead of inheritance, we can have a lot of global static methods. |
Beta Was this translation helpful? Give feedback.
-
I understand what you're trying to achieve, but based on the code you shared, there might be several alternative solutions that don’t necessarily involve C#. Sometimes insisting on a C# solution can limit the possibilities. In my opinion exploring other approaches could potentially offer better ways to solve the problem, e.g., Create a PowerShell module that exports some of the infrastructure methods to run the queries or whatever and make an 'PowerShellImporter' that basically loads the PowerShell environment and execute these files, then you would be dealing only with the variations. |
Beta Was this translation helpful? Give feedback.
-
Another part of our application that is exactly like this one, is our Migration engine. Basically, our developers write code like this:
So, a migratory code is just a single class, inside a single file, with a single method called So wouldn't it be nicer if we could simply write the body without the boilerplate?
|
Beta Was this translation helpful? Give feedback.
-
I think blazor's grammar is good. Let's introduce a template file again.
|
Beta Was this translation helpful? Give feedback.
-
I'm writing an ETL solution. It has hundreds of small ETL classes.
And basically, the content of each file follows this formula:
Is there a way for us to just write the
// ETL code for this X
and commit those 6 lines of boilerplate? Something similar to the top-level statements, but for all of these files.Beta Was this translation helpful? Give feedback.
All reactions