You still don’t like JavaScript?

You still don’t like JavaScript?

With the beginning of the era of HTML5, it took the market a large number of JavaScript programmers. Many other languages began to shift to JavaScript massively.

I have many times seen as developers with extensive experience scolded this, one of the most flexible and powerful, words without understanding its principles. In this article,

I will try to describe the essence and philosophy of JavaScript. Here will be just four lines of code and a lot of what not to write in textbooks. Promise that you’ll love this language, or at least become more efficient. So there you go!

I’ll discuss the main features of the language and the investigation of them. For example, JavaScript has a very low entry threshold. With C++ or Java, you can start the quite common program on it after 15 minutes after dating. However, to do professional things, you need to read the documentation, books on patterns of JavaScript to communicate with more experienced colleagues. Most of the “potbellied and old Jedi programming, of course, do not scold and language.

Maybe it would be better if the entry threshold was above?

I think not (although critics would be less). Agree, it is much easier to comprehend the nuances when you can already write functional code.

  • JavaScript is multi-paradigm language. It combines object-oriented and functional approaches.

  • Also available structured programming and much more. It’s due to the high flexibility of language. Functions are objects of the first kind; variables can change the type objects receive new properties on the fly.

Is this right or wrong?

On the one hand, this creates problems with understanding programmers accustomed to the certainty of languages such as Java or C#. But this is a small fee for efficiency. JavaScript, in most cases, allows you to create applications much faster than its strictly typing companions. To cite just one example:

I have worked in the company developing exchange Terminal. Creating a was necessary.Net C # desktop application, and it’s an exact copy of the Web on JavaScript. A C # application developed a team of 12 programmers within two years; JavaScript is a team of 3 developers throughout the year. You can talk about the differences in qualifications, that perhaps influenced by other factors, but the difference in 8 times is illustrative.

How did such a speed of development has been achieved?

Most languages put restrictions, ostensibly for our good. JavaScript does not recognize the limitations you can change code anywhere, anytime, including patching flexibly someone else’s code. If to compare programming languages with political systems, then, say VBA is totalitarianism, you put in rigid frames and can’t even see all the source code. C++ is a democracy, your freedom to wave hands ends where your nose begins. It’s a real, robust programming language that restricts personal freedom for the sake of the common interest. JavaScript is anarchy, you can change anything, and now you will not interfere, not limit your freedom. The problem is that not everyone can live in complete freedom.

High internal culture, not to steal from a neighbor’s tractor, even if you’re behind it, nothing will. The same code, for example, a common practice in JavaScript, not doing private properties truly private. Created regular (public) lands and to their name simply “underscores. It believed that other programmers would see this and will not use this property unless required. There are situations when the individual ownership values as modify, is the most direct and correct way. Yes, there are exceptions everywhere, and JavaScript allows us to do them. In such cases, the programmer knows someone else’s code and shall assume responsibility for the consequences. “It could all break!” — Resent peddlers of other languages. On this next point.

In JavaScript, there is no foolproof. We believe that all who work on the code — professionals and trust them. (Pause) A good JavaScript commands all programmers at the same level. It can be low or high, but should not be too much different. Just like in a country where all steal, honest person has difficulty, or indecent people wretch immediately gets short shrift. Even in an anarchical and uncontrolled JavaScript, junior will break the code of the Jedi and Jedi will use not understandable to junior camp (but acceptable for any professional) architectural moves unwittingly reducing their productivity. So whether you want to err through language, or better just to recruit the right people? Some JavaScript scolded for what they call “bugs” and “illogical.” For example:

‘ 3 ‘ 2 = 1;
‘ 3 ‘ + 2 = ‘ 32 ‘;

It’s is why after fast start preferably still read about type conversion. For any, even a novice JavaScript programmer, the above examples are trivial and entirely predictable. For ten years, these things never aroused me problems. Another exciting challenge that will return this code:

Math.max (2, []);
Math.max (2, {});

Funny, but the first line of the return and the second 2 NaN (Not a Number).

Whether this is an error and illogicality?

See above, foolproof JavaScript doesn’t have, and if you pass instead of an object or array — can only blame themselves. Similarly, in C++, you can write in different memory garbage and cuss language. If you have a gun, that does not mean you have to shoot yourself in the foot.

A bit about handling errors in JavaScript — it’s silent. It means that if the program can continue — it is likely to continue. Let’s say you divided by zero, most languages will throw an error and exits, and JavaScript will show Infinity and perhaps even displays its user interface as a string, so conceived program logic.

Is this right or wrong?

I’d say it allows you to create programs with the highest level of stability. Failure of one element does not incapacitate the entire system. Of course, bad show user NaN or undefined, but it’s much better than the aborted, as all we’ve seen the many native studies program under Windows (and not only). We trust the programmers and consider them to be professionals, so in an ideal world, these situations should not appear. If the same problem still arose — we have insurance, a margin of the tongue. And, of course, in the critical field program, we can manually check the values NaN, null, undefined, creating entirely strict code.

For dessert, I will tell a vision very ambiguous features of JavaScript is prototype inheritance. If we talk about object oriented programming, generally speaking, it does not require that the objects announced through the classes. Moreover, we often need some object in a single copy, or you want to create multiple similar items, but differing in some nuances — new field flags, methods. Often, create classes not necessarily, it’s excessive level of abstraction, and prototype-based inheritance, or even create objects on the fly, is perfect for cutting such tasks.

According to the principle of Ockham razor, it is not necessary to generate extra code, if the task can be solved easier. Such an approach requires not only less text but also less memory and processor time. Classes do not come out of the box, but if you write a large enterprise application is to write 20 lines of its implementation classes for you. If not, use one of the many libraries, languages such as C++ libraries have to without much harder. Although some people prefer to write in pure JavaScript, it is not so complicated and has additional benefits.

We can say that JavaScript has, perfect for our time, the level of abstraction. You don’t need to worry about memory allocation, about fifteen sort algorithms, the type of operating system. You can concentrate on the bigger things, such as architecture or application logic. We can say that JavaScript is a language specifically for programmers, not for hardware person or system administrators. Snipping insubstantial, you can achieve high performance and create high-quality and elegant software, remarkably short period. Of course, if you feel the language freely.

The last and most important thing you need to understand about JavaScript, associated with dynamic typing. It may seem strange, but I want to ask this question: what type system exists at all? In the human world is dominated by not typically information: we cannot often draw the line, story or novel, this Babe transformed into a child, then a teenager.

Can I assign to those stages types and whether you want to do this?

Data types are natural for the compiler; it is much easier to convert code if we immediately know what serves us primitives. But progress is moving forward, and I believe that language with a flexible typed — significant steps forward. In the tradition of JavaScript, if you lack class types, you can create them manually, write a wrapper, enter restrictions. I worked in the gaming company, the product which had a very complex logic and they made a wrapper for classes with rigid typing, multiple inheritance, and blackjack. JavaScript has a stunning level of introspection, and you can adjust it to yourself in a very wide range.

To be quite honest, I say the same about perhaps the most significant minus JavaScript: professional programming on it in many ways harder than in Java orc #. If in strongly typed languages, you see at least the kinds of the arguments that you take in the JavaScript function you need all these details to keep in mind. Sometimes you cannot be sure even what methods have one or another object which requires a high level of concentration and a good understanding of architecture. If you are ready for it and willing to honestly examine language, rather than blindly coding right off the bat, you get a truly one of the most powerful tools for a flexible and cross-platform software at high speed.