Dart, Byzantine Languages pt. 1
Why is Dart a Byzantine Language?
Dart wasn't born with types. It was born to replace JavaScript (JS) but wasn't any better than JS when it was born, because very quickly ES6 made the improvements Dart had over JS disappear. Then TypeScript gained ascendance as types help get a handle on large JS databases. So types were added to Dart... and Dart seemed to be ready for the graveyard of fringe languages like Pony, Prolog, and Idris.
But Google didn't give up on it. Dart kept evolving but like a Bazar, it evolved by adding things like it added types. So when you look at Dart you see many design decisions in the language are in conflict. It's a packed language, with lots of things. Its syntax was extended to use types and it's lightly based on C, quite possibly the most popular language historically but also one that largely succeeded in-spite of its syntax not because of it.
What's good about Dart?
The VM. The virtual machine that runs the language is fast and great. And it was chosen as the basis for Flutter a toolkit that allows rapid development of mobile apps both for Android and iOS while sharing the same code base (mostly). Notice that its main strengths are not the language per-se but its virtual machine.
Byzantine features
The Byzantine nature of the language can be seen in the names of its types. It's got String, RegExp but then num, int, and double. It's got List, Set, and Error but bool. There is no uniformity of types. Additionally, a type like Map which is a hash-map contains elements of the MapEntry type, clearly showing this was added on, not part of the design of the types.
Some features come from C but seem out of place in a modern language. It uses the semicolon as a terminal thing, but only sometimes. This inheritance from C is one of my most hated features. Then it also has the abysmal C-style-for-loops which JS is moving away from. They're terrible because a small typo will make it not work as intended. In a C-style-for-loop you have to declare a variable to count the number of times the loop is going to go, then set a condition for termination, then the increment. It's boilerplate the language itself should take care of for the programmer but in Dart, you have to watch your for-loops like a hawk. Thankfully there are comprehensions for collections but they don't have the same flexibility as the for-loop.
My favorite byzantine feature is the double dot operator (..). Some functions like sort for example change the object in place and return void (nothing basically) so you can't chain a method because void isn't the object you want to call the next method on. Well, Dart's got a solution for that, it has a double dot operator that passes the original object rather than the resulting object. However, this is operator is put in front of the call, so you put "..sort()" in order to get the original object sorted rather than void returned. If you want to chain something after that though, you'll need to wrap the first part in parenthesis, so the double dot operator returns the original object before continuing. This is an interesting solution in that it works but it looks horrendous on the code base making it hard to read at first and definitely doesn't look like anything in other languages.
Weird features that are cool.
Not everything unusual in Dart is bad, but it's good to know what they are because previous experience in other languages can trip you up.
I like that Dart allows trailing commas in Lists, in fact, it's the preferred way to write them. How many times have I deleted the last element in an Array and then caused a crash because the last element had a comma and that language didn't know how to handle that. Dart's got you covered.
Instantiating an object doesn't require the 'new' keyword. Simply call the class name (which is also the name of the constructor) feed it the parameters and boom. Its simplicity makes you want it in other languages.
The absolutely worse thing about Dart, though:
Dart lacks a REPL, or an interactive command-line utility. This means it's hard to figure out all the nooks and crannies of this language.
Comments
Post a Comment