What is the purpose of the 'library' keyword?

746 views
Skip to first unread message

Gonzalo Chumillas

unread,
Sep 13, 2014, 10:57:12 AM9/13/14
to mi...@dartlang.org
Hello Everybody,
Maybe this is a silly question, but I'm newbie in this language :)  What is the purpose of the 'library' keyword? When I create my own library, it starts with the 'library' keyword:

library my_library;
// ... classes and functions here

but when I want to import the previous library, I do not use 'my_library'. Instead, I use the path to my library file:

import 'package:my_project/my_library.dart'

so, what is the purpose of the 'library' keyword?
Thanks so much.

Lasse R.H. Nielsen

unread,
Sep 13, 2014, 11:18:40 AM9/13/14
to mi...@dartlang.org
It really is just to give a name to the library, so that library parts can start with "part of library.name;".
The system can give a warning if you import two libraries with the same name (which could be a sign that you import the same library via two different paths).

It's not used for anything else.
/L

--
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

To unsubscribe from this group and stop receiving emails from it, send an email to misc+uns...@dartlang.org.



--
Lasse R.H. Nielsen - l...@google.com  
'Faith without judgement merely degrades the spirit divine'
Google Denmark ApS - Frederiksborggade 20B, 1 sal - 1360 København K - Denmark - CVR nr. 28 86 69 84

Gonzalo Chumillas

unread,
Sep 13, 2014, 11:23:41 AM9/13/14
to mi...@dartlang.org
Thanks.

Mike

unread,
Sep 13, 2014, 7:46:52 PM9/13/14
to mi...@dartlang.org
Very slightly related question: If I want to use the Dart Editor to develop some class files for use in multiple projects, do I create a separate project for each file and then import the class file into each project that needs it? I think that's right because the "part"/"part of" syntax is only used for breaking libraries into multiple files (each "part of" just one library I assume)?

Günter Zöchbauer

unread,
Sep 14, 2014, 3:12:50 AM9/14/14
to mi...@dartlang.org
All you need to do to be able to reuse classes in different projects is to put the library files in the lib directory of your shared project (and don't make the classes private of course).
You can have as many libraries in a project as you want and you can import as many libraries from other projects as you want.
Reply all
Reply to author
Forward
0 new messages