How difficult is it to design a programming language?

Author | DAVID CASSEL

Translator | Crescent Moon, Editor in Charge | Zheng Liyuan

Title Map | Self Vision China

Source | CSDN (ID: CSDNnews)

Recently, Yukihiro Matsumoto, the founder and chief designer of the Ruby programming language and chief Ruby architect of Heroku, a cloud platform-as-a-service company, said in a speech that the Ruby community led by Yukihiro Matsumoto had in-depth thinking about the development of the programming language. The 30-minute speech also mentioned that the programming language is about to usher in exciting new developments.

Matsumoto said: "For the past four or five years, I have been talking about the future of Ruby 3. Maybe many people are tired of this cliché. But this year Ruby 3 is really coming. On December 25th, Ruby 3 will be Official release.” It’s a tradition to release Ruby language upgrades on Christmas Day.

"If all goes well, we will officially release Ruby 3 in December, unless there is a very bad accident."

The designer's dilemma

Hundreds of viewers from all over the world (from India to Indonesia, from Brazil to Berlin) watched Matsumoto's live broadcast, and many people made enthusiastic comments. They gathered to watch Matsumoto's speech, who has devoted 25 years to the development of Ruby. It is said that Ruby 3 was originally planned to be launched on the eve of the Tokyo Olympics, but since the Olympics were postponed to 2021, the core developers doubted whether Ruby 3 should also be postponed for a year.

"But after some discussion, we decided to release Ruby 3 this year, because as an open source community, we must move forward. We must keep moving forward. The open source community usually cannot stop developing, otherwise, we will face death...".

Matsumoto deeply described the dilemmas faced by all language designers. "Everyone likes new things, so as a programmer and engineer, I also like new things. In addition, I like languages ​​very much, so I like to study new programming languages, such as Elixir, Rust, Go, etc. I am very excited." However, this has also put pressure on the Ruby language change. Matsumoto said: "Ruby is a bit old, it was released in 1995. We are just mortals. We made some mistakes. So as language designers, we hope to correct the mistakes of the past."

But at the same time, "No one wants to experience pain." With all web applications using existing versions of Ruby, it’s a bit dangerous to force developers to upgrade. "No one likes pain. In this sense, Ruby should It's stable. This seems a bit contradictory, right?"

"Therefore, the design of the Ruby language and the language plan are difficult to overcome this contradiction. This contradiction is from our heart."

He described other programming languages ​​facing similar difficulties, including Python, PHP and ECMAScript, and pointed out that it took many years of hard work for these communities to get everyone to accept these changes. For example, Python 3, the community has spent more than ten years, and PHP 6 has even been cancelled. They abandoned major changes before release, and then jumped directly from PHP 5 to PHP 7. EMCAScript4 was also cancelled.

Matsumoto explained that if changes are not made, people may leave the community. "They will stop using Ruby because they are bored." But at the same time, he is also worried that if the pain of upgrading to a higher version is too much, then they may also leave the community because they will decide "Maybe our next project should Use Rust, Go or other programming languages."

"Therefore, it is difficult to design a language, but we must move forward anyway to create the future."

Let Ruby revive

In the speech, Matsumoto also outlined plans to maintain compatibility while "speeding up Rust and improving the efficiency of Ruby programmers." He identified three clear and specific goals, which represent the upcoming Ruby 3 Features: fast, concurrent and correct.

To speed up Ruby, the development team will set out to improve its JIT compiler (used to generate native code). In order to achieve concurrency, they did not choose a solution in other languages, but intended to try their own method. Node.js added Promise to notify the completion of asynchronous operations, while ECSMAScript 7 added a control mechanism with keywords async and await, but Ruby 3 will implement the long-awaited asynchronous i/o function "fiber", as a more A good way to control asynchronous threads. "Because switching context between fibers is fast, performance can be improved."

They believe that another reason this method can improve performance is that it was developed by the creator of Ruby's falcon application server, and Matsumoto believes that this project is very fast. But this is not the only way they can improve performance. They also implemented "Ractor" (Ruby Actor), similar to the way JavaScript provides the script behind the "Web worker". Each Ractor can run in parallel, Matsumoto explained, which takes advantage of parallel processing in modern multi-core systems.

The third goal of Ruby is correctness. This goal refers to the early detection of errors, which is mainly implemented by the type analyzer. It will generate Ruby signatures (Matsumoto compares this to the d.ts file describing the type in TypeScript). Ruby 3 will provide type signatures for its core library, which can be used for type checking and can also be used to enhance future IDEs.

But it also has its limitations. Matsumoto explained: "We do not pursue the completeness and rationality of the type system, because Ruby is Ruby. Ruby is basically dynamically typed, which means that even if we now have a progressive type system, we cannot do anything completely correct. Type checking, so we can only give up. We will not add type declarations to the grammar."

Three new functions

The syntax of Ruby 3 has undergone some changes. Matsumoto is very satisfied with the three new features. He said: "Ruby will get better and better. The first is the complex pattern matching syntax. You don't need to deconstruct arrays and hashes because you can write patterns, which is very easy."

The second new function can assign values ​​to the variables on the right side of the equal sign. He said that although we may feel a bit "unnatural" from the appearance, the IDE will be a bit uncomfortable, because general expressions start with variables, even if the value is assigned to a long code block. "If you can turn the assignment into an rvalue operation, it would seem natural, but we don’t recommend it everywhere. You don’t have to replace every assignment operation with rvalue assignment, but in some cases , It’s very convenient."

The third new feature in Ruby 3 is numbered block parameters, "You no longer have to name temporary local block parameters."

Matsumoto said: "Stability is important", so he did not say that there will be any major grammatical changes after Ruby 3. Instead, they will focus on improving Ruby's existing support tools, such as Solargraph for language server protocols, Sorbet for static type checking, and Rubocop to help developers write code that conforms to the Ruby specification. "These tools prove that the better the tool, the better the user experience. Therefore, we must continue to work hard. I think we need more tools, and then we also need to improve these tools." Matsumoto also hopes to see better Type checking tools and formatting tools, or better performance tuning and debugging tools. In addition, Matsumoto has some other ideas on how to speed up Ruby, such as setting up another lightweight JIT compiler on top of the virtual machine, such as MIR or DynASM.

Lighter Ruby

Finally, in the discussion about Ruby 3, Matsumoto also mentioned another idea: "Although this is just a crazy idea, but I am considering a more lightweight Ruby subset, this subset is not only simpler and stricter. , And it’s faster or easier to optimize."

This Ruby subset is backward compatible, that is, it can run in all existing Ruby versions (although not all versions of Ruby can run in this lightweight Ruby). In explaining its basic principles, Matsumoto showed a slide that read: "This lightweight Ruby runs faster." He said: "This is just a preliminary idea. It's not very clear. We Compatibility must be maintained, but if we stop at this Ruby subset, it may lack flexibility, but it should be easier to optimize." 

Matsumoto also said: "I have a lot of crazy ideas, we will try them one by one to make Ruby better and better."

Original link:

https://thenewstack.io/ruby-creator-yukihiro-matsumoto-on-the-challenges-of-updating-a-programming-language

更多精彩推荐

Guess you like

Origin blog.csdn.net/dQCFKyQDXYm3F8rB0/article/details/108675044