<p>This caught my attention last night.</p>
<p>On the latest <a href="http://altnetpodcast.com/episodes/10-oop-in-ruby" rel="nofollow noreferrer">ALT.NET Podcast</a> Scott Bellware discusses how as opposed to Ruby, languages like C#, Java et al. are not truly object oriented rather opting for the phrase &quot;class-oriented&quot;.  They talk about this distinction in very vague terms without going into much detail or discussing the pros and cons much.</p>
<p>What is the real difference here and how much does it matter?  What are other languages then are &quot;object-oriented&quot;?  It sounded pretty interesting but I don't want to have to learn Ruby just to know what if anything I am missing.</p>
<h2>Update</h2>
<p>After reading some of the answers below it seems like people generally agree that the reference is to duck-typing.  What I'm not sure I understand still though is the claim that this ultimately changes all that much.  Especially if you are already doing proper TDD with loose coupling etc.  Can someone show me an example of a specific thing I could do with Ruby that I cannot do with C# and that exemplifies this different OOP approach?</p>

[{'answer_id': 52107, 'author': 'Daren Thomas', 'author_id': 2260, 'author_profile': 'https://Stackoverflow.com/users/2260', 'pm_score': 2, 'selected': False, 'text': "<p>Maybe they are alluding to the difference between duck typing and class hierarchies?</p>\n\n<p><em>if it walks like a duck and quacks like a duck, just pretend it's a duck and kick it.</em></p>\n\n<p>In C#, Java etc. the compiler fusses a lot about: Are you allowed to do this operation on that object?</p>\n\n<p>Object Oriented vs. Class Oriented could therefore mean: Does the language worry about objects or classes?</p>\n\n<p>For instance: In Python, to implement an iterable object, you only need to supply a method <code>__iter__()</code> that returns an object that has a method named <code>next()</code>. That's all there is to it: No interface implementation (there is no such thing). No subclassing. Just talking like a duck / iterator.</p>\n\n<p><strong>EDIT:</strong> This post was upvoted while I rewrote everything. Sorry, won't ever do that again. The original content included advice to learn as many languages as possible and to nary worry about what the language doctors think / say about a language.</p>\n"}, {'answer_id': 52122, 'author': 'Simon Johnson', 'author_id': 854, 'author_profile': 'https://Stackoverflow.com/users/854', 'pm_score': 0, 'selected': False, 'text': "<p>I'll take a stab at this.</p>\n\n<p>Python and Ruby are duck-typed. To generate any maintainable code in these languages, you pretty much have to use test driven development. As such, it is very important for a developer to easily inject dependencies into their code without having to create a giant supporting framework. </p>\n\n<p>Successful dependency-injection depends upon on having a pretty good object model. The two are sort of two sides of the same coin. If you really understand how to use OOP, then you should by default create designs where dependencies can be easily injected. </p>\n\n<p>Because dependency injection is easier in dynamically typed languages, the Ruby/Python developers feel like their language understands the lessons of OO much better than other statically typed counterparts.</p>\n"}, {'answer_id': 52133, 'author': 'pete blair', 'author_id': 5119, 'author_profile': 'https://Stackoverflow.com/users/5119', 'pm_score': 3, 'selected': False, 'text': '<p>There are three pillars of OOP</p>\n\n<ol>\n<li>Encapsulation</li>\n<li>Inheritance</li>\n<li>Polymorphism</li>\n</ol>\n\n<p>If a language can do those three things it is a OOP language.</p>\n\n<p>I am pretty sure the argument of language X does OOP better than language A will go on forever.</p>\n'}, {'answer_id': 52137, 'author': 'Ben Scheirman', 'author_id': 3381, 'author_profile': 'https://Stackoverflow.com/users/3381', 'pm_score': 5, 'selected': True, 'text': "<p>The duck typing comments here are more attributing to the fact that Ruby and Python are more <em>dynamic</em> than C#.  It doesn't really have anything to do with it's OO Nature.</p>\n\n<p>What (I think) Bellware meant by that is that in Ruby, everything is an object.  Even a class.  A class definition is an instance of an object.  As such, you can add/change/remove behavior to it at runtime.</p>\n\n<p>Another good example is that NULL is an object as well.  In ruby, everything is LITERALLY an object.  Having such deep OO in it's entire being allows for some fun meta-programming techniques such as method_missing.</p>\n"}, {'answer_id': 52139, 'author': 'Peter Meyer', 'author_id': 1875, 'author_profile': 'https://Stackoverflow.com/users/1875', 'pm_score': 3, 'selected': False, 'text': '<p>IMO, it\'s really overly defining "object-oriented", but what they are referring to is that Ruby, unlike C#, C++, Java, et al, does not make use of <em>defining</em> a class -- you really only ever work directly with objects.  Conversely, in C# for example, you define <em>classes</em> that you then must <em>instantiate</em> into object by way of the new keyword.  The key point being you must <em>declare</em> a class in C# or describe it.  Additionally, in Ruby, <em>everything</em> -- even numbers, for example -- is an object.  In contrast, C# still retains the concept of an object type and a value type.  This in fact, I think illustrates the point they make about C# and other similar languages -- object <em>type</em> and value <em>type</em> imply a <em>type</em> system, meaning you have an entire system of <em>describing</em> types as opposed to just working with objects.</p>\n\n<p>Conceptually, I think OO <em>design</em> is what provides the abstraction for use to deal complexity in software systems these days.  The language is a tool use to implement an OO design -- some make it more natural than others.  I would still argue that from a more common and broader definition, C# and the others are still <em>object-oriented</em> languages.</p>\n'}, {'answer_id': 52146, 'author': 'crashmstr', 'author_id': 1441, 'author_profile': 'https://Stackoverflow.com/users/1441', 'pm_score': 0, 'selected': False, 'text': '<p>This is really probably getting down to what these people see others doing in c# and java as opposed to c# and java supporting OOP. Most languages cane be used in different programming paradigms. For example, you can write procedural code in c# and scheme, and you can do functional-style programming in java. It is more about what you are trying to do and what the language supports.</p>\n'}, {'answer_id': 52173, 'author': 'Scott Lawrence', 'author_id': 3475, 'author_profile': 'https://Stackoverflow.com/users/3475', 'pm_score': 2, 'selected': False, 'text': '<p>I\'ve only listened to the first 6-7 minutes of the podcast that sparked your question.  If their intent is to say that C# isn\'t a purely object-oriented language, that\'s actually correct.  Everything in C# isn\'t an object (at least the primitives aren\'t, though boxing creates an object containing the same value).  In Ruby, everything is an object.  Daren and Ben seem to have covered all the bases in their discussion of "duck-typing", so I won\'t repeat it.</p>\n\n<p>Whether or not this difference (everything an object versus everything not an object) is material/significant is a question I can\'t readily answer because I don\'t have sufficient depth in Ruby to compare it to C#.  Those of you who on here who know Smalltalk (I don\'t, though I wish I did) have probably been looking at the Ruby movement with some amusement since it was the first pure OO language 30 years ago.</p>\n'}, {'answer_id': 52228, 'author': 'Gishu', 'author_id': 1695, 'author_profile': 'https://Stackoverflow.com/users/1695', 'pm_score': 1, 'selected': False, 'text': "<p>That was an abstract-podcast indeed!<br>\nBut I see what they're getting at - they just dazzled by Ruby Sparkle. Ruby allows you to do things that C-based and Java programmers wouldn't even think of + combinations of those things let you achieve undreamt of possibilities.\nAdding new methods to a built-in String class coz you feel like it, passing around unnamed blocks of code for others to execute, mixins... Conventional folks are not used to objects changing too far from the class template.\nIts a whole new world out there for sure.. </p>\n\n<p>As for the C# guys not being OO enough... dont take it to heart.. Just take it as the stuff you speak when you are flabbergasted for words. Ruby does that to most people.<br>\nIf I had to recommend one language for people to learn in the current decade.. it would be Ruby. I'm glad I did.. Although some people may claim Python. But its like my opinion.. man! :D</p>\n"}, {'answer_id': 93409, 'author': 'Gishu', 'author_id': 1695, 'author_profile': 'https://Stackoverflow.com/users/1695', 'pm_score': 2, 'selected': False, 'text': '<p>Update: Its the new wave.. which suggest everything that we\'ve been doing till now is passe.. Seems to be propping up quite a bit in podcasts and books.. Maybe this is what you heard.</p>\n\n<p>Till now we\'ve been concerned with static classes and not <strong>unleashed</strong> the power of object oriented development. We\'ve been doing \'class based dev.\' Classes are fixed/static templates to create objects. All objects of a class are created equal. </p>\n\n<p>e.g. Just to illustrate what I\'ve been babbling about... let me borrow a Ruby code snippet from PragProg screencast I just had the privilege of watching.\n\'Prototype based development\' blurs the line between objects and classes.. there is no difference.</p>\n\n<pre><code>animal = Object.new                  # create a new instance of base Object\n\ndef animal.number_of_feet=(feet)     # adding new methods to an Object instance. What?\n  @number_of_feet = feet\nend\ndef animal.number_of_feet\n  @number_of_feet\nend\n\ncat = animal.clone          #inherits \'number_of_feet\' behavior from animal\ncat.number_of_feet = 4\n\nfelix = cat.clone           #inherits state of \'4\' and behavior from cat\nputs felix.number_of_feet   # outputs 4\n</code></pre>\n\n<p>The idea being its a more powerful way to inherit state and behavior than traditional class based inheritance. It gives you more flexibility and control in certain "special" scenarios (that I\'ve yet to fathom). This allows things like Mix-ins (re using behavior without class inheritance).. </p>\n\n<p>By challenging the basic primitives of how we think about problems, \'true OOP\' is like \'the Matrix\' in a way... You keep going WTF in a loop. Like this one.. where the base class of Container can be either an Array or a Hash based on which side of 0.5 the random number generated is.</p>\n\n<pre><code>class Container &lt; (rand &lt; 0.5 ? Array : Hash)\nend\n</code></pre>\n\n<p>Ruby, javascript and the new brigade seem to be the ones pioneering this. I\'m still out on this one... reading up and trying to make sense of this new phenomenon. Seems to be powerful.. too powerful.. Useful? I need my eyes opened a bit more. Interesting times.. these.</p>\n'}, {'answer_id': 211897, 'author': 'Keith', 'author_id': 905, 'author_profile': 'https://Stackoverflow.com/users/905', 'pm_score': 1, 'selected': False, 'text': "<p>I don't think this is specifically about duck typing.  For instance C# supports limited duck-typing already - an example would be that you can use foreach on <em>any</em> class that implements MoveNext and Current.</p>\n\n<p>The concept of duck-typing is compatible with statically typed languages like Java and C#, it's basically an extension of reflection.</p>\n\n<p>This is really the case of static vs dynamic typing. Both are proper-OO, in as much as there is such a thing. Outside of academia it's really not worth debating.</p>\n\n<p>Rubbish code can be written in either. Great code can be written in either. There's absolutely nothing functional that one model can do that the other can't.</p>\n\n<p>The real difference is in the nature of the coding done. Static types reduce freedom, but the advantage is that everyone knows what they're dealing with. The opportunity to change instances on the fly is very powerful, but the cost is that it becomes hard to know what you're deaing with.</p>\n\n<p>For instance for Java or C# intellisense is easy - the IDE can quickly produce a drop list of possibilities. For Javascript or Ruby this becomes a lot harder.</p>\n\n<p>For certain things, for instance producing an API that someone else will code with, there is a real advantage in static typing. For others, for instance rapidly producing prototypes, the advantage goes to dynamic.</p>\n\n<p>It's worth having an understanding of both in your skills toolbox, but nowhere near as important as understanding the one you already use in real depth.</p>\n"}, {'answer_id': 211938, 'author': 'JacquesB', 'author_id': 7488, 'author_profile': 'https://Stackoverflow.com/users/7488', 'pm_score': 2, 'selected': False, 'text': '<p>OO is sometimes defined as <em>message oriented</em>. The idea is that a method call (or property access) is really a message sent to another object. How the recieveing object handles the message is completely encapsulated. Often the message corresponds to a method which is then executed, but that is just an implementation detail. You can for example create a catch-all handler which is executed regardless of the method name in the message.</p>\n\n<p>Static OO like in C# does not have this kind of encapsulation. A massage <em>has</em> to correspond to an existing method or property, otherwise the compiler will complain. Dynamic languages like Smalltalk, Ruby or Python does however support "message-based" OO.</p>\n\n<p>So in this sense C# and other statically typed OO languages are not true OO, sine thay lack "true" encapsulation. </p>\n'}, {'answer_id': 792775, 'author': 'Scott Bellware', 'author_id': 96443, 'author_profile': 'https://Stackoverflow.com/users/96443', 'pm_score': 5, 'selected': False, 'text': "<p>In an object-oriented language, objects are defined by defining objects rather than classes, although classes can provide some useful templates for specific, cookie-cutter definitions of a given abstraction.  In a class-oriented language, like C# for example, objects must be defined by classes, and these templates are usually canned and packaged and made immutable before runtime.  This arbitrary constraint that objects must be defined before runtime and that the definitions of objects are immutable is not an object-oriented concept; it's class oriented.</p>\n"}, {'answer_id': 1007483, 'author': 'Mecki', 'author_id': 15809, 'author_profile': 'https://Stackoverflow.com/users/15809', 'pm_score': 1, 'selected': False, 'text': '<p>Object Oriented is a concept. This concept is based upon certain ideas. The technical names of these ideas (actually rather principles that evolved over the time and have not been there from the first hour) have already been given above, I\'m not going to repeat them. I\'m rather explaining this as simple and non-technical as I can.</p>\n<p>The idea of OO programming is that there are objects. Objects are small independent entities. These entities may have embedded information or they may not. If they have such information, only the entity itself can access it or change it. The entities communicate with each other by sending messages between each other. Compare this to human beings. Human beings are independent entities, having internal data stored in their brain and the interact with each other by communicating (e.g. talking to each other). If you need knowledge from someone\'s else brain, you cannot directly access it, you must ask him a question and he may answer that to you, telling you what you wanted to know.</p>\n<p>And that\'s basically it. This is real idea behind OO programming. Writing these entities, define the communication between them and have them interact together to form an application. This concept is not bound to any language. It\'s just a concept and if you write your code in C#, Java, or Ruby, that is not important. With some extra work this concept can even be done in pure C, even though it is a functional language but it offers everything you need for the concept.</p>\n<p>Different languages have now adopted this concept of OO programming and of course the concepts are not always equal. Some languages allow what other languages forbid, for example. Now one of the concepts that involved is the concept of classes. Some languages have classes, some don\'t. A class is a blueprint how an object looks like. It defines the internal data storage of an object, it defines the messages an object can understand and if there is inheritance (which is <em>not mandatory</em> for OO programming!), classes also defines from which other class (or classes if multiple inheritance is allowed) this class inherits (and which properties if selective inheritance exists). Once you created such a blueprint you can now generate an unlimited amount of objects build according to this blueprint.</p>\n<p>There are OO languages that have no classes, though. How are objects then build? Well, usually dynamically. E.g. you can create a new blank object and then dynamically add internal structure like instance variables or methods (messages) to it. Or you can duplicate an already existing object, with all its properties and then modify it. Or possibly merge two objects into a new one. Unlike class based languages these languages are very dynamic, as you can generate objects dynamically during runtime in ways not even you the developer has thought about when starting writing the code.</p>\n<p>Usually this dynamic has a price: The more dynamic a language is the more memory (RAM) objects will waste and the slower everything gets as program flow is extremely dynamically as well and it\'s hard for a compiler to generate effective code if it has no chance to predict code or data flow. JIT compilers can optimize some parts of that during runtime, once they know the program flow, however as these languages are so dynamically, program flow can change at any time, forcing the JIT to throw away all compilation results and re-compile the same code over and over again.</p>\n<p>But this is a tiny implementation detail - it has nothing to do with the basic OO principle. It is nowhere said that objects need to be dynamic or must be alterable during runtime. The Wikipedia says it pretty well:</p>\n<blockquote>\n<p>Programming techniques may include\nfeatures such as information hiding,\ndata abstraction, encapsulation,\nmodularity, polymorphism, and\ninheritance.</p>\n</blockquote>\n<p><a href="http://en.wikipedia.org/wiki/Object-oriented_programming" rel="nofollow noreferrer">http://en.wikipedia.org/wiki/Object-oriented_programming</a></p>\n<p>They <em>may</em> or they <em>may not</em>. This is all not mandatory. Mandatory is only the presence of objects and that they must have ways to interact with each other (otherwise objects would be pretty useless if they cannot interact with each other).</p>\n'}, {'answer_id': 3225429, 'author': 'liammclennan', 'author_id': 2785, 'author_profile': 'https://Stackoverflow.com/users/2785', 'pm_score': 1, 'selected': False, 'text': '<p>You asked: "Can someone show me an example of a wonderous thing I could do with ruby that I cannot do with c# and that exemplifies this different oop approach?"</p>\n\n<p>One good example is active record, the ORM built into rails. The model classes are dynamically built at runtime, based on the database schema. </p>\n'}]
['https://Stackoverflow.com/questions/52092', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5056/']