'Samuel Rawlins' via Dart Misc
2018-07-12 17:02:35 UTC
Hey Dartisans (+Bob for Effective Dart comments),
It is common to import packages with many top-level constants and functions
with a prefix, e.g.
import 'dart:math' as math;
import 'package:path/path.dart' as p;
void main() {
print(math.sqrt(2));
print(p.join('foo', 'bar'));
}
And I didn't use to import dart:convert with a prefix, because I use
classes (like JsonDecoder). However, with all constants now lower-case in
Dart 2, I think I want to start importing libraries such as dart:convert
with a prefix, maybe even with show directives.
Another reason is that these lower-case constants clutter up the scope with
things that look like local variables I never declared.
WDUT?
import 'dart:convert';
void main() {
print(ascii.decode([97, 98, 99])); // Wait, where did I declare an
`ascii` variable?
var manyJsonDocuments = getDocs();
for (json in manyJsonDocuments) { // I accidentally forgot `var`, but
now get a weird error about reassigning a constant?
...
}
}
import 'dart:convert' as convert;
void main() {
print(convert.ascii.decode(...));
}
import 'dart:convert' show ascii;
void main() {
print(ascii.decode(...)); // still not super obvious where ascii came
from but... you can scroll up to imports and its in your face.
}
// or both prefixed and show?
It is common to import packages with many top-level constants and functions
with a prefix, e.g.
import 'dart:math' as math;
import 'package:path/path.dart' as p;
void main() {
print(math.sqrt(2));
print(p.join('foo', 'bar'));
}
And I didn't use to import dart:convert with a prefix, because I use
classes (like JsonDecoder). However, with all constants now lower-case in
Dart 2, I think I want to start importing libraries such as dart:convert
with a prefix, maybe even with show directives.
Another reason is that these lower-case constants clutter up the scope with
things that look like local variables I never declared.
WDUT?
import 'dart:convert';
void main() {
print(ascii.decode([97, 98, 99])); // Wait, where did I declare an
`ascii` variable?
var manyJsonDocuments = getDocs();
for (json in manyJsonDocuments) { // I accidentally forgot `var`, but
now get a weird error about reassigning a constant?
...
}
}
import 'dart:convert' as convert;
void main() {
print(convert.ascii.decode(...));
}
import 'dart:convert' show ascii;
void main() {
print(ascii.decode(...)); // still not super obvious where ascii came
from but... you can scroll up to imports and its in your face.
}
// or both prefixed and show?
--
For more ways to connect visit https://www.dartlang.org/community
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.
To view this discussion on the web visit https://groups.google.com/a/dartlang.org/d/msgid/misc/CACshfx1HUQsW_qhBvVQYYpVsahztZOsSk%3DS3hb5FieWxhHFGzA%40mail.gmail.com.
For more ways to connect visit https://www.dartlang.org/community
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.
To view this discussion on the web visit https://groups.google.com/a/dartlang.org/d/msgid/misc/CACshfx1HUQsW_qhBvVQYYpVsahztZOsSk%3DS3hb5FieWxhHFGzA%40mail.gmail.com.