preface

I wrote several articles in the last couple of days about the advantages of Dart for back-end development, such as:

Dart Development Server, Do I have a fever?

Persistent fever, Dart language asynchronous operation, 500% efficiency increase

Dart Language Concurrency challenge Go?

If you haven’t seen it, you can take a look.

Today, we’ll talk about another big advantage of Dart, which is static compilation. Should PHP and Python throw in the towel and Java and Go sit on the sidelines?

Notice in advance, content slightly dry, please bring your own mineral water.

What compilation methods are supported by the Dart language

The current mainstream development languages generally support EITHER JIT mode, AOT mode, or both.

Take care of little white. Explain the noun a little bit

JIT is just-in-time, real-time compilation, referred to as interpretation type. In a simple way, it refers to compiling code while running the code after the code is run. The advantage is convenient for development and debugging, but the disadvantage is that the execution efficiency is not very good

AOT is ahead-of-time, pre-compiled, or compiled for short. It simply means that the code is compiled before it runs. It has the advantage Of high execution efficiency, but it is not friendly to development and debugging

The dominant backend languages, in practical terms:

PHP and Python are all interpretive, and when it comes to actual development, the code is pretty cool, but it’s always complained about low performance

Java, go are compiled, always complain that compile once, go out to fight is not over, I am talking about Java

Faced with such a situation, witty students see that the development of the use of JIT mode, the operation of the use of AOT mode is not good, development and debugging is convenient, the execution efficiency is also high?

Not bad. You’re smart, young man. You’re right. Dart does the same thing.

How do I compile programs written for Dart

After you have written your application using Dart, you can use the Dart compile command to compile the final file

For example, run the following command to compile an EXE file

dart compile exe bin/main.dart
Copy the code

You’ll get main.exe, which can run directly on the Win platform, but it won’t run under Linux

Can it be compiled into a file that is universal, that is universal across platforms? B: Sure.

Run the following command

dart compile kernel bin/main.dart
Copy the code

The resulting main.dill file is a binary file that can be used on all platforms and all CPU architectures.

Familiar with go students a blank face, copy mine?

Of course, you can also run the following command to compile it into an AOT file

dart compile aot-snapshot bin/main.dart
Copy the code

One downside is that aOT files compiled for the Win platform cannot be used under Linux.

For the same reason, Linux compiles cannot be used in Windows.

Of course, the best thing about it is that it has the best performance, so it is also the most recommended.

Anything else you want to add

There is.

There is a special reminder about compiled pages in the official Dart documentation

https://dart.dev/tools/dart-compile
Copy the code

This is the page, with this description, be sure to note:

The exe and aot-snapshot subcommands have some known limitations:
...
No support for dart:mirrors and dart:developer
...
Copy the code

Exe and AOT modes have some limitations, such as:

Dart: Mirrors are not supported Dart: Developer tools are not supported

Some students may write basic add, delete, change and check every day, I don’t know what reflection is used.

In fact, it is very useful, including SpringBoot framework in the Java field, Laravel framework in the PHP field, in the actual operation, need to use the reflection function, to obtain the attribute information of the running class, method information, to complete some automatic processing.

However, Dart disables reflection, which is a major inconvenience for framework writing.

Of course, Dart’s reasons for disabling reflection are that the library is not yet stable and that it improves performance.

Yeah, I believe you.

conclusion

Dart is compiled in a mainstream way, with ease of use and performance taken into account, and no rigor, unlike PHP, which has been criticized for this, paving the way for back-end development.

Along with the other two features I improved at the beginning of this article, asynchrony and concurrency, Dart is my primary recommendation for my company.

Dart is a better backend developer than Java.

We’ll talk about that later.