Live data from Hacker News

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

news.ycombinator.com

51–60 of 76 posts

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

#51

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 ju…

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 ...

I have sometimes thought the same thing. There are ample explanations of the use of OOP put in terms of stuff like, poodle inherits from dog, which inherits from mammal etc. or a car could be represented as a series of objects interacting with each other, the engine, gear box etc. This is all perfectly fine and super easy to visualise. But the stumbling block for me is sometimes when I try to turn these ideas to something that's actually useful. Abstact concepts that indeed do not always have a neat corelation in the real world.

If anyone has some tips on how one can begin to develop a clearer method for modeling more abstract concepts in OO, I'd love to hear them.

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

#52
post #2

(I'm not trying to sound condescending, so bear with me) How else would you write software with modular and re-usable components?

I've got 8 minutes til I need to catch the bus. The answer to your question hinges mainly on how you define components. In the Erlang language for example: It is completely functional but threads actually become somewhat stateful and ultimately end up recreating some similar scenarios for OOP programmers. On top of that, functions themselves showcase an even higher amount of reusability at times especially in functio…

A common misconception about erlang is its degree of functional-ness. It isn't completely functional. As Peyton-Jones says, a completely functional language will just sit there and make the computer run hot[1].

Erlang is a well thought out compromise between tying your hands by restricting side effects (the monad approach) and allowing a wide audience of people to be quickly productive.

[1]: Changing the temperature of the environment can be considered a side effect thereby rendering the 100% functional language 99.999% functional.

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

#53
post #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...

The language that fits this description best is Erlang, I would say ... (what, in this definition, is specific to objects compared to processes?)

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

#54
so this is not Procedural programming is like a recipe- you program a sequence of instructions and while there can be if/then, loop and other logic constructs, it still runs like a "choose your own adventure" book. Since you have an imperfect view of the world and how requirements will evolve and you're providing what are essentially sequential instructions, it's brittle and unforgiving to unanticipated requirements.

OO is less about writing instructions and more about creating a representation of the world (or at least the aspects you care about) as objects and having them interact with each other to achieve things. Because you're modeling the entities involved and having them interact rather than imposing a prescriptive set of instructions from above, it's cleaner and more resilient to unanticipated requirements.

Granted it's overkill to use OO for simple tasks when a script will suffice. But if you're building a system that involves interaction of different entities and will need to be adapted & maintained it will almost certainly be more productive to use an OO approach. Btw, I found this book provides the most concise and useful primer on OO I've seen: http://www.amazon.com/Object-Technology-Managers-David-Taylo...

sean

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

#55
one good way to start seeing more objects around you is to try to search for a pattern like this one in your procedural code : a group of functions operating on a certain kind of data structure. A classic example would be the stdio functions in C. You have FILE (which is your data structure) and then fopen,fclose,fscanf etc. which are the functions operating on FILE. This is object orientation at it's most basic (an object is some data and methods to process that data) even if C is not regarded as an OO supporting language.

There is only a small step from writing stuff like this :

FILE* ofile = fopen("test.txt","w"); fprintf(ofile,"%s %s %s",1,2,3); fclose(ofile)

to writing code like this :

FILE ofile("test.txt","w"); ofile.printf("%s %s %s",1,2,3); ofile.close();

So. you've grouped some data and some code together so it's easier to work with it. This is just the first step though, but the small objects you make will be very useful. You can make a small library of useful objects that way : file, string, date, time, point, rectangle, socket, regexp etc.

Also, you don't have to make the whole program OO. You can keep it procedural (and for most scripts that's the case), but you can use the above objects just like you'd use their procedural counterparts before. Slowly, and with experience both with OOP and larger programs, you'll see other parts of your work that would make sense as an object. On the other hand, some of them won't. And it's perfectly ok - not all problems can be naturally modeled as a system of objects.

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

#56
A strategy to manage complexity by decomposing problems into hierarchical type relationships through the mechanisms of encapsulation (code and data together in an "object"), polymorphism (actions on abstract types trigger behaviors without knowledge of their specific implementation), and derivation (relationships between classes) such that specific behaviors increase toward the leaves and decrease toward the roots, leaving implementation and general behavior isolated at appropriate levels.

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

#59

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 ju…

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 ... I have sometimes thought the same thing. There are ample explanations of the use of OOP put in terms of stuff like, poodle inherits from dog, which inherits from mammal etc. or a car could be represented as a series of objects inte…

Try to go through the articles at: http://www.objectmentor.com/resources/publishedArticles.html

Most articles carry some example to go with the concept being explained.

Post reply on HN