-
Notifications
You must be signed in to change notification settings - Fork 718
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 when to use Part directives #2371
Comments
My understanding is that Does that sound right, @kevmoo or @munificent? How can we clarify our guidance? |
I don't think there is a lot of overlap between extension members and parts.
My suggested guidance: parts are useful for code generation or cases here
libraries have to be big and should be broken into files.
...but it's pretty rare when a library has to be big. There are many ways
to split things up...
…On Mon, Apr 27, 2020 at 8:58 AM Kathy Walrath ***@***.***> wrote:
My understanding is that part was an early language feature that fell out
of common use, except in automatically generated code. Also, the relatively
new extension feature can be used in some places where part used to be
necessary.
Does that sound right, @kevmoo <https://github.com/kevmoo> or @munificent
<https://github.com/munificent>? How can we clarify our guidance?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2371 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAEFCX2OLYEF3WCEOK7J6LROWTS7ANCNFSM4MQ254ZQ>
.
|
I agree with Kevin. Maybe say:
|
Thanks @kwalrath, @kevmoo, and @munificent for the clarification! Is there some justification for avoiding parts outside of code generation? I feel there are cases where parts are still very useful. Take the following scenario for example: class Foo {...}
class Bar {...}
class MyClass extends Base<Foo, Bar>{...} We can define Alternatively, we can define I find parts are useful for this sort of scenario because they allow me to separate the implementations of these individual components while still representing them as parts of the whole part 'foo.dart';
part 'bar.dart';
class MyClass extends Base<Foo, Bar> {...} I can then access Is there anything "wrong" with this approach? Thanks 🙏 |
The case that @felangel described is what is being used in the flutter_bloc IDE extensions, and I personally like it a lot, since it makes the integration so much easier, and we do not need a barrel file just for the bloc (+ events and states). |
The main problems is that those part files:
So you don't get the benefits of being able to reason about each file independently. They are deeply intertwined. It only really lets you break your file into smaller files textually but not conceptually. In fact, it can end up more confusing because the separate files lead you to think things are more encapsulated than they actually are. Because of that, our experience is that for most users parts don't carry their weight as a feature. |
@munificent : Is this still a going concern? |
I think this comment is still decent guidance. We don't really want users hand authoring part files. They're much better off using separate libraries and using |
For 2024 my use, |
Fixes dart-lang#2371 --------- Co-authored-by: Marya <111139605+MaryaBelanger@users.noreply.github.com>
Can you please clarify what is meant by:
https://dart.dev/guides/libraries/create-library-packages#organizing-a-library-package
It’s a bit unclear if part usage is discouraged in general or just in the context of library creation and if so it would be nice to elaborate on the rationale. Happy to open a PR to improve the docs once this has been clarified. Thanks!
The text was updated successfully, but these errors were encountered: