Dart is a browser based language. That is, it's designed to run in your browser like Javascript already does. Unlike Javascript however, Dart does not currently in in a browser. One day Dart may be added to browsers so it runs natively, but until that happens you need to find an alternate way to run Dart. Luckily the Dart developers have come up with a way to do just that by creating tools that converts Dart code to Javascript.
Goals of Dart
Dart was developed because of perceived issues with existing browser based languages. In reality there's really only one browser based language, so these perceived issues are really issues with Javascript.
- As applications get larger they get more difficult to maintain. On top of maintaining the code, other problems such as testing become apparent. Dart attempts to prevent this by allowing the developer to create well structured and maintainable code. In addition, because you can run Dart from the command line it's possible to write testing harnesses the can execute as part of your development process
- Like all mature languages, Javascript has grown up over time and can be seen to lack certain features or the features have to be implemented in a non-standard way. Dart takes inspiration from many languages and adds a number of useful features that developers will find useful.
- Dart is designed to be a very fast language with high performance
Features of Dart
Dart has many new and interesting features, many of which exist in existing languages. Don't worry if you don't understand some of these terms, we'll get to those as we go.
Optional typing of variables
By default a variable can be of any type e.g. an integer, a string, a float and so on. If your variables are untyped you can have a variable that is a number, then change it to a string and there's no issues. As your scripts become more complicated, this may be unwanted and even lead to bugs. By typing your variables you're saying that your variable is a number and nothing else. This means that you can't inadvertently assign something else to it.
Interface and Class definitions
Classes are the cornerstone of any modern programming language. Dart provides not only a robust Class syntax but also provides Interfaces (a sort of super class) along with inheritance which allows you to extend existing classes
Libraries
As your code becomes more complex, you can split functional blocks in to multiple files. This allows you to re-use features and helps with maintainability. You can also split your testing up so you test each set of functionality individually.
String Interpolation
This might seem simple but it can be incredibly useful as a time saver. You can use your variables directly inside other strings. You can even perform other actions such as applying methods directly within your string.
Concurrency and Isolates
By default, Dart in single threaded. however you can implement concurrency using a feature called isolates. Isolates have their own memory and run independentl and you can securely pass data in and out of a isolate.
Factories
Factories are a way to allow you so create a class "on the fly" by protecting you from the details of how to actually create the class. For example you may have to call two different classes that do two very different things but happen to share the same methods. The problem becomes worse if you have to choose the right class based on some dynamic condition. You could instantiate each class yourself or you could simply have a factory you call with a parameters and the factory will instantiate the right class for you and pass you back the object. That way your program doesn't need to know which class it's using, it just nows it has a object it can now call methods on.
There's many more subtle features we'll get to along the way.
No comments:
Post a Comment