Save me unwanted drawers published.
If you want to place a small piece of potentially used code in a shared library, this library needs a good organizing principle. More importantly, it needs a good name that clearly indicates what is there and what should not be included. Do not create a dump that is nothing more than the material you have decided to extract. Gather things that have a good reason to be together.
I'm afraid you are following DRY's dead brain shape. This bad habit forces you to go through the code base to find a similar code without considering if duplication exists for a good reason.
DRY encourages you not to release a design decision by copying and sticking lazily. But he never asked you to make sure that no single line of code looks alike. Duplication is more appropriate when it represents a different idea, which could change independently, which simply looks the same.
If you carefully consider that when you target code for extraction, I am always with you.
However, the main engineers seem to think that we should not encapsulate such code fragments consisting of only two or three lines in the tool methods.
I must disagree with that. Small methods with good names are a gift from God.
Instead, it would be best to place the respective code where it is executed. They argue that the code is "clearer" this way, because when reading the code, you do not have to come and go between the methods.
This complaint is a valid concern. This seems to worry that you will take them to a festival of jumps when they read the code. You could do it even if you chose a code that should really be extracted.
To avoid this, you must use good names, a good abstraction and a proven code. Do this and they will not look inside your method. They will trust it as they do
Console.WriteLine("Hello World!");. Make them look inside again and again and of course, they will hate it.
A good name means that when they look inside, they will find what they expect. A good abstraction means that it works as they expect it. Looking inside and looking at documentation should not teach them anything they did not expect.
Do this and there will be no going back and forth between the methods. They will know what you mean when you call it.
So now the question is, is that
DeleteByColumn(conn, "students", "grade", "F"); at the height of that?
I must confess that I had to look inside this method before feeling like I understood what she was doing. I only guess that I use it correctly. But I think
DeleteByColumn() is a name that I could get used to.
Keep in mind that any library in which you put this should focus on the kinds of things it focuses on. I would tend to create a persistence adapter where I would dump logic that knows how to talk to the database so that the rest of the application does not have to know it.
If you've found, let's say, frequently used string manipulation code that has nothing to do with the database, I would not group it with that.
A shared library is a significant term that often extends between applications. If you propose that this code is ready to be used, keep in mind that you bite a lot. If you want to write a DB Access Library, you are facing guys like this: JOOQ. It's a lot to live.
It is much easier to create a code for your application rather than for each application. With a database adapter, you only hook up the features that your application really needs. No need to be everything for every database user. Reusability is a good idea but do not kill yourself by creating things that no one has asked for. Do not forget that your application may change. Be ready to change.
Show that you are ready to temper your plans so that it does not seem like you are rewriting because it's easier than reading that your team can be more welcoming towards your changes. If they are not, here is my advice:
It's perfectly fine to help you, when you try to understand the code, by extracting the code into small functions to push out the curious details so that you can see what's really going on at a glance. I do it all the time. Sometimes, after sitting with someone, I discover that what I have created is good enough to keep it. Sometimes no. When that is not the case, I do not record it. I throw it in my personal garbage drawer.