The story of why I chose Dart to help the RICOH THETA Developer community I am involved with may help you assess if you want to invest the time to learn the language to help your organization. The fantastic part about using Dart is that the language is simple to learn and is capable of handling some of the newest and most trendy programming paradigms. It’s fun.
Starting With curl and Bash
We all start with curl. It is simple, fast, and we can send our friends working scripts built with curl in email or post them in a forum. Everyone either has curl installed or can install it easily. MacOS, Windows, Linux people all understand and use curl.
Here’s an example of a simple curl command.
It is also easy to put the curl commands in a Bash script. Bash runs on Mac and Linux easily. Thanks to WSL2 from Microsoft, you can also expect people using Windows to be familiar with Bash. Realistically with the prevalence of Linux on cloud-based servers, there is no problem sharing Bash scripts with people as most people understand Bash or can search for information on Bash.
Let’s contrast this with Dart. Realistically, I expect no one else to use Dart. This is a significant downside. Obviously, I want to share my tests with other people to show that a system is working. I can’t share Dart tests easily. I understood the limitations of Dart before moving. Let’s look at why I moved to Dart.
The Problem With Bash and curl
The main reason I looked for an alternative to Bash is that there’s some benefit if I can test the API from iOS and Android to see if there is something specific to iOS or Android that is causing a problem. For example, the RICOH THETA camera I test sends out MotionJPEG that displays a live video stream on a mobile phone. Although I can capture the individual frames from the command line and test the API that way, it is nicer to show people that the video is working on a mobile app.
5 Advantages to Using Dart
1. Same Dart Scripts Work in iOS and Android Native Apps Without Modification
There are also conditions where I want to test multiple API commands in sequence and it is nice to show the sequence on a mobile phone.
In the next example, I’m using the exact same files from the command line tool backend library in a basic Flutter app.
Sharing Dart Tests
Although it is nice to show people tests on a mobile phone, my primary focus is on command line tests. I actually don’t need to show the API working on mobile phones that often. Although most people build mobile apps on iOS and Android, my tests of the API, are usually on a Windows 10 machine. For example, I’ll take 1,000 pictures in rapid sequence or take a set of 7 pictures with different shutter speed values.
The tests are sharable as a sequence of steps, not actual code. In the example below, it’s possible to use pseudocode to make a point.
For people that want to replicate a precise test, I publish the following tools with source code:
In the example below, I’m running a Dart script with roughly the same ease as running python
bash main.sh or
The word ‘info’ is the argument I am passing my application.
dart bin/main.dart info
I’m using the Dart args package, which is as used to build command-line interfaces as tools for other languages. Once I had roughly 50 individual Dart test scripts built up slowly over 6 months of on-and-off testing, I integrated the scripts into a library. I then built a command-line interface for the library.
2. Compile to Self-contained Snapshot
The Dart scripts can compile to self-contained snapshots that run on Linux, Mac, and Windows without requiring any other programs or libraries. On my GitHub releases page, I have binaries for those three platforms plus Raspberry Pi ARM to allow robotics and DIY developers easier access to the tools. In the example below, the Raspberry Pi archive is larger because I included more images in the documentation.
Although this type of distribution is possible with other languages, it is fast and easy with Dart. The binaries are also nice and small.
3. Static Typing, Finding Errors, and Optimization
4. Null Safety and Reducing App Crashes
The network is a finicky beast. You never know what you actually receive. Humans can also forget to assign values to variables. Often, an app will crash when it tries to read in data such as a GPS coordinate from an object and the GPS coordinate variable is blank. It is null and null won’t work. The app crashes and often doesn’t give very good debugging information as to the source of the problem.
Languages like Kotlin and Swift have similar null safety features. Although it’s possible to add these features to other languages, it’s usually not the default or common way to manage variables.
As of Dart 2.12.0, null safety is optional. Dart is moving toward null safety as the default style.
This is another helper feature for the ‘average’ programmer like me. The feature, like static typing, protects me from my own errors. I like this because the reality is that I’m not a great programmer and can be more productive with tools that find my own errors.
5. Dart is Supported by Google
As Dart is the least popular out of the languages I covered in this article, it’s important to me that a big company is committed to the success of Dart. I believe the support of Google helps with a frequent update cycle and fairly good management of bug fixes. Support for Dart and Flutter in editors like VS Code is excellent. Support in Android Studio is also excellent.
Disadvantages of Dart
While I like Dart, it’s fair to point out the disadvantages of Dart and Flutter. Realistically, most people using Dart will also use Flutter.
Dart is great for command-line applications. It’s more than just the language for Flutter. I’m very happy with Dart as a language and I can also use the same command-line scripts in other applications such as iOS and Android applications or desktop applications. Most of the same code can also be used in web applications, depending on the network requirements of your application.
Dart is a simple language. It has enough features to build complex applications using modern paradigms. There is nothing revolutionary about Dart. It will likely seem familiar even if you’ve never used Dart before.
Bash is easier to use for small applications, but Dart is easier for more complex applications. It’s more difficult to get Python on mobile and web applications compared to Dart.
While Flutter is getting all the media attention, I recommend using Dart alone and discovering the beauty of this simple language.