23

In other languages (like Python, Go, C#, etc.), circular imports are an issue and the program doesn't run. However, Dart seems to get around this issue and different Dart files can import each other. I am curious about how Dart handles this, and to get to know if there are any gotchas about it.

I tried searching online but couldn't get anything meaningful.

MendelG
  • 14,885
  • 4
  • 25
  • 52
Dinanjanan
  • 399
  • 2
  • 11
  • I think Dart's compiler just copies all code into a single file, and just compiles that one file, so it doesn't have to deal with multiple files. – Ali Qanbari Apr 15 '21 at 06:57

1 Answers1

16

Usually, the circular dependencies are allowed for languages using a multi-pass compiler.

The logic behind it is that the compiler parses and analyses the code multiple times, and generates intermediate code after each stage.

About Dart, the VM offers a Just-In-Time (JIT) and an Ahead Of Time (AOT) compilers as explained here, which also work with intermediate code.
I didn't play much with Dart's compiler but I guess the implemented logic is the one of a multi-pass compiler

FDuhen
  • 4,097
  • 1
  • 15
  • 26