Sean McCleary
2016-09-15 21:54:26 UTC
Hello all,
I've got a suggestion for the dart style guide, and I'm not really sure
where to pitch it. If I ought to take this somewhere else, someone wanna
point me in the right direction?
Specifically, it's about this rule: "DONâT type annotate initializing
formals."
The example in the documentation shows this as the correct way:
class Point {
int x, y;
Point(this.x, this.y);
}
That's fine. If you wanna tell me it'd be redundant or error-prone to
repeat the type of x and y, then OK. A consumer of the Point class can
clearly see, via the class's public interface, what the type of "x" and "y"
are.
However, when the class members are private, that's not the case. Consider
this:
class DemoClass {
String _someVar;
/// Instantiates a DemoClass
DemoClass(this._someVar);
}
In this example, _someVar is a private class member. As a consumer of this
class, I should not have to look at its private implementation details in
order to know the expected type of the constructor parameters. The method
signature of the constructor should provide me with that information.
Sure, dart's an interpreted language, so I could crack open the DemoClass
file and hunt through its private members to find the type of _someString.
Or, if the author of the class was kind enough to provide some generated
documentation, I could go look it up there. Or I could use the analysis
server to maybe not even worry about it.
But that all seems very out of line with (what I understand to be) dart's
philosophy -- that code should be clear in order to facilitate the building
of large applications by large teams. Having to dig through the code of a
class or module just to be able to use it because it doesn't provide a
clear public interface, or having to rely on external tools, is the kind of
thing that I think drives people _away_ from languages like JavaScript and
hopefully _towards_ dart.
So anyway, there's my suggestion.
Sean
I've got a suggestion for the dart style guide, and I'm not really sure
where to pitch it. If I ought to take this somewhere else, someone wanna
point me in the right direction?
Specifically, it's about this rule: "DONâT type annotate initializing
formals."
The example in the documentation shows this as the correct way:
class Point {
int x, y;
Point(this.x, this.y);
}
That's fine. If you wanna tell me it'd be redundant or error-prone to
repeat the type of x and y, then OK. A consumer of the Point class can
clearly see, via the class's public interface, what the type of "x" and "y"
are.
However, when the class members are private, that's not the case. Consider
this:
class DemoClass {
String _someVar;
/// Instantiates a DemoClass
DemoClass(this._someVar);
}
In this example, _someVar is a private class member. As a consumer of this
class, I should not have to look at its private implementation details in
order to know the expected type of the constructor parameters. The method
signature of the constructor should provide me with that information.
Sure, dart's an interpreted language, so I could crack open the DemoClass
file and hunt through its private members to find the type of _someString.
Or, if the author of the class was kind enough to provide some generated
documentation, I could go look it up there. Or I could use the analysis
server to maybe not even worry about it.
But that all seems very out of line with (what I understand to be) dart's
philosophy -- that code should be clear in order to facilitate the building
of large applications by large teams. Having to dig through the code of a
class or module just to be able to use it because it doesn't provide a
clear public interface, or having to rely on external tools, is the kind of
thing that I think drives people _away_ from languages like JavaScript and
hopefully _towards_ dart.
So anyway, there's my suggestion.
Sean
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
---
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.
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
---
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.