JavaScript, despite its many flaws, is probably the best programming language for novice developers, and the best language kids can tinker with.
It was 2007. Excellent technical book publishing O'Reilly Media approached me, proposing one idea. They asked me if I would like to write a book on javascript that would be intended for absolute beginners in programming. “Why on earth?”, I immediately asked a counter question.
It was impossible to say that JavaScript in those days was a completely useless language. But it was only one, far from the most important ingredient from a carefully selected set of technologies needed for website development. Yes, small pieces of JS-code could be used to check the form, or to highlight the buttons, which hover the mouse. But JavaScript was just an optional addition to the site’s functionality. If you remove it from the page, then everything continued to work in almost the same way as with its use.
JavaScript, moreover, pulled along a lot of luggage presented by other technologies. So, browser incompatibility problems were associated with it; it was slow, insecure, completely unreliable. I was not interested in teaching someone to create javascript widgets for web pages using JavaScript. These widgets seemed to me as meaningless as animated gifs with a rotating globe, which were very popular at the dawn of the Internet.
')
The most obvious way to use JavaScript, like me, naively, then it seemed like the following: a large server framework should generate all the necessary JS code and embed it into a page designed specifically for your browser. The JavaScript code generated by the server might be too cumbersome, but it would be designed for a specific browser version. And given that JS played only the role of an auxiliary mechanism, everything would work as it should, even if the site visitor completely disabled JavaScript.
Needless to say, I didn’t write a book about JavaScript. I continued to do server programming and write about my favorite technologies (usually about C # and the .NET Framework). Many years later.
Then something strange happened.
JavaScript literally took off.
I still do not think that JavaScript deserves the honor of being called the world's best programming language. I even, if really quite honestly, do not consider it a very good language. But something in which I changed my opinion. Now I think JavaScript is probably the best first language for kids and novice programmers. The thing is that JavaScript has one very serious advantage over all other programming languages.
The awesome prevalence of javascript is its main advantage
One of the unique advantages of JavaScript is its prevalence.
This language can be found literally everywhere. It is supported on all operating systems, in all types of browsers, and on desktop computers, and on mobile devices. It is also very important that JavaScript applications work without installing them on users' computers. In fact, it is already difficult to remember not so old times, when companies, deploying client-server applications in their internal networks, spent weeks struggling with the problems of setting up these applications and with unexpected errors. Faced with such nightmares, you can appreciate the appeal of JavaScript.
JavaScript, due to its prevalence, does not have to be the best programming language. He just needs to be a good enough language.
Similar mechanisms work when it comes to learning programming. At first, the problem of the prevalence of a language does not seem particularly important for one whose goal is to learn time-tested practical program development techniques. But a lot of the same problems are relevant, as for professional programming, in teaching programming. If you want anyone to use what you create, then JavaScript is the only alternative.
Suppose you are developing a wonderful application that, when asking the user questions, determines his personal profile. Setting up the development environment is pretty simple. But what happens when you want to send your program to a friend? Will it need to install a runtime environment or recreate the same development environment as yours? Will it be necessary to “tweak” the security settings of his computer before he can download and install your program? Maybe your friend uses an operating system that simply does not support your program, or a mobile platform on which, if you don’t go into details, you can install only professional applications distributed via iTunes or Google Play? If you use JavaScript to develop the program, and a simple website (for example,
GitHub allows you to create such websites for free) to distribute it, all these problems will simply disappear.
And if our future programmer is a child, then here is an irrefutable fact: children and browsers are very strongly connected. If you watched a child who works on a computer (not on a mobile device), then you may have noticed that he spends at least 98% of his time working with the browser. Children play browser games, use social networks, go to school with Google Classroom and Google Docs. And if the code that children write will work in their native browser world, it will be completely natural.
We are now discussing the strengths of JavaScript. But, of course, speaking of JavaScript as a programming language for beginners, one can not forget about its shortcomings.
JavaScript flaws
How about javascript issues? This language has serious flaws, its quirks, contradictions and limitations can be extremely unpleasant for someone who is just starting to learn programming. Fortunately, there are modern solutions that can smooth most of the drawbacks of JavaScript.
Let's sort four main claims shown to this language.
â–Ť1. The problem of working with data types in JavaScript
The most important concept, which novice programmers learn very early, is the idea of ​​variables, containers that store information during program operation. The problem with javascript is that this language is too loose and careless about handling variables. It allows you to do something that does not look right, and ignores obvious inconsistencies. His negligence can turn minor typos into disasters that disrupt programs.
Here is an example of code that is doomed to failure:
var myNumber = 100; myNumber = myNumbr + 1;
See a mistake? The second line actually uses two variables: the variable
myNumber
, which was declared in the first line, and some dummy variable
myNumbr
. We know that the second variable is the result of a typo, but JavaScript will tell us about it only during the execution of the program, giving an error message that looks like
ReferenceError: myNumbr is not defined
. The same thing happens if when writing the variable name mixed up small and small letters (for example, the variable from
myNumber
accidentally turned into
MyNumber
). The problem, but of a different nature, may arise if you, considering that a variable stores a number, add another number to it, and this variable actually contained a string or something else. JavaScript in this case will not report an error, but the result of the calculations will not be at all what you would expect from adding two numbers. Every JavaScript developer can remember an unpleasant story of this kind, when type confusion caused strange program errors.
It's hard enough to learn how to program, and at the same time, worry about how a programming language you study can harm you. But, fortunately, the problems of safe work with data types can be easily solved with the help of suitable development tools.
One of my favorite code editors that is suitable for both learning programming and professional use is
Visual Studio Code . It is free, undemanding of resources, its code is open, it can be expanded almost infinitely. One of its most remarkable features is to support the organization of checking JavaScript code for the presence of common problems with TypeScript tools. You can enable such a check by using the appropriate configuration file or inserting the following comment in the top of the JavaScript file:
Here is an example in which there are two errors, neither of which, from the point of view of JavaScript, is not an error.
Problems that JavaScript does not consider to be errorsIf you add a comment
// @ts-check
to the beginning of this file, VS Code will highlight lines of code that contain potential errors.
Highlighted lines of codeIf you hover the mouse over the highlighted line, a popup window will appear explaining the problem.
Problem explanationWhat conclusions can be drawn from this? Although JavaScript is tolerant of many bad things, if you combine JavaScript with a high-quality code editor and the right extra tools, you can create a development environment similar to those of other modern programming languages. As a result, JavaScript development is just as convenient as in other languages, and, of course, its other advantages do not go away.
â–Ť2. JavaScript does not support OOP
Object-oriented programming (OOP) is an approach to modeling and organizing code. If OOP techniques are applied correctly, they help the programmer create simple and well-organized code. In addition, OOP simplifies the reuse of important program functionality.
JavaScript is notorious for not supporting object-oriented programming. In fact, JavaScript developers traditionally bypass this drawback using all sorts of strange constructs. These constructs may mean something for someone who has already studied OOP (and even for someone who has not studied, but simply copied a certain template into his code and was used to working with it). But if you are a completely new person in programming, the use of such dubious constructions that implement basic programming concepts is completely wrong.
Fortunately, there are beautiful solutions that provide OOP support in JavaScript. My favorite solution of this kind is
TypeScript , an open source project launched by Microsoft in 2012. TypeScript is a kind of improved JavaScript that supports OOP (as well as many other useful features like strong type checking).
Someone might say that we are talking about JavaScript, and that TypeScript is still not JavaScript. And, in fact, it is. But here is one interesting detail. The code is written in TypeScript, and then converted into JavaScript before it is executed. This allows you to enjoy all the best of worlds TypeScript and JavaScript. If you choose TypeScript, then you will have a modern programming language in which you can write your code, and that is the broadest support that regular JavaScript uses.
And, best of all, the conversion of TypeScript code into JavaScript is done automatically. Of course, in the computer-generated JavaScript-code are used, to reflect in it the concepts implemented by means of TypeScript, rather cumbersome constructions, but this does not change anything. The programmer studies the concepts of OOP, and the ready-made code works correctly, processed without problems by means of modern computers.
Do not believe? Then consider that some of the most modern innovative desktop applications use a combination of TypeScript and
Electron - a framework that allows you to execute JavaScript code outside a traditional browser (although it should be noted that Electron uses browser-based features). One of the most impressive examples of such an application is the VS Code editor. It turns out that the very tool with which it is very convenient to write JavaScript code is itself written in JavaScript. True, to be more precise, VS Code is written in TypeScript, but the code written in this language is still converted into JavaScript code.
Of course, studying programming does not necessarily use TypeScript, and new JavaScript programmers, if they decide to do so, will be able to do a lot without studying the principles of OOP. This is actually a matter of choice. In any case, it can be noted that JavaScript is a dynamically developing language, and features that bring it closer to everything valuable in TypeScript are gradually added to it.
â–Ť3. Around is full of poor-quality JavaScript-code
What can I say. Poor code can be written in any programming language. Ever heard of
Visual Basic ?
â–Ť4. JavaScript development requires additional libraries and frameworks.
In order to gain access to a wider set of features (and not reinvent the wheel) than is in the language, JavaScript programmers need to use third-party libraries and frameworks. Choosing the right ingredients to use when creating a project is not as easy as it might seem at first glance. It is, in particular, that the chosen additional tools should correctly solve the tasks set for them, it is necessary that the programmer would have the confidence that they will enjoy the support of their developers for a long time, it is necessary that they do not conflict with each other. a friend.
Some kind of this problem is faced by developers using other languages. However, it should be noted that few languages ​​suffer from this problem as much as JavaScript. In order to become a serious programmer in a JavaScript world open to all, you need to build your own set of development tools. At the same time, each of the possible choices is so complex and multifaceted that it can only be understood very well if it’s appropriate for you, say, a library (and when you study it, it may turn out that it already loses its relevance and her place will come something new, attracting, perhaps - for a short time, the general interest).
No matter how sad all this may be, these problems, in fact, do not affect newcomers. If someone learns programming using JavaScript, then it’s best to stay away from frameworks and libraries, whether it’s about something widely known, such as
jQuery ,
Angular ,
React, or
Vue , or something invented at that moment this sentence was written, or the second the article was published. Of course, a beginner, having mastered the fundamental things well, will probably want to familiarize himself with at least one of the popular additional tools. But this is a completely different story.
Results
In fact, the choice of the first programming language is a question that cannot be answered with the absolutely correct answer. The author of this material shared here only his own opinion on this matter, gave examples that are close to him because of his experience and preferences. But, in any case, all programmers start from something, and no matter how difficult the choice of the first language may be, it is a choice, anyway, you have to do.
Dear readers! Do you agree that JavaScript is, in modern conditions, the best language for learning programming? If you do not agree - then maybe you know some language that is better suited for this purpose?
