📜 ⬆️ ⬇️

There is a javascript. Why do we need other scripting languages?

I endured long and honestly, but finally I could not stand it. Maybe we can figure it out together?



So, suppose someone decided to create a new scripting language. And let's say it calls Ruby. Let's try to understand - why do we need to do this at all? What do we expect from a scripting language? All this, in my opinion, is fairly obvious, but those who wish can also say a word, of course. For example, you can paint the advantages and disadvantages like this:
')
Minuses:

- A new syntax requiring study;
- low performance in comparison with native-code;

Pros:

- automatic garbage collection;
- syntactic sugar;
- runtime typing;
- runtime-extensibility of objects.

Like that. Thus, the creator of the scripting language first of all _ refuses productivity_ for the sake of other advantages. This is a very important architectural solution and we will return to it later.

When creating a new scripting language, you need a VM connection (virtual machine that executes the script) of the script and the outside world. I need modules, libraries, frameworks and other implementations, forgive me this old Russian word. Arguing about the possibilities of a scripting language, adherents of scripting cults can discuss the following completely different topics:

- about the syntax and convenience of the language itself (for example, built-in eval ());
- about the convenient implementation of a certain functionality that is implemented by a certain library (for example, regular expressions or an embedded web server);
- about the speed of execution of calculations "inside" VM (for example, array sorting);
- about the speed of making calls from VM to the outside world (library, OS) (for example, writing to a file).

So here. Only the first item is relevant to the scripting language. Only he.
Everything else is relevant to the implementation. Not to the language itself.

If a scripted holivarschik doesn’t argue about the first paragraph, then he should note that he’s not about the language, but about the platform: the concrete implementation of the scripting language on a specific OS or on a specific VM.

The first thesis. The advantage of a scripting language cannot be the presence of libraries that implement this or that functionality. It all depends solely on the implementation of the scripting language. Take, for example, this article:

habrahabr.ru/blogs/ruby/69314

This describes the implementation of a www server in Ruby.

But what is actually Ruby here?

Look, I just wrote a www server in javascript:

var www_server = new WebServer ('127.0.0.1', 3456);

It accepts requests and gives files. Believe it? And I have this here the implementation of the BBB server. And now you know that JavaScript is a good language and it’s easy to create a web server, right? Do you know or do not know?

By the way, in JavaScript it is also easy to run Doom 4. Well, when it comes out. Look here:

var doom4 = new Doom4 ();

Cool, right? In the following bottles we will continue to get acquainted with javascript, and now we return to our topic.

We take now specifically Ruby. Oh, sorry, I got my hand, but it could be any other language, in principle.

Here, for example, I am reading the capabilities of Ruby and a bit of a wow.

ru.wikipedia.org/wiki/Ruby#.D0.92.D0.BE.D0.B7.D0.BC.D0.BE.D0.B6.D0.BD.D0.BE.D1.81.D1.82 .D0.B8_Ruby

"
It has a concise and simple syntax, partly developed under the influence of Hell, Eiffel and Python.
Allows you to handle exceptions in the style of Java and Python.
Allows overriding operators that are actually methods.
Fully object-oriented programming language.
It does not support multiple inheritance, but the concept of "impurities" based on the module mechanism in this language can be used instead.
Contains automatic garbage collector. It works for all Ruby objects, including external libraries.
Supports full-variable closures.
"

Khm And what of this is not in JavaScript? Well, except that the operator overrides. AND? What is all the noise about?

“There are many original solutions in Ruby that are rarely or not at all found in common programming languages. You can add methods not only to any classes, but also to any objects. For example, you can add an arbitrary method to a string. ”

Javascript:



“Any construction in Ruby returns a value. For example:"

Gyygygygy.

alert (a? "a": "b");

“Working with arrays is one of the strengths of Ruby. They automatically resize, can contain any elements, and the language provides powerful tools for processing them. ”

Well, there is even nothing to talk about. Javascript just takes out Ruby.

Namba thesis two. The syntax and capabilities of JavaScript are completely superior to other scripting languages, and they are not dependent on implementation, and are already part of the language. The small advantages that competitive syntactic sugar provides are quickly crushed by eval (), JSON, arguments, and other nice JavaScript features.

I'm not a big specialist in scripting languages. Please show me how to do eval () in PHP, Ruby, Python. Is there a null with special properties? Can I work with the passed arguments of any function as with the arguments array? Can I create an object in them with data and methods by writing:

var o = {animal: 'dog', dead: false, kill: function () {if (! this.dead) this.dead = true; }}

Please write examples. But maybe something I persistently do not understand, and there is some secret knowledge about the secret possibilities of these scripting languages ​​that a few enlightened people have comprehended?

And a big request - examples of what can not be done in JavaScript. We take Ecma-262 as a basis.

What can you write such in other scripts, what can you not do in JavaScript?

Now I'm just rude walk through the implementations of these scripting languages. There is JavaScript to rest.

The most interesting thing comes when you start to execute many, many scripts at the same time. And here it turns out that the praised scripting machines die quickly or slowly.

With minor disassembly, it turns out an interesting detail - the developers of these scripting languages ​​for some strange and mysterious reason put on performance. Immediately! They are so fascinated by erotic fantasies associated with an amazing new syntax that no one took a simple thought into their heads: you should foresee an implementation from the very beginning that allows you to execute a lot of scripts quickly.

As a result, we read:

Ruby:

ru.wikipedia.org/wiki/Ruby#.D0.92.D0.BE.D0.B7.D0.BC.D0.BE.D0.B6.D0.BD.D0.BE.D1.81.D1.82 .D0.B8_Ruby

“The Ruby interpreter today has the following drawbacks ...: Low speed. Ruby 1.8 is one of the slowest programming languages ​​used in web development practice. ”

PHP

php.russofile.ru/ru/ru/translate/unsort/optimizing/#01

“The PHP script is loaded into Zend Engine and compiled into opcode. Opcode can be optimized using an optional optimizer named Zend Optimizer. Depending on the script, it can increase the execution speed of the PHP script up to 50%.
Previously, after execution, opcode was destroyed. „

Lyrical digression. Isn't that brilliant? Well, who - who in the whole world could guess that compiled scripts can be cached? Well this should be ... Bill Gates, I guess. Or two Gates at once.

I hope you understand what exactly I am ironic about? Here it is: “before,” “had flaws that were eliminated,” “was complete shit before.” I do not understand - why start with crappy performance. Well, explain to me! You are welcome! What is the purpose of creating a new scripting language?

Well, let's say you offer your new super-trendy scripting language for home use and writing student works. Then I understand - performance does not matter.

But if you propose to use your language to dynamically generate the content of a loaded website, then I have a strong suspicion that performance is the most important ’criterion.

So the following thesis is not related to JavaScript, this is another portion of the poison in relation to others.

Thesis Namba Fries. Implementations of new scripting languages ​​did not initially contain the original architectural solution, which allows them to squeeze the maximum performance out of them: multi-threaded execution, pools of shared internal structures (execution contexts, for example), precompilation, setup compilation from intermediate bytecode. At the same time, most of these languages ​​were offered just for the sector with a large load, for example, a web server.

And so it's pretty funny to read how PHP is used to process web requests. Just want to ask - maybe you should have taken a BASIC? It is also scripted. And it also works slowly ...

It turned out a little messy and sometimes harsh, maybe.
I hope no one took my comments personally and was not offended.
I will be glad to find the truth with you.

Source: https://habr.com/ru/post/70314/


All Articles