Overview of the Dart programming language
Dart is an object-oriented, client-optimized programming language developed by Google (first released circa 2011). Originally designed as a modern alternative to JavaScript for large-scale frontend applications, it has evolved into a general-purpose language primarily used for cross-platform development with Flutter.
Key Use Cases
- Client Applications: Powering Flutter for mobile (iOS, Android), desktop (Windows, macOS, Linux), and web.
- Web Applications: Compiles Dart code to JavaScript for browser execution.
- Backend and CLI: Native compilation (AOT) into machine code for microservices and command-line utilities.
Technical Characteristics
- Type System: Features static and sound null safety, separating nullable and non-nullable types to reduce runtime errors.
- OOP Model: Everything is an object. It supports classes and interfaces (via abstract classes and
implements). While it lacks multiple inheritance, it providesmixins(viawith) for behavior composition. - Concurrency Model: Uses a single-threaded event loop by default. Asynchrony is handled via
async/await,Future, andStream. For true parallelism, Dart uses Isolates—separate execution environments with their own memory and a message-passing communication model (no shared state). - Compilation Strategies:
- JIT (Just-In-Time): Enables fast builds and "hot reload" during development.
- AOT (Ahead-Of-Time): Compiles to native machine code for high performance and fast startup in production.
- JS Compilation: For web targets.
- Ecosystem: Uses
pub.devas the central package manager and repository.
class User {
final String name;
final int age;
User(this.name, this.age);
void greet() {
print('Hello, my name is $name, I am $age years old.');
}
}
Future<void> main() async {
final user = User('Alice', 30);
user.greet();
final data = await fetchData();
print('Data: $data');
}
Future<String> fetchData() async {
// simulate asynchronous operation
await Future.delayed(Duration(milliseconds: 500));
return 'OK';
}