Book Image

Learning Dart, Second Edition - Second Edition

By : Ivo Balbaert
Book Image

Learning Dart, Second Edition - Second Edition

By: Ivo Balbaert

Overview of this book

Table of Contents (18 chapters)
Learning Dart Second Edition
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Variables – to type or not to type


In our first example (raising rabbits) in Chapter 1, Dart – A Modern Web Programming Language, we started by declaring a rabbitCount variable dynamically with var. Then, in the second version, we gave it a static int type (refer to the prorabbits_v1.dart and prorabbits_v2.dart files in Chapter 1, Dart – A Modern Web Programming Language) and concluded that typing is optional in Dart. This seems confusing and it has provoked a lot of discussion: "is Dart a dynamic language like Ruby or JavaScript, or a static language like Java or C#?" After all, some of us were raised in the (static) belief that typed variables are absolutely necessary to check whether a program is correct, a task mainly performed by the compiler (however, the Dart VM has no separate compiler step, and dart2js, the Dart to JS compiler, doesn't check types because JS is fully dynamic).

It turns out that no mainstream language actually has a perfect type system (static types don't guarantee...