Live data from Hacker News

Ask HN: can you summarize OO for me in 64 words or less?

news.ycombinator.com

21–30 of 76 posts

Re: Ask HN: can you summarize OO for me in 64 words or less?

#21
post #8
post #3

Earlier quoted context omitted.

modular and re-usable components is not really OO specific tho.

That didn't answer my question though. You can technically convert any programming paradigm to anything that is touring-complete. Just because something is designed with OO methods doesn't mean that it can not be designed any other way. Original C++ compilers simply converted C++ code to C. But seriously, if you had to write software that abstracts complexity (good), has modular components (good) and let's you attack…

This is sort of resonating with me. Maybe I've been doing to many exercises by the book, I dunno, but your description of the problem space seems straight out of a textbook which I'm all to familar with. Divide and conquer; define the data set, factor, isolate, call foo, iterate. . .expressions, storage space, and iterating each as a function is not hard, in short deducing a problem set in terms of an operation is not hard for me, since an operation, to me at least, is synomous with run-time, which is why I thought I was programming. . .a compositon of operations in terms of input and output. I understand that each approach is borrowing similar tenents of refactoring input, but I don't understand how the composition of operations are playing in terms of code-time vs run-time.

Re: Ask HN: can you summarize OO for me in 64 words or less?

#22
What is Object Oriented programming?

I wrestled with this one in school for a while, because the name is so screwy. What is an object? It's a blob of code. It's a walled off place in your computer's RAM that has variables and functions. It's just a bit of reusable code.

Why is that special? If you've spent your programming life copying and pasting code in a text editor, it's probably not going to be readily apparent. It's pretty easy to reuse code without having to jump through OOP hoops.

In OOP, those reusable bits of code aren't copied and pasted, in the text editor, however. They're reused automatically in memory. When programming in an OOP style, you create one blob of code (an object), and then without touching the original, you can use the object and use it's methods and variables.

You can modify or extend the object, and you're never changing the original object.

For instance, in Ruby. Everything is an object. Even integers are objects and strings are objects. That is, every time I use the integer "5" in my code, I have all the methods from the Integer class available at my finger tips.

So, I can do something like this:

   5.next  #this returns 6
   5.next.next # this returns 7
Or, I can use the "times" method from the Integer class, to create a loop:

   5.times do |i|
      print i, " "
   end
      #produces
   0 1 2 3 4
Why can Ruby do this? Because all integers are a type of object that has the .next() and the .times() method that we can use every time we use an integer.

The same goes for strings. In Ruby, every string is automatically given all the methods from Ruby's String class for free. So, you can do stuff like this:

   "hello".capitalize  #this returns "Hello"
   "HELLO".capitalize  #this returns "Hello" as well
and

   "hello".empty?  #returns false
   "".empty? #returns true
   "hello".length #returns the length of the string
   "hello".reverse   # returns "olleh"
Every string that you use in Ruby has all the String class methods available to the programmer, because in Ruby, every string is an object.

There are lots of other things that you can do with OOP, this is just a taste of what Ruby does. I think the key to learning OOP is to learn it in a language that uses it very elegantly like Ruby, or even Python. If you're trying to learn OOP in PHP or Perl or Java, you're in for a rather difficult time, because there's so much other stuff that gets in your way.

But, if you learn OOP in a langauge that uses is really well, you can isolate some of the OOP concepts, and you can go back and use them in your language of choice if and when you need to.

OOP certainly isn't the be all end all of programming paradigms, but it's well worth your while to learn if you're going to be writing code for a living. It's one way to reuse code. It's certainly not the only way.

Re: Ask HN: can you summarize OO for me in 64 words or less?

#23
Data structures bound to operations on those data structures, and some obvious elaborations on that theme.

Going much deeper gets controversial; there are many, many elaborations on that theme, each of which you can find a language that implements it and a language community that considers it anathema.

Re: Ask HN: can you summarize OO for me in 64 words or less?

#25
post #10

Think of it less as "Object-Oriented" and more as "Message-Oriented" and things become clear. Every object has a vocabulary of messages it can respond to. The only contract you have with the object is what it can do, not how it does it; therefore, the supplier of the object is free to implement algorithms as he sees fit. (60 words) Bonus analogy: The web itself is object-oriented. You ask a server to return a resourc…

The smalltalk object system is a nice simple example:

    A Smalltalk object can do exactly three things:
    Hold state (references to other objects).
    Receive a message from itself or another object.
    In the course of processing a message, send messages to itself or another object.
http://en.wikipedia.org/wiki/Smalltalk#Object-oriented_progr...

Re: Ask HN: can you summarize OO for me in 64 words or less?

#26
Computer programming is all about declaring abstractions that make computers easier to control. Objects are an intuitive way to model your program by defining logical subsets of data and operations on that data. Classes are define common, readable patterns in the data - a person class can have age, name, height and weight and methods to manipulate these. At runtime, only the values of data are replicated with pointers to single copies of methods. OOP is just another way to organize your code. Inheritance of classes gives a higher level of abstraction, allowing you to reduce the code footprint of your application and make it more maintainable.

Re: Ask HN: can you summarize OO for me in 64 words or less?

#27
This is probably the wrong community to mention this, but this discussion is an excellent example of why I am largely procedural in my programming and don't focus too much on OO. I need to tackle real world business problems. Likening objects to things like refrigerators and toasters is where I get lost. Perhaps those examples work well in the classroom to help kids wrap their heads around the concept of OO, but I just don't see how or where they fit in the real world. OO evangelists are always quick to cite a lot of technical reasons for why programming in OO offers up major benefits in their work, but (from those I've spoken to) can rarely match examples to those reasons.

Re: Ask HN: can you summarize OO for me in 64 words or less?

#28
Objects combine information and operations. They should help keep disjoint things separate, and related things together. They do provide a simple metaphor for modeling.

Not all objects are alike. Smalltalk is "pure"; Python and Ruby mostly "just work"; C++ is very complicated.

No programming paradigm can save you from under-specification. You need a very good description of your desired behavior before you start coding.

Post reply on HN