Clean code in Dart
Effective Dart: types in UpperCamelCase, every other name in lowerCamelCase, constants included, files in lowercase_with_underscores, lines of 80 characters or fewer, braces on every if and loop, and dart format for the layout.
What does Effective Dart ask for?
DO name packages, directories, and source files using lowercase_with_underscores
source
From Effective Dart: Style.
What does cleaner Dart look like?
// CartScreen.dart
const MAX_ITEMS = 20;
class cart_screen {
List<CartItem> l = [];
void add(CartItem i) {
if (l.length >= MAX_ITEMS) throw StateError('full');
l.add(i);
}
}// cart_screen.dart
const maxItems = 20;
class CartScreen {
final List<CartItem> items = [];
void addItem(CartItem item) {
if (items.length >= maxItems) {
throw StateError('The cart holds $maxItems items at most.');
}
items.add(item);
}
}Other languages
More on clean code: comments, functions, naming and the checklist.