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…
Ask HN: can you summarize OO for me in 64 words or less?
21–30 of 76 posts
Re: Ask HN: can you summarize OO for me in 64 words or less?
#22I 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?
#23Going 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?
#24Re: Ask HN: can you summarize OO for me in 64 words or less?
#25Think 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…
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?
#26Re: Ask HN: can you summarize OO for me in 64 words or less?
#27Re: Ask HN: can you summarize OO for me in 64 words or less?
#28Not 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.