learn-co-curriculum / oo-basics

Other
0 stars 23 forks source link

Be careful about encouraging students to tie OO to the real world too much #22

Closed pletcher closed 8 years ago

pletcher commented 8 years ago

The sentence "Object oriented programming, or OOP, is an extremely useful programming paradigm in which we can organize our code according to how real-world objects might interact with one another" is at best an oversimplification and at worst a confusing limitation on the possibilities of OO.

One of the most confusing things about OO is it's attempt to mirror the real world, but that's not really what OO sets out to do, right?

An easy way enough; or rather, there are many ways in which the feat might be quickly and easily accomplished, none quicker than that of turning a mirror round and round --you would soon enough make the sun and the heavens, and the earth and yourself, and other animals and plants, and all the, other things of which we were just now speaking, in the mirror. Yes, [Glaucon] said; but they would be appearances only.

OO is all about mnemonics and ergonomics, not representations per se (I think, anyway).

So anyway we should be more precise with this introduction.

AnnJohn commented 8 years ago

@pletcher any specific on how to be more precise with the intro?

@StevenNunez, i think you probably will agree with @pletcher here but feel free to discuss on this.

pletcher commented 8 years ago

I think what I'm going for is that OO is a way of organizing code according to shared actions and properties, and less about making our code look like the real world.

What I'm trying to avoid is a situation where students are reluctant to implement, e.g.,

class Honker
  def honk
    puts "honk!"
  end
end

class Car < Honker
end

class Duck < Honker
end

This is a contrived example, but I just mean for it to show how programming is nothing like the real world.

frederikcreemers commented 8 years ago

I'd leave the connection to real world objects out of it completely. I find it much more useful to think of classes in terms of responsibilities. I don't know how deep you want to go into what that means. What a single responsibility for a method means vs. what a single responsibility for a class means. Having a single reason to change vs. "doing" one thing.

octosteve commented 8 years ago

I think a good way to get into this is to build a few objects that collaborate with each other. Maybe something like:

class Dog                                                                          
  attr_reader :name                                                                
  def initialize(name)                                                             
    @name = name                                                                   
  end                                                                              
end                                                                                

class Human                                                                        
  attr_reader :name                                                                
  def initialize(name)                                                             
    @name = name                                                                   
  end                                                                              
end                                                                                

class NotificationDispatch                                                         
  attr_reader :notifier, :recipient                                                
  def initialize(notifier, recipient)                                              
    @notifier = notifier                                                           
    @recipient = recipient                                                         
  end                                                                              

  def notify(message)                                                              
    puts "#{notifier.name} says #{message} to #{recipient.name}"                   
  end                                                                              
end                                                                                

fido = Dog.new('fido')                                                          
bob = Human.new('Bob')                                                          
notifier = NotificationDispatch.new(fido, bob)                                  
notifier.notify("GIVE ME FOOD")          

This is a wacky example, but something like this might work. @pletcher

pletcher commented 8 years ago

@bigblind agreed 100% -- the challenge is, I think, working up to the idea of single responsibility without inundating beginners with programmer-speak :)

@StevenNunez I like that example. I wonder if we can just rewrite "Object oriented programming, or OOP, is an extremely useful programming paradigm in which we can organize our code according to how real-world objects might interact with one another" so that it instead reads, "Object-oriented programming, or OOP, is a programming paradigm in which we organize our code according to shared behaviors and properties. For example..." and then maybe a pseudo-code example of what you have above?

octosteve commented 8 years ago

@pletcher I like it but it doesn't sound as nice as the first one even though it's more accurate! Is there a better way of saying "shared behaviors and properties"?

pletcher commented 8 years ago

@StevenNunez yeah, that's the thing. Maybe we can talk about "organiz[ing] our code around things (objects) and what they do"?

octosteve commented 8 years ago

We can put the misperception that "Objects help you model the world" and show the limitations of that. Something like "If we only limit our objects to entities in the real world, the limitations will start jumping out at us." Maybe follow up with something like "Imagine a telephone call between 2 people. Sure, the PEOPLE are real, but what about the phone call? If we think about the phone call through OOP, we can model it too! A phone call has a caller and a receiver, a duration, and even a cost_per_minute. In the real world, it's not a real thing, but in programming IT IS!" @pletcher

pletcher commented 8 years ago

That seems perfect -- wanna pop that into a PR?

octosteve commented 8 years ago

@pletcher githttps://github.com/learn-co-curriculum/oo-basics/pull/24 Let me know what you think.

pletcher commented 8 years ago

Fixed with https://github.com/learn-co-curriculum/oo-basics/commit/dd7825c3a52ca29bbc6194ab93befc3483b38a05

octosteve commented 8 years ago

WOOT!