📜 ⬆️ ⬇️

How I found the best programming language in the world. Part 1

Since I will continue to strongly provoke trolls on the topic of programming languages, and even more so I will name the best programming language in the world (at the moment) (absolutely the best programming language, that is, without any reservations), from which, as a rule, a troll breaks a tower, I recommend them and everyone else to get acquainted with my post almost three years ago, "On the choice of programming language" , everything written there is relevant and I do not want to repeat.

Read? Next will be about the best programming language in the world , which I will call closer to the end. Yes, yes, three days ago I didn’t think that unicorns exist - after all, each language sucks one way or another, and each sucks in its own way (although no, there are those that always and everywhere suck, but we won’t talk about them). As an engineer, I was well aware that the language issue was not possible without a variety of trade offs, starting with garbage collected vs manual memory management, although Rust tries to eat the fish without sitting on the stick in this matter, and so on. Although we are talking about languages ​​of general use, they all position themselves in one way or another, focusing on some ideas, principles, and goals for which they are good, leaving everything that is not consistent with such principles at best possible, but not effective and / or not comfortable. In a word impractical. However, there is a language combining the incompatible .


')
As I wrote in the past , the problem of choosing a programming language in my life appeared only at a mature age, about 7 years ago, when I realized that Java is no longer a cake. At the same time, in the search for productivity and the naive desire to make Scala the main clerical language for the next 10 years, we bought early access (some chapters) of the book that was not yet published by Odersky et al. So I also discovered Scala for myself, years before it appeared in the resumes and heads of candidates who came to the interview, and some of you were still in school. Again, being in a company that has been making an IDE to order for more than 10 years, I saw so many linguistic threshills and pearls among them that I ask the captains for evidence to think a bit before sending the author to any linguistic history - do you really think that 7 years looking for and can not find the language does not know about your captain's history.

In recent years, the problem of choosing a language has only become aggravated: we need to start a new technological revolution in Xored , and there are some ideas of “exquisite” technologies that allow us to do all kinds of Magic, but I was not ready to start something for a very long time. The answer to the question why, still surprises me, as if I received a similar answer at the interview, I would immediately write down the dude minus in my book. The answer really sounds silly and childish: I did not know in what programming language I would like to see a stack of our amazing technologies. The only excuse: I’m really aiming for a long way - and this is not one single project, this is what I want to invest the best years of my life, and the price of the issue for me is very high.

Going on a long and difficult journey in choosing a vehicle is dangerous to make a mistake. And all the last years I have been looking for (waiting for?) A programming language (platform) that would not cause me to be rejected for this or that reason. Having plans for quite ambitious tasks, I put forward various functional and non-functional requirements for such a programming language.

Requirements



I want high-performance code in the browser, and I want the opportunity to push my code into unikernel / cloud os. I want a high-performance side-server with large amounts of processed information. I want iOS and Android (of course, also high-performance). And I want to program all this without hemorrhoids . Do not soar with code generation, do not work with memory directly through the narrow gate of sun.misc.Unsafe, and do not program large arrays as a mathematician on Fortran.

I want to write very low-level code (close to bare metal), and have a performance comparable to native C / C ++. I want GC when necessary, and I do not want GC when not necessary. I want to write in OO style, and in functional. I want to override operations, HOF, and closures. I want generics, maybe I want templates and / or macros to implement some future concepts. I want to understand how all this is implemented in the language, starting with the memory and concurrency models, and to be able to manage these things the way I want.

I want everything at a low level, and I want all the power at a high level comparable to Scala. I want to write code quickly and simply, with the spinal cord (I want the compiler to think for me), and not for the compiler (as happens when programming in Scala or C ++). I want to be productive as a programmer and write programs many times faster than, for example, in Java or JavaScript.

This is such a quick dump from the head (I never recorded them on purpose). But it is clear that I want everything at once, and I’m the first to say that all at once: there is no such language - go to the beach . But he is .

Cross-platform and Close to Bare Metal


