How to find the right balance between “fast and dirty” and “good and general” code?

This is not a direct programming issue, but a little help from the developer community will be appreciated.

I suffer from excessive illness. I cannot stop wasting precious time making my code the most general and abstract. I might as well call it a tool / library disease. I tend to turn every programming task into a common problem and try to “write a toolbox” that will work for many such problems.

I know that it’s good overall, if there is enough time, but sometimes I have to write a quick prototype and just can't write fast and dirty code that just works for a special case. I am often enthusiastic about the idea that makes the code more general and customizable by the user and understands the time required to implement it in this way.

Does anyone else have that kind of experience? How can I force myself to find the right balance between a quick hack and a good solution?

+4
source share
7 answers

The development under test (called TDD) can be a useful counterweight to overkill for generality - it instills practice, to quote a Wikipedia entry that I just pointed out,

It is important that the written code is intended only for passing the test; no further (and therefore untested) functionality should be predicted and "allowed" at any stage.

Once you practice it strictly for a while (best of all, if possible, in pair programming, where partners reinforce each other to follow the rules!), You can move on to this.

This is the usual learning cycle: shu, “save”, where you practice one technique until you master it; ha, "separate" where you balance methods with each other; and finally ri, "transcend", where you go beyond such explicit learning, mastering and assimilating all this - it works just as well for programming as it does for No theater, for which it was originally conceived (most people in the West , familiar with the concept of shu-ha-ri, probably met him in the context of martial arts, but, historically, this was already a huge extension of the original ;-).

+4
source

I do it too. But when I came to use the reuse of my "generic" code, I usually think that this is not quite what I need in a new situation.

These days I try to wait until I have done something a couple of times before thinking about how to generalize it. So I have a better idea of ​​the real use cases that I should consider.

The question also reminds me of a quote from Charles Moore to this blog post . Each time you redefine something, you learn more about it, and you improve your implementation. You may have to invent the wheel several times before applying your implementation to the library.

+4
source

Write fast and dirty and check if it works, refactoring, until you are ashamed of the code.

+3
source

Get to know your deadlines. And if you have no deadlines, create your own.

Programmers do not work in a vacuum; they are there to serve the business most of the time.

Usually I get a quick delivery solution, then when I have time, I start the process of cleaning it (so as not to disrupt functionality. The last good version in the deadline is the version for delivery.

Believe me, the first pair of boots in the rear or other poor performance ratings will teach you the importance of this :-)

+3
source

Working code is better than well-designed but not working code. Even the roughest implementation is much better than what doesn't work or even isn't finished.

It is easier to make refactoring and structural improvements from the prototype / quick and dirty implementation, since there is a working link for testing.

As others have written, TDD is very useful because without proper tests it is very difficult to succeed with any refactoring project.

But finally, it is very important to separate the generalization in the problem area in which your program works, and the generalization in the entire domain of calculations.

Very often, projects end with the development of solutions for data structures, algorithms, network protocols, etc. instead of using existing implementations / libraries.

I have seen numerous examples where programmers implement their own hashmaps, http implementations, etc. instead of using existing ones. Sometimes, there might not be compatibility between the library and the application, but then the facade template could be used to encapsulate the use of an external library.

+2
source

This, I think, is a problem that many programmers face. That's why we need project managers who understand business. Unfortunately, we work in an environment that is not purely academic. Therefore, the work that we do is useful only if it timely meets the requirements of the business.

You must find the right balance between executing the code on the “right” and the actual provision of working software.

0
source

The best answer I've always found is how long does the code last? You don't have to write an entire structure, just make sure it is supported.

0
source

Source: https://habr.com/ru/post/1307277/


All Articles