3

I am experimenting with my first Dart web app and do not expect to make any part of my app a reusable library for other apps/libs. As such, I do not have a lib directory in my project; rather, I have a web directory.

I guess my intent is to have my web directory look like this:

web/
    Main.dart <-- where my main method is
    logging/
        Logger.dart
        LogLevel.dart
    model/
        Signin.dart
        Signout.dart
    view/
        SigninView.dart
        signinView.html
    presenter/
        SigninPresenter.dart
    ...lots of other packages

Several questions:

  1. Should my entire application (everything under web) be considered to be a part of the same library? If so, would I then put library myapp; at the top of every Dart file? Otherwise, what is the level of granularity for a library? Should I put it package-level, and have Logger and LogLevel inside library logging;? Is it at the class/file level and have a library logger and a library log_level?
  2. Is my web directory set up correctly? I'm coming from Java so I'm treating web the same as Java/Maven's src/main/java directory, and setting up a package structure under web that makes sense to me...
  3. I understand that the import keyword is for importing source types from other packages. But what about export - what does that do?
halfer
  • 19,824
  • 17
  • 99
  • 186
IAmYourFaja
  • 55,468
  • 181
  • 466
  • 756
  • 1
    Please, keep one question per post instead of spawning several at once. – Braiam Dec 26 '13 at 19:13
  • 1
    Thanks @Braiam (+1) but that is always a judgement call. I feel like if you have several, similar questions, and they all require the same setup/backstory/SSCCE, that it's better to just group them into one question rather than bog SO down with the extra text from multiple questions. – IAmYourFaja Dec 26 '13 at 19:18
  • SO is not a forum, no one feels bogged, also your question should be searchable, if I need to know what `export` does in dart sources, how can I find [this](http://stackoverflow.com/q/20789600/792066) question? And if you ask several questions in one post is more likely that yours will be closed as duplicated just because it answers one of your many questions. – Braiam Dec 26 '13 at 19:20

1 Answers1

1

I would recommend that you have a lib/ directory and put shared code within it. If the code isn't directly to be used by other parts of your app, move that code to the src/ directory within lib/. I realize that you are not planning to make your app reusable by other apps, but code which is consumed by different parts of your app should probably live within lib/.

A lot of this is a matter of convenience and convention, but I try to keep my web/ directory pretty lean, even going so far as to place only those .dart files in it that are directly referenced in a .html file. Your mileage may vary, but I find that this convention (putting shared code in lib/ and web-specific code in web/ helps keep things clear).

As for library directives, I like to use a single namespace which is the same as the name of the app.

So, a library in lib/models.dart could be declared like this:

library myApp.models;

A library in `web/foo/bar.dart' could be declared like this:

library myApp.web.foo.bar;
Shailen Tuli
  • 13,815
  • 5
  • 40
  • 51
  • Thanks @Shailen Tuli (+1) - very sound advice. I guess I'm confused over the **purpose** of the library. What's the difference between placing `web/foo/bar.dart` in a library named `myapp.web.foo.bar` or putting it in one called `myapp.web.foo`? What are the benefits/cons to either approach? Thanks again! – IAmYourFaja Dec 27 '13 at 02:24