I want cross-platform with mandatory compilation in javascript. And not just compilations in JavaScript, but high-performance code in the browser . In addition to all the features of the language that give me the ability to program the UI and client-server interaction, I need a serious number crunching on the client, and grinding a million-different tuples in a fraction of a second is a very desirable requirement. It is possible that the client code will be including a full P2P network, and so on. In short, the requirements for the code on the browser side, no less than for solutions on the server side.

To write something high-performance over a large amount of data in Java, which is possible in JavaScript. Such things are more or less solved by active use of off-heap data structures, which implies either a bunch of generated (with all the hemorrhoids) code, or a miserable kind of programming - technically you are programming in Java, but this is not your mother’s Java, but a miserable subset language. In the world of browsers - the same story with typed arrays and asm.js (keep with you all sorts of NaCl / PNaCl, etc. - not interested).

Theoretically, I can take a lot of things for my tasks: scala - scalajs , go - gopherjs , and most of the JVM-based things (my favorite Fantom , Kotlin , Ceylon ) with JavaScript compilation, provided that I can elegantly use off-heap data when compiled to bytecode, and, accordingly, typed arrays when compiled into JavaScript.

Actually, I walked this path, but, returning to the topic of the article, this is the path against the language. I programmed against the language, or rather the JVM platform, which is essentially orthogonal to the problem being solved, and to solve my problems I need everything that the platform gives, but in a different way and do-it-yourself. I need off-heap memory management, a proprietary system of value types, and in addition to all this working effectively, I need code generation (compile-time and / or run-time). In short, the question arises - why do I need all these languages ​​and platforms (JVM, browser) if they don’t help me, but only get in the way?

JVM Off-Heap Data Structures


Of course, there are many worthy projects in the world that go “against the platform,” I can recommend different sources to those who are interested in the Java context, but you can start with the Mechanical Sympathy blog. In general, these guys have done and are doing a lot of interesting things with the JVM. As for performance, the last post shows how they make ProtoBuf 15-35 times, as for Off-Heap data structures, this post shows an example showing a performance increase of 40 times compared to using (Java) as they say as designed.

Taking this opportunity, I want to mention a little-known to me (I would say a completely unknown project): landz . In which the author actually offers a new platform on top of the JVM with lock-free / garbage-free off-heap memory allocator, lock-free collections, async-await, channels, off-heap collections and the like. Very cool ... You can mention objectlayout.org and a lot more, but all this is very inconvenient, and is done contrary to, and not due to, the design of the platform.

Browsers, asm.js and emscripten


In browsers, emscripten does wonders. For those who are not aware of emscripten - you can play, for example, in Quake3 , a list of ported games (etc.) here . As far as I understand, Unity and high-end game engines are just now engaged in dragging themselves into the browser in this way. Unity generally compiles all its problems including .NET (Mono) runtime in JavaScript (asm.js) using emscripten, but of course this is not the JavaScript you write with your hands - such JavaScript can only be the result of compilation. I have serious doubts that the JavaScript program (as designed) will be somewhere close in comparison with asm.js (meaning number crunching and large amounts of data), and if so, then I want to generate asm.js (and, accordingly , another memory model) where appropriate.

More suitable language? (low level)



A thinking reader will assume that for a comfortable solution of such low-level tasks, completely different languages ​​are needed (and from myself I will add: and platforms), and will be right. I also thought so, and even tried to write my own language - a sort of LLJS , which would be compiled into JavaScript and JVM bytecode, driving bytes back and forth along off-heap memory / typed arrays. By the way, if such a language existed (and LLJS still requires a lot of work), then most likely I would take it and close the question. But then there would not be this article, and, probably, I and would not find the best programming language in the world .

In addition to more suitable languages ​​for the task, I placed great hopes on go, which is pass by value unlike JVM-based, and the memory model in it is simpler and more transparent. But when we start compiling into “traditional” JavaScript (gopherjs), which, as it were, is close to the JVM in the low-level issues that interest me partly - performance sags every 20 (for the sake of interest, you can look at the sadness of the naive dude from the office who decided what the analog React.js is only very fast, because go, and will write a cool UI) ...

Something I have already begun to merge my beloved JVM, but for now it's too early. First you need to understand the high level: Scala and other friends, but this is already in the next part .

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


All Articles