In my head there are ideas about what and how to write, but there is no understanding how to combine and group it. And so it became interesting who and how is concentrated in the development of + - complex algorithms? How do you divide into a sequence of actions? How do you group?

PS Newbie, I write for myself, wrote a prototype + - a worker and I want to improve.

  • one
    All your thoughts immediately try to code, to obtain the desired result. Naturally, this should be the most readable code for further refactoring. When your algorithm works, you begin to optimize and refine your code. Development via tdd (through writing tests) is also desirable. This will allow you to immediately find problems when refactoring - JVic
  • one
    The question is too general. It is unlikely that you can answer something not in the spirit of KO (like, абстрагируй задачу, разделяй ее на части и повторяй, пока каждое действие не станет очевидно (this approach is also called top-down programming or hierarchical decomposition) or возьми входные данные, представь, во что они должны превратиться и придумай последовательность элементарных шагов, которые сделают такое преобразование ). - avp
  • Look at this book - Levitin, Algorithms: an introduction to the development and analysis. There everything just revolves around how to develop algorithms, and not around ready-made solutions. - Mikhailo

2 answers 2

For the development of the algorithm is not tied to any language. At first I just write down the steps on paper what and how should happen.

Top-down approach. That is, first in large blocks, then I divide each of these large blocks into smaller ones, and so on until there is no point in further beating.

Then I write a prototype solution and tests for it already on my computer. And already this prototype I bring to mind, refactor, profiling and optimizing those or other code sections.

It is very useful to write tests, as they help to control whether the code remains operable after this or that change.

In addition, I use static code analyzers. They should not be trusted one hundred percent, but they often provide useful information about where potentially code can be dangerous from the point of view of bugs.

    To compile a particular algorithm, not a bad knowledge of the language in which you write is necessary, because depending on the use of certain tools of this language, you can write an algorithm. And good or bad it will be - it depends just on this knowledge. For example, in the OOP there are patterns — patterns of implementation for particular tasks, due to which their implementation and further support will pass with minimal problems. The code (preferably, almost necessarily) must adhere to certain design rules: for example, such as KISS, SOLID, DRY, etc.

    I usually start by implementing some kind of code preparation that is not ground, so to speak, depending on the specific conditions that must be fulfilled in the code. Trying to match them, in parallel I think how the code can be improved, in what ways to make it so that it is as productive and optimized as possible. (Here we will need various knowledge)

    Different knowledge helps due to its diversity to choose the best option possible.

    Example:

    Different methods of implementation in algorithms - https://tproger.ru/articles/computational-complexity-explained/

    Many different sorting options - https://habr.com/ru/en/post/335920/

    I will add, if thoughts come