2022-11-10
1386
#typescript
Will Soares
137462
Nov 10, 2022 â‹… 4 min read

Comparing Dart and TypeScript

Will Soares I'm a front-end developer and writer based in Porto, Portugal. For more posts, check out willamesoares.com.

Recent posts:

Rust logo over black marble background.

Handling memory leaks in Rust

Learn how to manage memory leaks in Rust, avoid unsafe behavior, and use tools like weak references to ensure efficient programs.

Ukeje Goodness
Nov 20, 2024 â‹… 4 min read
Robot pretending to be a person.

Using curl-impersonate in Node.js to avoid blocks

Bypass anti-bot measures in Node.js with curl-impersonate. Learn how it mimics browsers to overcome bot detection for web scraping.

Antonello Zanini
Nov 20, 2024 â‹… 13 min read
Solving Eventual Consistency In Frontend

Solving eventual consistency in frontend

Handle frontend data discrepancies with eventual consistency using WebSockets, Docker Compose, and practical code examples.

Kayode Adeniyi
Nov 19, 2024 â‹… 6 min read
How To Use Lazy Initialization Pattern With Rust 1.80

How to use the lazy initialization pattern with Rust 1.80

Efficient initializing is crucial to smooth-running websites. One way to optimize that process is through lazy initialization in Rust 1.80.

Yashodhan Joshi
Nov 18, 2024 â‹… 5 min read
View all posts

2 Replies to "Comparing Dart and TypeScript"

  1. In the language comparison, it looks like Dart takes twice (16) as many lines of code than TypeScript (8). But that’s because the implementations are different. The Dart code can be greatly simplified to look like a 1 to 1 match of the TypeScript code:

    “`dart
    import ‘dart:math’;

    int multiply(int a, int b) {
    return a * b;
    }

    void main() {
    int a = Random().nextInt(10);
    int b = 3;

    print(‘$a * $b = ${multiply(a, b)}’);
    }
    “`

    Now it takes the same number of lines as the TypeScript counterpart: 8, excluding the import and the wrapping main function, which are indeed an unavoidable.

    1. Hey wilsonsilva, thanks for your comment. It’s good to see how that code can be altered to look more compact.

      The comparison in the post though was targeted at showing the differences in syntax between the two, rather than which one needs more lines of code.

      Again, appreciate your feedback and I hope the post helped with giving you insights on the two languages.

Leave a Reply