A library or your own code

A library or your own code

Have you ever connected lodash, or any other library, using a single function from it? Wouldn't it be easier to write that function myself, especially if I solved this problem on vanilla js?


First of all, if you are looking for one, there is no definite answer to this question. In each case, you need to take into account many factors, starting with the nature of the code and ending with the launch conditions, i.e. where and how the program is launched. We will talk about this later.


On the one hand, the size of the code is almost irrelevant. Plus or minus a megabyte, or even ten megabytes, doesn't solve anything at all. Modern software has enormous resources, the weight of which is much larger than the size of any library. Even so, a library with simple functionality takes up a lot of space.


On the Front-End, everything is a bit more complicated, but now it all comes down to how the library is organized. If the export is properly configured, the final version (for example, built by a webpack) will contain only those functions that are actually used. And this is very little.


Dependencies:

Some developers minimize the number of dependencies (third-party libraries) in their code. Small functions are no longer enough here, complex projects can have their own solutions with many ready-made tools.

There's not much to say here. Dependencies are good if they save developer time and allow you to spend more time on application logic than infrastructure tasks.

What are the advantages?

Not all libraries are equally useful. There are often several basic problems that are poorly implemented in the programming language itself. These include working with collections, working with dates and times. In addition, various more specific parts need to be extended. In these cases, the library must be added as a dependency even for a single function.


As a rule, where one function is needed, another soon becomes necessary. Without realizing it, one person will write one function, another will write it elsewhere, and there is no certainty that they are aware of each other's already written solutions.?

This situation quickly turns from "too early" to "too late" when there are many functions in the code available in each library.?

Moreover, when programmers move to other projects, the same thing happens there. As a result, standard functions scattered across different projects, written by different people, contain bugs, lack documentation, and are usually poorly or not tested at all.


Your code will not be as thoroughly tested and documented as in popular libraries. Try opening lodash and see how extensive the documentation is. This is another advantage of such libraries. Since the library is so widely used and standardized, most developers know how to work with it.?

This means the project code will be more understandable for everyone who works with it.


There is another interesting but not obvious advantage of using such libraries.

Libraries contain many functions that are difficult to understand on their own. By using these libraries, developers can increase their level of knowledge and learn how to solve most standard problems with a minimum amount of code and correct abstractions.?

Of course, these functions need to be reviewed periodically. Students regularly reinvent the wheel because they don't know about standard solutions. In addition, when we say that only one function is needed, it turns out that there are actually several, and the developer may simply not be aware of them.

For other rare libraries, the situation is more complicated and it's not always clear whether to pull with the library. The key to making such a decision is realism, not completeness.

#programming #frontend #development

要查看或添加评论,请登录

Volodymyr Shaitan的更多文章

  • Розробка через тестування - TDD

    Розробка через тестування - TDD

    Поговоримо про тести. На якому етап? краще всього писати тести? Взагал?, ?сну? три п?дходи: тести пишуться п?сля коду…

    1 条评论
  • Б?бл?отека чи св?й код

    Б?бл?отека чи св?й код

    Мен? потр?бна всього одна функц?я Ви коли-небудь п?дключали lodash, або будь-яку ?ншу б?бл?отеку, використовуючи з не?…

    5 条评论

社区洞察

其他会员也浏览了