truths universally acknowledged: swift design patterns as jane austen heroes

31
Truths Universally Acknowledged Swift Design Patterns As Jane Austen Heroes

Upload: northofnormal

Post on 21-Jan-2017

146 views

Category:

Software


0 download

TRANSCRIPT

Truths Universally Acknowledged

Swift Design Patterns As Jane Austen Heroes

How To Tell You Are In A Jane Austen Novel

1. Someone disagreeable is trying to persuade you take a trip to Bath

How To Tell You Are In A Jane Austen Novel

2. A woman who hates you is playing the pianoforte

How To Tell You Are In A Jane Austen Novel

3. A picnic has gone horribly wrong

Code CrushElyse made me do it.

How To Tell You Are In A Jane Austen Novel

4. You once took a walk with a cad

Jane Austen

Jane Austen

Mr. DarcyDelegates & Protocols

Pride and Prejudice• Mr. Fitzwilliam Darcy arrives at Netherfield Hall, immediately is

horrified by the neighbors and makes a terrible impression on Ms. Elizabeth Bennet

• Shortly thereafter, army officer Mr. Wickham arrives in town and makes a much better impression on the local ladies.

• A series of events, Darcy eventually warms to Lizzie, while she’s seeing the appeal of Mr. Wickham.

• So Darcy rushes to her side to tell her that, despite her appalling family and the fact that she is so terribly beneath him, he has, despite all his better judgment, fallen in love with her.

Pride and Prejudice• Meanwhile, Wickham disappears with Lizzie’s younger

sister—without marrying her.

• Everyone panics, Mr. Bennet goes looking for his lost daughter but returns without her—only to find that somehow, everything has worked out for the best.

• Wickham has married Lydia in return for an annual income…paid for by Darcy!

• Darcy returns, he and Lizzie take a walk in a garden and he proposes.

Protocols & Delegates

“A protocol defines a blueprint of methods, properties, and other requirements that suit a particular task or piece of functionality. The protocol can then be adopted by a class, structure, or enumeration to provide an actual implementation of those requirements. Any type that satisfies the requirements of a protocol is said to conform to that protocol.”

For Examplepublic protocol wooingDelegate { var endearments: String { get } func proposal() -> Bool}

class upstandingGentleman: wooingDelegate { var income: Int = 10_000 var endearments = "You must allow me to tell you how ardently I admire and love you." func proposal() -> Bool { happilyEverAfter() return true } func happilyEverAfter() { // lives happily ever after }}

class scoundrel: wooingDelegate { var debt: Int = -600 var endearments = "I know it's not funny, but your perfume smells like your daddy's got money" func proposal() -> Bool { getSlapped() return false } func getSlapped() { // gets slapped in the face }}

Protocols & Delegates

• Kind of smug

• Inscrutable

• Will save the day, behind the scenes

How To Tell You Are In A Jane Austen Novel

5. You develop a resentment at public dance

Captain WentworthSwitch Statements

Persuasion• 7 years ago, Anne Elliot broke an engagement to a young

naval officer, Frederick Wentworth.

• He was confident and ambitious, but not of a particularly noteworthy family—her father and sisters convinced her that she would be marrying beneath her station

• But time passes, and Freddie Wentworth becomes the decorated Capt. Wentworth, but as for Anne, “her bloom had vanished early…she was faded and thin.”

• And the proud Elliot family has fallen into debt and been reduced to renting out their manor to another naval officer

Persuasion• Anne goes with some friends and Capt. Wentworth to

Lyme to visit still more naval officers. One of the friends falls and is terribly injured, but Anne handles things and is generally competent

• The entire party decamps to Bath, because in Austen novels you always end up in Bath?

• In Bath, Anne has a conversation with a gentlemen over wether women or men fall out of love quicker

• Capt. Wentworth overhears and hides a letter to Anne declaring his love.

If Statementif setting == "Netherfield Hall" { cell?.tintColor = .blueColor() if suitor.name == "Wickham" { cell?.textLabel?.text = "Immoral con-man" } else if suitor.name == "Darcy" { cell?.textLabel?.text = "Insufferable, but maybe not?" }}else if setting == "Cleveland Park" { cell?.tintColor = .yellowColor() if suitor.name == "Willoughby" { cell?.textLabel?.text = "Charming, but a jerk" } else if suitor.name == "Brandon" { cell?.textLabel?.text = "Surprisingly sweet" } }else if setting == "Kellynch Hall" { cell?.tintColor = .greenColor() if suitor.name == "Elliot" { cell?.textLabel?.text = "Probably shady" } else if suitor.name == "Wentworth" { cell?.textLabel?.text = "The one that got away, almost" }}

Switch statement switch setting {case "Netherfield Hall": cell?.tintColor = .blueColor() switch suitor.name { case "Wickham": cell?.textLabel?.text = "Immoral con-man" case "Darcy": cell?.textLabel?.text = "Insufferable, but maybe not?" } case "Cleveland Park": cell?.tintColor = .yellowColor() switch suitor.name { case "Willoughby": cell?.textLabel?.text = "Charming, but a jerk" case "Brandon": cell?.textLabel?.text = "Surprisingly sweet" } case "Kellynch Hall": cell?.tintColor = .greenColor() switch suitor.name { case "Elliot": cell?.textLabel?.text = "Probably shady" case "Wentworth": cell?.textLabel?.text = "The one that got away, almost" }}

How To Tell You Are In A Jane Austen Novel

6. You have five hundred a year. From who? Five hundred what? No one knows. No one cares. You have it. It’s yours. All five hundred of it.

Col. BrandonGuard Statements

Sense and Sensibility• Marianne Dashwood meets the charming Mr. Willoughby

when she sprains her ankle on a walk and he gallantly carries her home

• The two are inseparable and deeply in love, but suddenly Mr. Willoughby departs for London and stops answering Marianne’s letters

• Meanwhile, Col. Brandon shows up and is obviously taken with Marianne.

• But! Col. Brandon has a scandalous past and possibly a bastard daughter!

Sense and Sensibility• Marianne is invited to London, where she hopes to meet

Mr. Willoughby again

• And she does, at dance where he is incredibly rude to her—and announces his engagement to a wealthy heiress

• Distraught, Marianne falls ill and Col. Brandon helps care for her, reading her sonnets

• Eventually we learn that the alleged bastard daughter is his niece, who he cared for after she was orphaned

• And Col. Brandon and Marianne get married

Guard Statements

“A guard statement is used to transfer program control out of a scope if one or more conditions aren’t met”

Willoughby Code

func acceptsProposal(suitor: gentleman) -> Bool { if !suitor.hasHat || suitor.income < 1200 { return false } else { return true }}

Brandon Code

func acceptsProposal(suitor: gentleman) -> Bool { guard suitor.hasHat else { return false } guard suitor.income > 12_000 else { return false } return true}

How To Tell You Are In A Jane Austen Novel

7. You are in a garden, and you are astonished.

Questions?

Anne Cahalannorthofnormal

gmail - twitter - github