Skip to content

Steal from the Github style guide! #58

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

Merged
merged 1 commit into from
Dec 11, 2014
Merged

Conversation

gregheo
Copy link
Contributor

@gregheo gregheo commented Dec 3, 2014

GitHub have created their own guide here:

https://github.com/github/swift-style-guide

Good to see that we agree on quite a few syntax related points. However theirs is a lot more opinionated.

I am still trying to get my head around Swift structs and how widely to use them, notice that GitHub advise you to prefer structs over classes.

@hollance
Copy link
Member

hollance commented Sep 7, 2014

Here's how I think about structs vs classes:

You use structs for things that do not have an identity. An array that contains objects a, b, c is really the same as another array that contains objects a, b, c. Even though both arrays may be located in different memory locations, they are completely interchangeable. For the code it doesn't matter whether you use the first array or the second, because they represent the exact same thing. That's why array is a struct.

You use classes for things that do have an identity (as well as a specific life cycle). You would model a Person as a class because two persons are two different things. Just because two people have the same name and birthdate (or other attributes), doesn't mean they are the same person. But the person's birthdate would be a struct because a date of 3 March 1950 is the same as any other date object for 3 March 1950. The date itself doesn't have an identity.

(Of course, if you use NSDate then the date is a class but that's because of Objective-C.)

@ColinEberhardt
Copy link
Contributor Author

BUMP

We really should get this text included somehow!

Text is from @hollance's comment in the issue.
gregheo added a commit that referenced this pull request Dec 11, 2014
Merge in Matthijs's struct vs classes
@gregheo gregheo merged commit 3a1b50e into kodecocodes:master Dec 11, 2014
@gregheo gregheo deleted the issue-58 branch December 11, 2014 00:07
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

Successfully merging this pull request may close these issues.

3 participants