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

Suggest that one file may contain multiple classes #36

Closed
kwalrath opened this Issue Jul 21, 2016 · 3 comments

Comments

Projects
None yet
2 participants
@kwalrath
Copy link
Member

kwalrath commented Jul 21, 2016

From @nicolasgarnier on August 26, 2014 15:19

From sigmund@google.com on December 30, 2013 20:26:08

consider adding to the styleguide suggestions for file organization.

For example:

  • avoid 1 file per class: this is common in other languages, but Dart encourages that you put together things that are related to each other.

Original issue: http://code.google.com/p/dart/issues/detail?id=15836

Copied from original issue: dart-archive/www.dartlang.org#804

@kwalrath

This comment has been minimized.

Copy link
Member

kwalrath commented Jul 21, 2016

From @nicolasgarnier on August 26, 2014 15:19

From sigmund@google.com on May 14, 2014 13:33:48

We recently had some discussions in this area, and here are some interesting points that might be worth bringing up in the style guide:

a- more than one class in a file helps cluster ideas by library concepts. In a way making things easier to navigate. It is true that 1-class per file makes the name of the file predictable, so you know which file contains the definition of a class. However, we found that when files contain libraries with multiple classes, all the sudden files have more meaningful names (typically names match features of your package) and you tend to find it easier to locate where a particular feature would be implemented.

b- there are many scenarios where some classes are just an implementation detail, they could be private or visible just to that package. These are much easier to understand when their definition is together with the code that will use them.

c- there are situations that highlight that it might be a good idea to merge some code or do something else. For example,
c.1- if you always have to write 2 imports for two classes or functions are always used together. That is typically a sign that they should either be in the same file or one should be exporting the other as well.
c.2- sometimes an extra file and and extra import doesn't seem worth it (e.g. a class with just 5 lines of code used in a single place).

@kwalrath

This comment has been minimized.

Copy link
Member

kwalrath commented Jul 21, 2016

From @nicolasgarnier on August 26, 2014 15:19

From kathyw@google.com on June 04, 2014 14:53:22

Labels: -Area-Documentation Area-Site

@kwalrath

This comment has been minimized.

Copy link
Member

kwalrath commented Jul 21, 2016

From @sethladd on September 3, 2014 23:37

This should be for Idiomatic Dart, yes?

@kwalrath kwalrath removed the triaged label Jul 21, 2016

@munificent munificent changed the title specify file organization conventions in style guide Suggest that one file can contain multiple classes Mar 29, 2018

@munificent munificent changed the title Suggest that one file can contain multiple classes Suggest that one file may contain multiple classes Mar 29, 2018

munificent added a commit that referenced this issue Apr 4, 2018

munificent added a commit that referenced this issue Apr 5, 2018

Add guideline for placing multiple classes in a single file. (#745)
* Add guideline for placing multiple classes in a single file.

Fix #36.

* Copy-edit.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment