Skip to content
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

Guidelines for the logical lumping of types into a file. #5

Open
chrsmys opened this issue Nov 3, 2015 · 4 comments
Open

Guidelines for the logical lumping of types into a file. #5

chrsmys opened this issue Nov 3, 2015 · 4 comments

Comments

@chrsmys
Copy link

chrsmys commented Nov 3, 2015

What are people's opinions on when we should add a class/struct to an already existing swift file rather than creating a dedicated file for that class/struct? Also, if we do logically lump classes/structs together, what should this file be named?

For Example: If we have a UITableViewController, should the UITableViewCells that the UITableViewController uses be in the same file? What if later on down the road we want to use that UITableViewCell somewhere else?

My initial opinion on this is that each class should be in a dedicated file so that classes are easier to find.

@Grigs-b
Copy link

Grigs-b commented Nov 3, 2015

I would say separate file for all classes. Grouping causes way more confusion than it solves, especially when there's no way to apply it consistently

@ianterrell
Copy link

I think one file per type is overly restrictive, but I agree that there are no easy rules for when to group things.

Personally I say take a stab at using one file for similar things when it feels good. General guidelines:

  1. Code is logically grouped
  2. Code contains private types (required)
  3. Want to skim this code at once
  4. We're under 1kish lines lines

@chrsmys chrsmys changed the title Guidelines for the logical lumping of classes into a file. Guidelines for the logical lumping of types into a file. Nov 3, 2015
@mikerunnals
Copy link

I like how Apple treats UITableView. This file has 3 classes, 2 protocols, 4 enums and an extension. It's ~400 (swift) lines. I would happily find a WT VC of similar length, with a similar num of types.

@rothomp3
Copy link

rothomp3 commented Nov 3, 2015

We did already decide that private types should be "namespaced" by being inside the type that uses them, right? If so, then one file per "over-type" makes sense to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants