-
Notifications
You must be signed in to change notification settings - Fork 669
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clarify calling one library in two ways on 'Effective Dart: Usage' page #3124
Comments
It's true that the first line isn't bad; it's the combination of the two lines that's bad. I'm not sure how to make this clearer. |
@kwalrath By "combination", do you mean there should be a space between the two lines (as mentioned in best practices)? |
No, I mean that you're including the same library in two different ways, which is very bad. Maybe we could change the example to something like this: // This import by itself would be fine.
import 'package:my_package/api.dart';
// This import causes problems because it imports the same file (api.dart)
// but uses a different path. Avoiding ../lib imports prevents this problem.
import '../lib/api.dart'; // Reaching into lib. |
/cc @munificent in case he has suggestions. |
@kwalrath I didn't pay attention to the 2nd import line in 1st screenshot. I thought it would be |
You aren't the first person to be confused by the example, so I think it needs some improvement. |
Turns out we had a PR from long ago that aims to fix this. I think it's ready to commit, and I hope it helps. |
I think the addition of a "good" example with the current text after #3066 seems to sufficiently solve this issue. Let me know if you think further additions or changes are needed. Thanks again for creating an issue for this! |
Hi @dark-chocolate, thanks for raising the concern. Taking a look, this snippet is not about the first one being good and the second one being bad, it's about how importing in both ways at the same time is very confusing and causes issues. So the suggestion to this issue, is to just stick to the If we only put the Keeping that in mind, do you see someway this would be more clear? |
It's not clear what is bad. import '../lib/api.dart'; or the combination of import 'package:my_package/api.dart';
import '../lib/api.dart'; Of course both are bad. I think the docs needs to convey the following message explicitly because the reader also knows that importing both will be bad, the doc was (I think) more about what should be the correct way of importing.
|
Use 11ty's first-party [image transformation plugin](https://www.11ty.dev/docs/plugins/image/) to automatically optimize images, convert them to `png`, `webp`, and `avif`, and then transform the site HTML to use the [`<picture>` element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/picture) to select the best one for the user. This only runs in production deploy builds to reduce serving time. Also applies lazy loading and async decoding to all images, even when serving without optimizations. The transform also adds a hash of the image, allowing us to expand caching for images in Firebase hosting. To account for the transformed HTML structure, some minor HTML and CSS changes were needed as well. Overall, this reduces page load time on pages that use images, and reduces unnecessary downloads that were due to a relatively short cache time for images. On a page with just a few images, such as https://dart.dev/tools/pub/automated-publishing, the lighthouse perf score increases around 10-15 points. Fixes #4473 Fixes #3124
Page URL: https://dart.dev/guides/language/effective-dart/usage
Page source: https://github.com/dart-lang/site-www/tree/master/src/_guides/language/effective-dart/usage.md
Description of issue:
Quoting this article,
I think the first line is not
bad
, but actually is the right way to import. It is further confirmed in the next section:The text was updated successfully, but these errors were encountered: