library a;
import "c.dart";
export "c.dart";
class A {}
library b;
import "c.dart";
export "c.dart";
class B {}
library c;
class C {}import "../lib/a.dart" as a;
import "../lib/b.dart" as b;
main() {
var c1 = new a.C();
var c2 = new b.C();
print(c1 is b.C); // prints true
print(c2.runtimeType == c1.runtimeType); // prints true
}import "../lib/a.dart";
import "../lib/b.dart";
main() {
new C(); // Causes "ambiguous reference" error
}--
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
The API exported by b has not changed, yet assuming we considered c legal before, c breaks now because there is a real ambiguity that b has no control over.
The API exported by b has not changed, yet assuming we considered c legal before, c breaks now because there is a real ambiguity that b has no control over.
--
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
I mean, I know now how to use export and that prefixes are used for the special case that b defines its own class C or function f.But why is this behavior so useful to be the default ?Why not an error message in case things are actually ambiguous ?And in Gilads example, why is the ambiguity error not in the exporting lib b that overrides f but instead in the importing library c that uses f from b ?
Of course c can break if b changes.How did this insight change our world view with regard to ambiguities ?
Of course c can break if b changes.How did this insight change our world view with regard to ambiguities ?What changed my world view is the concept of exported symbols becoming part of the imported library's interface. Even though b's implementation did change, it's interface stayed the same. In my original example the fact that the symbol C happens to refer to the same class is an implementation detail, and so it should not "leak" into the user code. If it did, it would restrict the authors of either of libraries a and b to change the implementation, and that would defeat the purpose of having an interface.
Once you start thinking in terms of interfaces, the ambiguity becomes quite clear. C in a and C in b are different interface elements sharing a name, and therefore new C() is ambiguous. In fact, had I read the error message more carefully I might have got that sooner (the full file paths, stripped below, didn't help with readability):'e.dart': Error: line 5 pos 7: ambiguous reference: 'C' is defined in library 'a.dart' and also in 'b.dart'Cheers!
--
@GenDo not expect to get answers to very specific questions.Of your questions and complaints will choose only those that are nice to answer.Topical and reasonable questions will always remain unanswered.Many people (developers) only react when they have something to say.In other cases, they simply remain silent or choose simple and easy questions to answer them.Usually this happens for several reasons. At least two of these are valid.1. Silent when unpleasant to admit that this is not what others want.2. Just no reasonable answers to reasonable questions.When you long to explain the simple thing as did Gilad then I think that it's actually not that simple.And perhaps no one needs. Because everyone else perceive it in other manner (simple than this want Gilad).Sometimes coming up with a very interesting but totally useless things.Why should anyone worry about me that if I do something to change that I will break compatibility.There are other ways around this problem.I do not understand why to avoid this problem is to "make a fuss"?Something that can be used daily sacrificed of what will occur very infrequently?Also my personal opinion about Smalltalk language.1. Old language which is not used anywhere2. Not to focus on the "dead" languages but adopt lively and popular. Such as Java and C #.
If "don't export libs that can be imported by anyone else" is true
I mean, is it an alternative to "part" for tighter visibility?
>> I still have one doubt. If "don't export libs that can be imported by anyone else" is true, what is export for? I mean, is it an alternative to "part" for tighter visibility? Does it have implications for browser downloading, speed? In other words: when should I use part and when should I use import+export?
Read Dart documentation.1. You might have a huge library that you implement as a set of smaller libraries (that you and only you control).2. You might create a library that provides a subset of methods from another library (that you and only you control).
Re-exporting libraries
You can combine or repackage libraries by re-exporting part or all of them. For example, you might have a huge library that you implement as a set of smaller libraries. Or you might create a library that provides a subset of methods from another library.
пятница, 7 июня 2013 г., 13:58:51 UTC+6 пользователь Iván Zaera Avellón написал:
>> @mezoni Where is that in the documentation? I googled for it and only find it in the book "Dart: up and running" :-o.
I do not knew about it. And I do not know now.I do not care about the fact that this is a chapter from the book.The main thing that this information offered on the official Dart site in the "docs" folder.So it's documentation (I assume).
>That's the only safe usage of export that I know of. There are people who prefer to compose libraries from smaller libraries>that are considered private (typically one library per file). In that case, export makes sense.That's exactly what I had in mind so I suppose it confirms my assumptions about how import, export and part have to be used.