Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
hipster oriented
programming
Jens Ravens
Developer at nerdgeschoss
iOS/ OS X (Swift)
Server / Backend (Ruby)
@JensRavens
jensravens.de
nerdgeschoss.de
I hate monads already. Even if it’s
the most useful, elegant thing - it’s
all what’s wrong about hype based
hipster-progra...
Is it really functional
programming if you don't give a
talk about it?
- @alejandrocrosa
This talk is not about
functional programming.
What is a hipster anyway?
a person who follows the latest
trends and fashions, especially those
regarded as being outside the
cultural mainstream.
-...
orientation
Imperative
Do this 5 times!
func nullToNil(dict: [String: AnyObject])->[String: AnyObject]{
var cleaned = [String: AnyObje...
Functional
Same input, same output.
let l = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
let sum = l.reduce(+) // 55
Object Oriented
Put your family of objects in a
room and let them talk.
Protocol Oriented
You have a lot of equatable,
comparable, parseable, archiveable,
transmittable, displayable objects.
Spaghetti Oriented
JSON parsing.
What is state anyway?
class ViewController: UIViewController, UITableViewDelegate {
var selectedItem: Item?
func updateVie...
Question State How to recognise?
IP
imperative
How? a lot of nested loops and assignments
OOP
object oriented
How?
(but en...
They all mix pretty well.
- pretty big secret
bridging the worlds
Monads.
http://fuckingmonads.com
Signals.
jensravens.de/series/functional-reactive-programming-in-swift/
Boxing and Optionals.
Throwing Errors.
Mapping Arrays and
Collections.
Type Safety.
Protocols and Facades.
combining ideas
idea 1
treating your user as an
interface
user interface
Recipe
Recipe
Recipe
Recipe
Recipe
protocol User {
func selectRecipe(recipies: [Recipe], completion:Recipe-...
user interface
Recipe
Recipe
Recipe
Recipe
Recipe
protocol User {
func selectRecipe(recipies: [Recipe], completion:Recipe?...
user interface
Recipe
Recipe
Recipe
Recipe
Recipe
protocol User {
func selectSingle(collection: [Selectable], completion:S...
user interface
Recipe
Recipe
Recipe
Recipe
Recipe
func downloadStuff(term: String, completion: Result<[Recipe]>->Void){
//...
idea 2
facades via typedef
abstract servers
public typealias Headers = [String: String]
public typealias Environment = [String: AnyObject]
public typ...
idea 3
common behavior in
protocols
protocol Contextable {
func showContext(gestureRecognizer: UIGestureRecognizer)
func viewControllerForContext(context: Ite...
extension Contextable {
func viewControllerForContext(context: Item) -> UIViewController?
{
return self as? UIViewControll...
extension ChannelViewController: Contextable {
@IBAction func triggerContext(gestureRecognizer:
UIGestureRecognizer) {
sho...
These are just concepts.
They won’t hurt you, they
won’t take away your job.
It’s more out there than just
object oriented
programming.
object oriented programming
has a lot of hidden gems you
might not be aware of yet.
learning from
other plattforms
these are amazing times
to be a developer
do not just read about
your plattform
What’s .next()?
Functors, Applicatives
and Monads in Pictures.
http://adit.io/posts/2013-04-17-
functors,_applicatives,_and_monads_in_pict...
The Introduction to RP
you’ve been missing.
https://gist.github.com/staltz/868e7e9bc2a7b8c1f754
Imperative Programming In Swift (Graham Lee)
sicpers.info/2015/07/imperative-programming-in-swift/
Protocol-Oriented Progr...
keep searching for
new frontiers
use the right tool
for the right job
Thank you.
@JensRavens
jensravens.de
Hipster oriented programming (Mobilization Lodz 2015)
Hipster oriented programming (Mobilization Lodz 2015)
Hipster oriented programming (Mobilization Lodz 2015)
Hipster oriented programming (Mobilization Lodz 2015)
Hipster oriented programming (Mobilization Lodz 2015)
Upcoming SlideShare
Loading in …5
×

Hipster oriented programming (Mobilization Lodz 2015)

1,705 views

Published on

Not sure if you should order a burrito or a monad for lunch? Get a quick overview of Object Oriented, Functional and Protocol Oriented programming and learn what all that fuss is about.

Published in: Software
  • Be the first to comment

  • Be the first to like this

Hipster oriented programming (Mobilization Lodz 2015)

  1. 1. hipster oriented programming
  2. 2. Jens Ravens Developer at nerdgeschoss iOS/ OS X (Swift) Server / Backend (Ruby) @JensRavens jensravens.de nerdgeschoss.de
  3. 3. I hate monads already. Even if it’s the most useful, elegant thing - it’s all what’s wrong about hype based hipster-programming in one word. - tweet after UIKonf
  4. 4. Is it really functional programming if you don't give a talk about it? - @alejandrocrosa
  5. 5. This talk is not about functional programming.
  6. 6. What is a hipster anyway?
  7. 7. a person who follows the latest trends and fashions, especially those regarded as being outside the cultural mainstream. - Wikipedia
  8. 8. orientation
  9. 9. Imperative Do this 5 times! func nullToNil(dict: [String: AnyObject])->[String: AnyObject]{ var cleaned = [String: AnyObject]() for (key, value) in dict { if !(value is NSNull) { cleaned[key] = value } } return cleaned }
  10. 10. Functional Same input, same output. let l = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] let sum = l.reduce(+) // 55
  11. 11. Object Oriented Put your family of objects in a room and let them talk.
  12. 12. Protocol Oriented You have a lot of equatable, comparable, parseable, archiveable, transmittable, displayable objects.
  13. 13. Spaghetti Oriented JSON parsing.
  14. 14. What is state anyway? class ViewController: UIViewController, UITableViewDelegate { var selectedItem: Item? func updateView() { // do something to update the display } func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { selectedItem = findItemAtIndex(indexPath) } }
  15. 15. Question State How to recognise? IP imperative How? a lot of nested loops and assignments OOP object oriented How? (but encapsulated) encapsulated state seperation of concerns “unix principle” POP protocol oriented What? encapsulated objects implementing hundreds of protocols. FP functional What? no state. you have no idea what it’s doing, but it’s short and beautiful. FRP functional reactive When? over my dead lambda. you’re constantly flatMapping
  16. 16. They all mix pretty well. - pretty big secret
  17. 17. bridging the worlds
  18. 18. Monads. http://fuckingmonads.com
  19. 19. Signals. jensravens.de/series/functional-reactive-programming-in-swift/
  20. 20. Boxing and Optionals.
  21. 21. Throwing Errors.
  22. 22. Mapping Arrays and Collections.
  23. 23. Type Safety.
  24. 24. Protocols and Facades.
  25. 25. combining ideas
  26. 26. idea 1 treating your user as an interface
  27. 27. user interface Recipe Recipe Recipe Recipe Recipe protocol User { func selectRecipe(recipies: [Recipe], completion:Recipe->Void) }
  28. 28. user interface Recipe Recipe Recipe Recipe Recipe protocol User { func selectRecipe(recipies: [Recipe], completion:Recipe?->Void) }
  29. 29. user interface Recipe Recipe Recipe Recipe Recipe protocol User { func selectSingle(collection: [Selectable], completion:Selectable?->Void) }
  30. 30. user interface Recipe Recipe Recipe Recipe Recipe func downloadStuff(term: String, completion: Result<[Recipe]>->Void){ // networking and error handling } class UserSelection: UIViewController, User { static func selectRecipe(presentingViewController: UIViewController) (recipies: [Recipe], completion: Result<Recipe> -> Void) { // present your view controller here and save the completion block } } let searchVC = // your current vc let textField = // the textfield used for typing textField .textSignal .flatMap(downloadStuff) .flatMap(UserSelection.selectRecipe(searchVC)) .next { recipe in // do whatever you like } .error { error in // something went wrong on the way }
  31. 31. idea 2 facades via typedef
  32. 32. abstract servers public typealias Headers = [String: String] public typealias Environment = [String: AnyObject] public typealias StatusCode = Int public typealias Response = (StatusCode, Headers, ContentStreamable) public typealias Swagable = Request throws -> Response let HelloWorld: Swagable = { env in return (200, [:], "Hello World") }
  33. 33. idea 3 common behavior in protocols
  34. 34. protocol Contextable { func showContext(gestureRecognizer: UIGestureRecognizer) func viewControllerForContext(context: Item) -> UIViewController? func contextViewControllerForContext(context: Item) -> UIViewController? func contextForGestureRecognizer(gestureRecognizer: UIGestureRecognizer) -> Item? // the only required method func contextForIndexPath(indexPath: NSIndexPath) -> Item? }
  35. 35. extension Contextable { func viewControllerForContext(context: Item) -> UIViewController? { return self as? UIViewController } func contextForGestureRecognizer(gestureRecognizer: UIGestureRecognizer) -> Item? { // find the clicked indexpath } }
  36. 36. extension ChannelViewController: Contextable { @IBAction func triggerContext(gestureRecognizer: UIGestureRecognizer) { showContext(gestureRecognizer) } func contextForIndexPath(indexPath: NSIndexPath) -> Item? { return dataSource.itemForIndexPath(indexPath) } }
  37. 37. These are just concepts. They won’t hurt you, they won’t take away your job.
  38. 38. It’s more out there than just object oriented programming.
  39. 39. object oriented programming has a lot of hidden gems you might not be aware of yet.
  40. 40. learning from other plattforms
  41. 41. these are amazing times to be a developer
  42. 42. do not just read about your plattform
  43. 43. What’s .next()?
  44. 44. Functors, Applicatives and Monads in Pictures. http://adit.io/posts/2013-04-17- functors,_applicatives,_and_monads_in_pictures.html
  45. 45. The Introduction to RP you’ve been missing. https://gist.github.com/staltz/868e7e9bc2a7b8c1f754
  46. 46. Imperative Programming In Swift (Graham Lee) sicpers.info/2015/07/imperative-programming-in-swift/ Protocol-Oriented Programming in Objective-C sicpers.info/2015/06/protocol-oriented-programming-in- objective-c/ Mutable objects in immutable objects in object-oriented programming in functional programming in Swift sicpers.info/2015/06/mutable-objects-in-immutable- objects-in-object-oriented-programming-in-functional- programming-in-swift/
  47. 47. keep searching for new frontiers
  48. 48. use the right tool for the right job
  49. 49. Thank you. @JensRavens jensravens.de

×