the Internet Windows Android

NPM and Left-Pad: We have learned to program? CSS style Padding-left. Installing the field on the left using Padding-Left, we are struggling to reduce dependencies

CSS Padding-Left style sets the field size (distance from the inner edge of the element frame to an imaginary rectangle that limits its contents to the left.

Summary of CSS Property Padding-Left

PADDING-LEFT Properties Writing Rules

Padding-left:<размер>;

The magnitude of the left field can be indicated in pixels (PX), percent (%), or other permissible units permissible for CSS.

Object model

Object.Style.paddingleft.

Padding-Left Style Application Example

We will illustrate the work of Padding-Left on the example. We need the field on the left to be greater than from other sides. It is necessary that the text does not climb on the background pattern.

Application Properties Padding-Left Example CSS Style Padding-Left
We need the field on the left to be greater than from other sides. This will help the CSS property Padding-left.


Instead of writing Padding: 5px; and then Padding-Left: 90px; We should have written Padding: 5PX 5PX 5PX 90px; . So much shorter and shows a higher level of layout.

Sets the field value from the left edge of the contents of the element. The field is the distance from the inside edge of the element frame to an imaginary rectangle that limits its contents (Fig. 1).

Syntax

padding-Left: Value | AUTO.

Arguments

The magnitude of the left field can be indicated in pixels (PX), percent (%) or other permissible units for CSS. The AUTO argument indicates that the field size will be automatically calculated by the browser.





padding-Left.



Lorem Ipsum Dolor Sit Amet, Consectetuer Adipiscing Elit, Sed Diem Nonummy Nibh Euismod Tincidunt UT Lacreet Dolore Magna Aliguam Erat Volutpat. UT Wisis Enim Ad Minim Veniam, Quis Nostrud Exerci Tution Ullamcorper Suscipit Lobortis Nisl UT Aliquip Ex Ea Commodo Consequat.





The result of this example is shown in no rice. 2.

Fig. 1. Apply Padding-Left parameter

Browser Nettscape. Opera Mozilla Firefox.
Version 5.5 6.0 7.0 8.0 8.0 9.0 7.0 8.0 9.2 9.5 1.3 2.0 3.1 1.5 2.0 3.0
Supported Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes

brief information

Description

Sets the field value from the left edge of the contents of the element. The field is meant due to the distance from the inner edge of the frame of the element to the imaginary rectangle that limits its contents (Fig. 1).

Syntax

padding-Left: Value | AUTO.

Arguments

The magnitude of the left field can be indicated in pixels (PX), percentage (%) or other permissibles for CSS (TSS) units. The AUTO argument indicates that the field size will be automatically calculated by the browser.

STML 4.01 CSS (TSSS) 2.1 IE 5.5 IE 6 IE 7 OP 9.5 SA 3.1 FF 2.0 FF 3.0

padding-Left.

Lorem Ipsum Dolor Sit Amet, Consectetuer Adipiscing Elit, Sed Diem Nonummy Nibh Euismod Tincidunt UT Lacreet Dolore Magna Aliguam Erat Volutpat. UT Wisis Enim Ad Minim Veniam, Quis Nostrud Exerci Tution Ullamcorper Suscipit Lobortis Nisl UT Aliquip Ex Ea Commodo Consequat.



The result of this example is shown in no rice. 2.

Fig. 1. Apply Padding-Left parameter

(David Haney), Lead Programmer Stack Overflow

So developers, time for a serious conversation. You are probably aware that this week React, Babel and a bunch of other popular NPM packages broke. The reason is pretty amazing.

A simple NPM packet called Left-Pad has been set as a dependence in REACT, Babel and other packages. The module that at the time of writing this post has 11 stars on GitHub (now 323 - approxper). The entire package consists of 11 simple lines that implement the primitive function inserting spaces in the left side of the rows. If some of the links are someday, here is its code:

Module.exports \u003d leftpad; Function LeftPad (STR, LEN, CH) (STR \u003d STRING (STR); var i \u003d -1; if (! CH && CH! \u003d\u003d 0) CH \u003d ""; Len \u003d Len - str.Length; While (+ + I.< len) { str = ch + str; } return str; } Что меня беспокоит, так это such a large number of packageswhere installed addiction From a simple rowing functions with spaces, instead of spending 2 minutes and write this basic function itself.

Having learned about the distress that happened because of Left-Pad, I began to explore the NPM ecosystem. And that's what I discovered, among other things:

  • There is a package called isarray.Batching 880,000 times a day, 18 million downloads in February 2016. Him 72 dependent NPM packages. And here is it whole 1 line code:
    Return Tostring.call (Arr) \u003d\u003d "";
  • There is a package called iS-POSITIVE-INTEGER (Github), which consists of 4 lines and which was required for yesterday 3 other packages for work. The author has since spent a refactoring, so now the package has 0 dependencies, but I can not understand why it was not done immediately.
  • Fresh installation Babel. Includes 41,000 files
  • Clean JSPM / NPM-based application template Begins C. 28 000+ files
All this makes you ask a question ...

We learned to program?

In which of the parallel worlds, the above decisions are the best? How hundreds of dependencies and 28,000 files for an empty template can be called something else, except for excessive difficulty and madness?

It seems that the NPM ecosystem participants have grown fetish micropower plants. Instead of writing any function or code, they seem to be preferred to establish a dependence on something written by someone else. It seems to me that all the work of the programmer in the NPM ecosystem is reduced to writing as a smaller code as possible to associate existing libraries together to create something new, functioning uniquely for personal or commercial needs.

Functions are not packets

The functions are too small to get into the package and dependency. Clean functions have no connection; These are random code fragments and nothing more. Who needs dependence on cosine? Instead, we would truly like the dependence on the trigonometry package, which covers many cunning functions that we do not want to write themselves. It is much more similar to how .NET and other frameworks create a basic library with the main functionality. Such a library is tested by the creators of the language and has a large extent guaranteed reliability, with the absence of bugs.

The problem of third parties

There is no absolutely no guarantee that written by someone else correctly or will work normally. Even if everything is correct, is it an optimal way to solve the problem? At least when you write code yourself, you can easily change it, fix bugs and improve efficiency. There should be no particularly many bugs in a function of 1 lines.

Secondly, even if the logic in the package is correct, it is affected by the fact that the developers establish dependencies on single-line functions that themselves must be able to write with closed eyes. If you can not write the function left-pad, is-positive-integer or isarray in five minutes (including the time to search for Google), then you do not know how to program. Damn, any of them can be a good question at the interview as a check, whether the candidate is able to program.

In the end, the binding together of different APIs is not programming. This is some kind of crazy form of hacking of dependencies, which includes clouds and overloading by code and difficulties that are not really necessary.

What is even worse if there is a bug or code in your code or in the code of a third-party library, then you will not know how to debug or fix it if you do not know how to program.

We fight for a decrease in dependencies

Each added package adds another one. addiction To your project. Dependencies in the essence of this word is what you needideSo that the code worked. The more dependencies, the more you have failure points. Not to mention a greater probability of mistake: Did you check any of those programmers who wrote these functions from which you depend daily?

Take the dependency for any complex functionality that is very long and expensive to implement yourself. Things like the level of access to the database (ORM) or caching client must be established as dependencies, because they are complex and risk of depending on savings and efficiency.

But please, for the sake of love for everything, which is programming, write the damned basic functions. Putting dependencies on single-term packages - it is generally to scream. Do not believe? Just ask the developers of React, as they have passed the week, and whether they do not regret that they did not write those 11 lines to pack the string on the left spaces.