What's the point of OOP?

As far as I can tell, in spite of the countless millions or billions spent on OOP education, languages, and tools, OOP has not improved developer productivity or software reliability, nor has it reduced development costs. Few people use OOP in any rigorous sense (few people adhere to or understand principles such as LSP); there seems to be little uniformity or consistency to the approaches that people take to modelling problem domains. All too often, the class is used simply for its syntactic sugar; it puts the functions for a record type into their own little namespace.

I've written a large amount of code for a wide variety of applications. Although there have been places where true substitutable subtyping played a valuable role in the application, these have been pretty exceptional. In general, though much lip service is given to talk of "re-use" the reality is that unless a piece of code does exactly what you want it to do, there's very little cost-effective "re-use". It's extremely hard to design classes to be extensible in the right way, and so the cost of extension is normally so great that "re-use" simply isn't worthwhile.

In many regards, this doesn't surprise me. The real world isn't "OO", and the idea implicit in OO--that we can model things with some class taxonomy--seems to me very fundamentally flawed (I can sit on a table, a tree stump, a car bonnet, someone's lap--but not one of those is-a chair). Even if we move to more abstract domains, OO modelling is often difficult, counterintuitive, and ultimately unhelpful (consider the classic examples of circles/ellipses or squares/rectangles).

So what am I missing here? Where's the value of OOP, and why has all the time and money failed to make software any better?

30033 次浏览

Why we use TestNG instead of JUnit?

  1. The declaration of @BeforeClass and @AfterClass method has to be static in JUnit whereas, there is more flexibility in TestNG in the method declaration, it does not have these constraints.

  2. In TestNG, we can parametrize tests using 2 ways. @Parameter or @DataProvider annotation.

    I can think of dozens of libraries off the top of my head which are beautifully reusable and which have saved time and money that can never be calculated.

    But to the extent that OOP has been a waste of time, I'd say it's because of lack of programmer training, compounded by the steep learning curve of learning a language specific OOP mapping. Some people "get" OOP and others never will.

    i) @Parameter for simple cases, where key value mapping is required.(data is provided through xml file)

    ests will be skipped, not marked as failed. But JUnit marked it failed.

  3. Grouping: Single tests can belong to multiple groups and then run in different contexts (like slow or fast tests). A similar feature exists in JUnit Categories but lacks the @BeforeGroups / @AfterGroups TestNG annotations that allow initializing the test / tearing it down.

  4. ii) @DataProvider for complex cases. Using 2 dimensional array, It can provide data.

  5. Parallelism: If you’d like to run the same test in parallel on multiple threads, TestNG has you covered with a simple to use annotation while JUnit doesn’t offer a simple way to do so out of the box.

  6. In TestNG, since @DataProvider method need not be static, we can use multiple data provider methods in the same test class.

  7. TestNG @DataProvider can also support XML for feeding in data, CSVs, or even plain text files.

  8. Dependency Testing: In TestNG, if the initial test fails, then all subsequent dependent tests will be skipped, not marked as failed. But JUnit marked it failed.

  9. TestNG allows you to declare dependencies between tests, and skip them if the dependency test didn’t pass.

  • Grouping: Single tests can belong to multiple groups and then run in different contexts (like slow or fast tests). A similar feature exists in JUnit Categories but lacks the @BeforeGroups / @AfterGroups TestNG annotations that allow initializing the test / tearing it down.

  • @Test(dependsOnMethods = { "dependOnSomething" })

  • Parallelism: If you’d like to run the same test in parallel on multiple threads, TestNG has you covered with a simple to use annotation while JUnit doesn’t offer a simple way to do so out of the box.

  • This functionality doesn’t exist in JUnit

    1. TestNG @DataProvider can also support XML for feeding in data, CSVs, or even plain text files.

    2. Reporting:
  • TestNG allows you to declare dependencies between tests, and skip them if the dependency test didn’t pass.

  • TestNG reports are generated by default to a test-output folder that includes HTML reports with all of the test data, passed/failed/skipped, how long did they run, which input was used and the complete test logs. In addition, it also exports everything to an XML file which can be used to construct your own report template.

    @Test(dependsOnMethods = { "dependOnSomething" })

    On the JUnit front, all of this data is also available via XML, but there’s no out of the box report and you need to rely on plugins.

    This functionality doesn’t exist in JUnit

      Resource Link:

      1. Reporting:
    1. A Quick JUnit vs TestNG Comparison
    2. TestNG reports are generated by default to a test-output folder that includes HTML reports with all of the test data, passed/failed/skipped, how long did they run, which input was used and the complete test logs. In addition, it also exports everything to an XML file which can be used to construct your own report template.

    3. JUnit vs. TestNG: Which Testing Framework Should You Choose?

    On the JUnit front, all of this data is also available via XML, but there’s no out of the box report and you need to rely on plugins.

    A good difference is given in this tutorial side by side: TestNG Vs JUnit: What's the Difference?

    Resource Link:

      The real world isn't "OO", and the idea implicit in OO--that we can model things with some class taxonomy--seems to me very fundamentally flawed

    While this is true and has been observed by other people (take Stepanov, inventor of the STL), the rest is nonsense. OOP may be flawed and it certainly is no silver bullet but it makes large-scale applications much simpler because it's a great way to reduce dependencies. Of course, this is only true for “good” OOP design. Sloppy design won't give any advantage. But good, decoupled design can be modelled very well using OOP and not well using other techniques.

  • A Quick JUnit vs TestNG Comparison
  • JUnit vs. TestNG: Which Testing Framework Should You Choose?
  • There are much better, more universal models (Haskell's type model comes to mind) but these are also often more complicated and/or difficult to implement efficiently. OOP is a good trade-off between extremes.

    I think where OO breaks down is when people create deeply nested class heirarchies. This can lead to complexity. However, factoring out common finctionality into a base class, then reusing that in other descendant classes is a deeply elegant thing, IMHO!

    @CodingTheWheel

    I'm trying to solve the 3n+1 problem and I have a for loop that looks like this:

    for(int i = low; i <= high; ++i)
    {
    res = runalg(i);
    if (res > highestres)
    {
    highestres = res;
    }
    
    
    }
    

    Unfortunately I'm getting this error when I try to compile with GCC:

    But to the extent that OOP has been a waste of time, I'd say it's because of lack of programmer training, compounded by the steep learning curve of learning a language specific OOP mapping. Some people "get" OOP and others never will.

    3np1.c:15: error: 'for' loop initial

    I dunno if that's really surprising, though. I think that technically sound approaches (LSP being the obvious thing) make hard to use, but if we don't use such approaches it makes the code brittle and inextensible anyway (because we can no longer reason about it). And I think the counterintuitive results that OOP leads us to makes it unsurprising that people don't pick it up.

    declaration used outside C99 mode

    I don't know what C99 mode is. Any ideas?

    More significantly, since software is already fundamentally too hard for normal humans to write reliably and accurately, should we really be extolling a technique that is consistently taught poorly and appears hard to learn? If the benefits were clear-cut then it might be worth persevering in spite of the difficulty, but that doesn't seem to be the case.

    However, factoring out common finctionality into a base class, then reusing that in other descendant classes is a deeply elegant thing, IMHO!

    I'd try to declare i outside of the loop!

    But "procedural" developers have been doing that for decades anyway. The syntax and terminology might differ, but the effect is identical. There is more to OOP than "reusing common functionality in a base class", and I might even go so far as to say that that is hard to describe as OOP at all; calling the same function from different bits of code is a technique as old as the subprocedure itself.

    Good luck on solving 3n+1 :-)

    @Konrad

    Here's an example:

    #include <stdio.h>
    
    
    int main() {
    
    
    int i;
    
    
    /* for loop execution */
    for (i = 10; i < 20; i++) {
    printf("i: %d\n", i);
    }
    
    
    return 0;
    }
    

    OOP may be flawed and it certainly is no silver bullet but it makes large-scale applications much simpler because it's a great way to reduce dependencies

    That is the dogma. I am not seeing what makes OOP significantly better in this regard than procedural programming of old. Whenever I make a procedure call I am isolating myself from the specifics of the implementation.

    "Even if there is no actual [information architecture], it doesn’t mean we don’t experience or perceive it as such. Zen Buddhists say there is no actual “self” but they still name their kids."-Andrew Hinton

    ompiler switch -std=c99

    Or as @OysterD says, declare the variable outside the loop.

    ards of the C language.

    @Blorgbeard:

    g long int, optional extended integer types, an explicit boolean data type, and a complex type to represent complex numbers

    New Features in C99

    • variable-length arrays
    • inline functions
    • support for one-line comments beginning with //, as in BCPL or C++
    • variable declaration no longer restricted to file scope or the start of a compound statement
    • new library functions, such as snprintf
    • several new data types, including long long int, optional extended integer types, an explicit boolean data type, and a complex type to represent complex numbers
    • new header files, such as stdbool.h and inttypes.h
    • variable-length arrays
    • type-generic math functions (tgmath.h)
    • support for one-line comments beginning with //, as in BCPL or C++
    • improved support for IEEE floating point
    • new library functions, such as snprintf
    • designated initializers
    • new header files, such as stdbool.h and inttypes.h
    • compound literals
    • type-generic math functions (tgmath.h)
    • support for variadic macros (macros of variable arity)
    • improved support for IEEE floating point
    • restrict qualification to allow more aggressive code optimization
  • designated initializers
  • http://en.wikipedia.org/wiki/C99

    A Tour of C99

  • compound literals
  • support for variadic macros (macros of variable arity)
  • Relative to straight procedural programming, the first fundamental tenet of OOP is the notion of information hiding and encapsulation. This idea leads to the notion of the class that seperates the interface from implementation. These are hugely important concepts and the basis for putting a framework in place to think about program design in a different way and better (I think) way. You can't really argue against those properties - there is no trade-off made and it is always a cleaner way to modulize things.

  • restrict qualification to allow more aggressive code optimization
  • Other aspects of OOP including inheritance and polymorphism are important too, but as others have alluded to, those are commonly over used. ie: Sometimes people use inheritance and/or polymorphism because they can, not because they should have. They are powerful concepts and very useful, but need to be used wisely and are not automatic winning advantages of OOP.

    http://en.wikipedia.org/wiki/C99

    A Tour of C99

    Relative to re-use. I agree re-use is over sold for OOP. It is a possible side effect of well defined objects, typically of more primitive/generic classes and is a direct result of the encapsulation and information hiding concepts. It is potentially easier to be re-used because the interfaces of well defined classes are just simply clearer and somewhat self documenting.

    @Jeff

    if you compile in C change

    for (int i=0;i<10;i++) { ..
    

    Relative to straight procedural programming, the first fundamental tenet of OOP is the notion of information hiding and encapsulation. This idea leads to the notion of the class that seperates the interface from implementation.

    Which has the more hidden implementation: C++'s iostreams, or C's FILE*s?

    to

    int i;
    for (i=0;i<10;i++) { ..
    

    I think the use of opaque context objects (HANDLEs in Win32, FILE*s in C, to name two well-known examples--hell, HANDLEs live on the other side of the kernel-mode barrier, and it really doesn't get much more encapsulated than that) is found in procedural code too; I'm struggling to see how this is something particular to OOP.

    You can also compile with the C99 switch set. Put -std=c99 in the compilation line:

    gcc -std=c99 foo.c -o foo
    

    I suppose that may be a part of why I'm struggling to see the benefits: the parts that are obviously good are not specific to OOP, whereas the parts that are specific to OOP are not obviously good! (this is not to say that they are necessarily bad, but rather that I have not seen the evidence that they are widely-applicable and consistently beneficial).

    OOP has reduced costs, and increased efficiency.

    When I made the jump from classic ASP/VBScript to C# I noticed a HUGE increase in productivity thanks to OOP.

    To switch to C99 mode in CodeBlocks, follow the next steps:

    tions, and place -std=c99 in the text area, and click Ok.

    This will turn C99 mode on for your Compiler.

    I hope this will help someone!

    I think the use of opaque context objects (HANDLEs in Win32, FILE*s in C, to name two well-known examples--hell, HANDLEs live on the other side of the kernel-mode barrier, and it really doesn't get much more encapsulated than that) is found in procedural code too; I'm struggling to see how this is something particular to OOP.

    Click Project/Build options, then in tab Compiler Settings choose subtab Other options, and place -std=c99 in the text area, and click Ok.

    HANDLEs (and the rest of the WinAPI) is OOP! C doesn't support OOP very well so there's no special syntax but that doesn't mean it doesn't use the same concepts. WinAPI is in every sense of the word an object-oriented framework.

    See, this is the trouble with every single discussion involving OOP or alternative techniques: nobody is clear about the definition, everyone is talking about something else and thus no consensus can be reached. Seems like a waste of time to me.

    Note that a similar solution applies if you run into a similar scenario with C++ compilation that requires C++ 11, you can use:

    export CXXFLAGS="-std=c++11"
    

    Jihene Stambouli answered OP question most directly...

    HANDLEs (and the rest of the WinAPI) is OOP!

    Are they, though? They're not inheritable, they're certainly not substitutable, they lack well-defined classes... I think they fall a long way short of "OOP".

    Question was;

    Have you ever created a window using WinAPI? Then you should know that you define a class (RegisterClass), create an instance of it (CreateWindow), call virtual methods (WndProc) and base-class methods (DefWindowProc) and so on. WinAPI even takes the nomenclature from SmallTalk OOP, calling the methods “messages” (Window Messages).

    why does

    for(int i = low; i <= high; ++i)
    {
    res = runalg(i);
    if (res > highestres)
    {
    highestres = res;
    }
    }
    

    produce the error;

    3np1.c:15: error: 'for' loop initial declaration used outside C99 mode
    

    Handles may not be inheritable but then, there's final in Java. They don't lack a class, they are a placeholder for the class: That's what the word “handle” means. Looking at architectures like MFC or .NET WinForms it's immediately obvious that except for the syntax, nothing much is different from the WinAPI.

    Yes, I find this to be too prevalent as well. This is not Object Oriented Programming. It's Object Based Programming and data centric programing. In my 10 years of working with OO Languages, I see people mostly doing Object Based Programming. OBP breaks down very quickly IMHO since you are essentially getting the worst of both words: 1) Procedural programming without adhering to proven structured programming methodology and 2) OOP without adhering to to proven OOP methodology.

    OOP done right is a beautiful thing. It makes very difficult problems easy to solve, and to the uninitiated (not trying to sound pompous there), it can almost seem like magic. That being said, OOP is just one tool in the toolbox of programming methodologies. It is not the be all end all methodology. It just happens to suit large business applications well.

    Most developers who work in OOP languages are utilizing examples of OOP done right in the frameworks and types that they use day-to-day, but they just aren't aware of it. Here are some very simple examples: ADO.NET, Hibernate/NHibernate, Logging Frameworks, various language collection types, the ASP.NET stack, The JSP stack etc... These are all things that heavily rely on OOP in their codebases.

    Have you ever created a window using WinAPI?

    Enable C99 mode in Code::Blocks 16.01

      More times than I care to remember.

      Then you should know that you define a class (RegisterClass), create an instance of it (CreateWindow), call virtual methods (WndProc) and base-class methods (DefWindowProc) and so on. WinAPI even takes the nomenclature from SmallTalk OOP, calling the methods “messages” (Window Messages).

      Then you'll also know that it does no message dispatch of its own, which is a big gaping void. It also has crappy subclassing.

    • Go to Settings-> Compiler...
    • Handles may not be inheritable but then, there's final in Java. They don't lack a class, they are a placeholder for the class: That's what the word “handle” means. Looking at architectures like MFC or .NET WinForms it's immediately obvious that except for the syntax, nothing much is different from the WinAPI.

      They're not inheritable either in interface or implementation, minimally substitutable, and they're not substantially different from what procedural coders have been doing since forever.

    • In Compiler Flags section of Compiler settings tab, select checkbox 'Have gcc follow the 1999 ISO C language standard [-std=c99]'

    Is this really it? The best bits of OOP are just... traditional procedural code? That's the big deal?

    , calling the methods “messages” (Window Messages).

    OOP isn't about creating re-usable classes, its about creating Usable classes.

    Then you'll also know that it does no message dispatch of its own, which is a big gaping void. It also has crappy subclassing.

    There's no empirical evidence that suggests that object orientation is a more natural way for people to think about the world. There's some work in the field of psychology of programming that shows that OO is not somehow more fitting than other approaches.

    Handles may not be inheritable but then, there's final in Java. They don't lack a class, they are a placeholder for the class: That's what the word “handle” means. Looking at architectures like MFC or .NET WinForms it's immediately obvious that except for the syntax, nothing much is different from the WinAPI.

    Object-oriented representations do not appear to be universally more usable or less usable.

    They're not inheritable either in interface or implementation, minimally substitutable, and they're not substantially different from what procedural coders have been doing since forever.

    It is not enough to simply adopt OO methods and require developers to use such methods, because that might have a negative impact on developer productivity, as well as the quality of systems developed.

    Which is from "On the Usability of OO Representations" from Communications of the ACM Oct. 2000. The articles mainly compares OO against theprocess-oriented approach. There's lots of study of how people who work with the OO method "think" (Int. J. of Human-Computer Studies 2001, issue 54, or Human-Computer Interaction 1995, vol. 10 has a whole theme on OO studies), and from what I read, there's nothing to indicate some kind of naturalness to the OO approach that makes it better suited than a more traditional procedural approach.

    In my experience of reviewing code and design of projects I have been through, the value of OOP is not fully realised because alot of developers have not properly conceptualised the object-oriented model in their minds. Thus they do not program with OO design, very often continuing to write top-down procedural code making the classes a pretty flat design. (if you can even call that "design" in the first place)

    It is pretty scary to observe how little colleagues know about what an abstract class or interface are, let alone properly design an inheritance hierarchy to suit the business needs.

    However, when good OO design is present, it is just sheer joy reading the code and seeing the code naturally fall into place into intuitive components/classes. I have always perceived system architecture and design like designing the various departments and staff jobs in a company - all are there to accomplish a certain piece of work in the grand scheme of things, emitting the synergy required to propel the organisation/system forward.

    That, of course, is quite rare unfortunately. Like the ratio of beautifully-designed versus horrendously-designed physical objects in the world, the same can pretty much be said about software engineering and design. Having the good tools at one's disposal does not necessarily confer good practices and results.

    Maybe a bonnet, lap or a tree is not a chair but they all are ISittable.

    Maybe a bonnet, lap or a tree is not a chair but they all are ISittable.

    Yes, but only ex post facto. They're ISittable because someone sat on them.

    It is very much worth it. jQuery really makes JavaScript fun again. It's as if all of JavaScript best practices were wrapped up into a single library.

    Using OO features (especially deeply nested abstract hierarchies), when there is no point, is pointless. But for some application domains, there really is a point.

    The thought of OO as a new way to get to reuse through inheritance is fundamentally flawed. As you note the LSP violations abound. Instead, OO is properly thought of as a method of managing the complexity of a problem domain. The goal is maintainability of a system over time. The primary tool for achieving this is the separation of public interface from a private implementation. This allows us to have rules like "This should only be modified using ..." enforced by the compiler, rather than code review.

    Rick Strahl and Matt Berseth's blogs both tipped me into jQuery and man am I glad they did. jQuery completely changes a) your client programming perspective, b) the grief it causes it you, and c) how much fun it can be!

    Using this, I'm sure you will agree, allows us to create and maintain hugely complex systems. There is lots of value in that, and it is not easy to do in other paradigms.

    http://www.west-wind.com/weblog/

    http://mattberseth.com/

    I used the book jQuery in Action ="noreferrer">Prototype or MooTools or ExtJS are as good as jQuery. But for me, jQuery seems to have a little more momentum behind it right now and that counts for something for me.

    http://www.amazon.com/jQuery-Action-Bear-Bibeault/dp/1933988355/ref=sr_1_1?ie=UTF8&s=books&qid=1219716122&sr=1-1 (I bought it used at Amazon for about $22). It has been a big help into bootstrapping me into jQuery. The documentation at jquery.com are also very helpful.

    Check jQuery out. It is very cool!

    I believe a hybrid model of objects where useful and procedural where practical is the most effective method of coding. It's a shame we have all these religious wars where people advocate using one method at the expense of the others. They are both good, and they both have their place. Most of the time, there are uses for both methods in every larger project (In some smaller projects, a single object, or a few procedures may be all that you need).

    There are numerous JavaScript libraries that are worth at least a cursory review to see if they suit your particular need. First, come up with a short list of criteria to guide your selection and evaluation process.

    Yes OOP did not solve all our problems, sorry about that. We are, however working on SOA which will solve all those problems.

    "The real world isn't "OO","

    Then, check out a high level framework comparison/reviews somewhere like Wikipedia, select a few that fit your criteria and interest you. Test them out to see how they work for you. Most, if not all, of these libraries have websites w/ reference documentation and user group type support.

    Really? My world is full of objects. I'm using one now. I think that having software "objects" model the real objects might not be such a bad thing.

    OO designs for conceptual things (like Windows, not real world windows, but the display panels on my computer monitor) often leave a lot to be desired. But for real world things like invoices, shipping orders, insurance claims and what-not, I think those real world things are objects. I have a stack on my desk, so they must be real.

    I think those real world things are objects

    You do?

    What methods does an invoice have? Oh, wait. It can't pay itself, it can't send itself, it can't compare itself with the items that the vendor actually delivered. It doesn't have any methods at all; it's totally inert and non-functional. It's a record type (a struct, if you prefer), not an object.

    Likewise the other things you mention.

    Just because something is real does not make it an object in the OO sense of the word. OO objects are a peculiar coupling of state and behaviour that can act of their own accord. That isn't something that's abundant in the real world.

    There are a number of resources to learn jQuery (which is completely worth it IMHO). Start here http://docs.jquery.com/Main_Page to read the jQuery documentation. This is a great site for seeing visually what it has to offer:

    As to have a set of classes model a domain in an effective way, there is no magic method. Like a piano, we have to practice. OOP is an abstract tool, it can help you build code in a simpler way, but it can't think and analyze the domain of your app for you.

    What works for me is to stay close to the domain as long as possible, while still avoiding most code duplications.

    The trouble is, 90% of us work in the world of business where we are working with business concepts such as Invoice, Employee, Job, Order. These do not lend themselves so well to OOP because the "objects" are more nebulous, subject to change according to business re-engineering and so on.

    I used Prototype for about six months before I decided to learn jQuery. To me, it was like a night and day difference. For example, in Prototype you will loop over a set of elements checking if one exists and then setting something in it, in jQuery you just say $('div.class').find('[name=thing]') or whatever and set it.

    The worst case is where OO is enthusiastically applied to databases, including the egregious OO "enhancements" to SQL databases - which are rightly ignored except by database noobs who assume they must be the right way to do things because they are newer.

    is also very useful. Also jQuery HowTo is also has a great collection of jQuery code snippets.

    Jquery.com is well organized and has many great examples. You don't need to buy a book. I found it easy to pickup on the fly by just referencing website's documentation. If you're someone who learns best by doing, I'd suggest this approach.

    The point of OOP is to give the programmer another means for describing and communicating a solution to a problem in code to machines and people. The most important part of that is the communication to people. OOP allows the programmer to declare what they mean in the code through rules that are enforced in the OO language.

    And yes, it's absolutely worth learning. It'll save you a lot of time and you'll actually look forward to doing JavaScript work!

    Contrary to many arguments on this topic, OOP and OO concepts are pervasive throughout all code including code in non-OOP languages such as C. Many advanced non-OO programmers will approximate the features of objects even in non-OO languages.

    and OO concepts are pervasive throughout all code including code in non-OOP languages such as C. Many advanced non-OO programmers will approximate the features of objects even in non-OO languages.

    Having OO built into the language merely gives the programmer another means of expression.

    Having OO built into the language merely gives the programmer another means of expression.

    The biggest part to writing code is not communication with the machine, that part is easy, the biggest part is communication with human programmers.

    In the only dev blog I read, by that Joel-On-Software-Founder-of-SO guy, I read a long time ago that OO does not lead to productivity increases. Automatic memory management does. Cool. Who can deny the data?

    I still believe that OO is to non-OO what programming with functions is to programming everything inline.

    (And I should know, as I started with GWBasic.) When you refactor code to use functions, variable2654 becomes variable3 of the method you're in. Or, better yet, it's got a name that you can understand, and if the function is short, it's called value and that's sufficient for full comprehension.

    The biggest part to writing code is not communication with the machine, that part is easy, the biggest part is communication with human programmers.

    When code with no functions becomes code with methods, you get to delete miles of code.

    de>b, c, q, and Z become this, this, this and this. And since I don't believe in using the this keyword, you get to delete miles of code. Actually, you get to do that even if you use this.



    When you refactor code to be truly OO, b, c, q, and Z become this, this, this and this. And since I don't believe in using the this keyword, you get to delete miles of code. Actually, you get to do that even if you use this.



    I do not think OO is natural metaphor.

    I don't think language is a natural metaphor either, nor do I think that Fowler's "smells" are better than saying "this code tastes bad." That said, I think that OO is not about natural metaphors and people who think the objects just pop out at you are basically missing the point. You define the object universe, and better object universes result in code that is shorter, easier to understand, works better, or all of these (and some criteria I am forgetting). I think that people who use the customers/domain's natural objects as programming objects are missing the power to redefine the universe.

    I do not think OO is natural metaphor.

    I don't think language is a natural metaphor either, nor do I think that Fowler's "smells" are better than saying "this code tastes bad." That said, I think that OO is not about natural metaphors and people who think the objects just pop out at you are basically missing the point. You define the object universe, and better object universes result in code that is shorter, easier to understand, works better, or all of these (and some criteria I am forgetting). I think that people who use the customers/domain's natural objects as programming objects are missing the power to redefine the universe.

    For instance, when you do an airline reservation system, what you call a reservation might not correspond to a legal/business reservation at all.



    For instance, when you do an airline reservation system, what you call a reservation might not correspond to a legal/business reservation at all.



    Some of the basic concepts are really cool tools

    I think that most people exaggerate with that whole "when you have a hammer, they're all nails" thing. I think that the other side of the coin/mirror is just as true: when you have a gadget like polymorphism/inheritance, you begin to find uses where it fits like a glove/sock/contact-lens. The tools of OO are very powerful. Single-inheritance is, I think, absolutely necessary for people not to get carried away, my own multi-inheritance software not withstanding.



    Some of the basic concepts are really cool tools

    I think that most people exaggerate with that whole "when you have a hammer, they're all nails" thing. I think that the other side of the coin/mirror is just as true: when you have a gadget like polymorphism/inheritance, you begin to find uses where it fits like a glove/sock/contact-lens. The tools of OO are very powerful. Single-inheritance is, I think, absolutely necessary for people not to get carried away, my own multi-inheritance software not withstanding.



    What's the point of OOP?

    I think it's a great way to handle an absolutely massive code base. I think it lets you organize and reorganize you code and gives you a language to do that in (beyond the programming language you're working in), and modularizes code in a pretty natural and easy-to-understand way.

    What's the point of OOP?

    I think it's a great way to handle an absolutely massive code base. I think it lets you organize and reorganize you code and gives you a language to do that in (beyond the programming language you're working in), and modularizes code in a pretty natural and easy-to-understand way.

    OOP is destined to be misunderstood by the majority of developers

    This is because it's an eye-opening process like life: you understand OO more and more with experience, and start avoiding certain patterns and employing others as you get wiser. One of the best examples is that you stop using inheritance for classes that you do not control, and prefer the Facade pattern instead.



    OOP is destined to be misunderstood by the majority of developers

    This is because it's an eye-opening process like life: you understand OO more and more with experience, and start avoiding certain patterns and employing others as you get wiser. One of the best examples is that you stop using inheritance for classes that you do not control, and prefer the Facade pattern instead.



    Regarding your mini-essay/question

    Regarding your mini-essay/question

    I did want to mention that you're right. Reusability is a pipe-dream, for the most part. Here's a quote from Anders Hejilsberg about that topic (brilliant) from here:

    I did want to mention that you're right. Reusability is a pipe-dream, for the most part. Here's a quote from Anders Hejilsberg about that topic (brilliant) from here:

    If you ask beginning programmers to

    If you ask beginning programmers to write a calendar control, they often write a calendar control, they often think to themselves, "Oh, I'm going to think to themselves, "Oh, I'm going to write the world's best calendar write the world's best calendar control! It's going to be polymorphic with respect to the kind of calendar. It will have displayers, and mungers, and this, that, and the other." They need to ship a calendar application in control! It's going to be polymorphic two months. They put all this with respect to the kind of calendar. infrastructure into place in the It will have displayers, and mungers, control, and then spend two days and this, that, and the other." They need to ship a calendar application in writing a crappy calendar application two months. They put all this on top of it. They'll think, "In the infrastructure into place in the next version of the application, I'm control, and then spend two days going to do so much more."

    writing a crappy calendar application

    Once they start thinking about how on top of it. They'll think, "In the they're actually going to implement next version of the application, I'm all of these other concretizations of going to do so much more."

    their abstract design, however, it turns out that their design is

    Once they start thinking about how completely wrong. And now they've they're actually going to implement painted themself into a corner, and all of these other concretizations of they have to throw the whole thing their abstract design, however, it out. I have seen that over and over. turns out that their design is I'm a strong believer in being completely wrong. And now they've minimalistic. Unless you actually are painted themself into a corner, and going to solve the general problem, they have to throw the whole thing don't try and put in place a framework out. I have seen that over and over. for solving a specific one, because I'm a strong believer in being you don't know what that framework minimalistic. Unless you actually are should look like.

    going to solve the general problem, don't try and put in place a framework

    It's the only language-portable methodology for keeping variables grouped together with the functions/methods/subroutines that interact with them.

    The point of OOP is to hide the actual implementation by abstracting it away. To achieve that goal, you must create a public interface. To make your job easier while creating that public interface and keep things DRY, you must use concepts like abstract classes, inheritance, polymorphism, and design patterns.

    So to me, the real overriding goal of OOP is to make future code maintenance and changes easier. But even beyond that, it can really simplify things a lot when done correctly in ways that procedural code never could. It doesn't matter if it doesn't match the "real world" - programming with code is not interacting with real world objects anyways. OOP is just a tool that makes my job easier and faster - I'll go for that any day.

    I found that these series of tutorials (“jQuery for Absolute Beginners” Video Series) by Jeffery Way are VERY HELPFUL.

    <a href="#" id="larger">Larger</a> |

    It targets those developers who are new to jQuery. He shows how to create many cool stuff with jQuery, like animation, Creating and Removing Elements and more.

    <a href="#" id="Smaller">Smaller</a>

    I learned a lot from it. He shows how it's easy to use jQuery. <p> Now I love it and I can read and understand any jQuery script even if it's complex.

    In today’s video tutorial, I’ll show you how to resize text every time an associated anchor tag is clicked. We’ll be examining the “slice”, “parseFloat”, and “CSS” Javascript/jQuery methods.

    Here is one example I like "Resizing Text"

    1- jQuery:

    <script language="javascript" type="text/javascript">
    $(function() {
    $('a').click(function() {
    var originalSize = $('p').css('font-size'); // Get the font size.
    var number = parseFloat(originalSize, 10);  // That method will chop off any integer
    // from the specifid varibale "originalSize".
    var unitOfMassure = originalSize.slice(-2); // Store the unit of massure, Pixle or Inch.
    
    
    $('p').css('font-size', number / 1.2 + unitOfMassure);
    if (this.id == 'larger') {
    $('p').css('font-size', number * 1.2 + unitOfMassure);
    } // Figure out which element is triggered.
    });
    });
    </script>
    
    </p>

    2- CSS Styling:

    <style type="text/css" >
    body{
    margin-left:300px;text-align:center;
    width:700px;
    background-color:#666666;}
    .box {
    width:500px;
    text-align:justify;
    padding:5px;
    font-family:verdana;
    font-size:11px;
    color:#0033FF;
    background-color:#FFFFCC;}
    </style>
    
    </div>

    2- HTML:

    <div class="box">
    <a href="#" id="larger">Larger</a> |
    <a href="#" id="Smaller">Smaller</a>
    <p>
    In today’s video tutorial, I’ll show you how to resize text every
    time an associated anchor tag is clicked. We’ll be examining
    the “slice”, “parseFloat”, and “CSS” Javascript/jQuery methods.
    </p>
    </div>
    

    I highly recommend these tutorials:

    I highly recommend these tutorials:

    http://blog.themeforest.net/screencasts/jquery-for-absolute-beginners-video-series/

    OOP helps separate interface from implementation. You do not need OOP support in the language to benefit from OO design.

    Hey, I am biased in that I now work with these guys, but Carsonified offers some great resources for people learning and improving their jQuery skill set.

    One small example where OOP has helped tremendously:

    The UNIX Virtual File System (VFS) layer presents a uniform interface (open/read/write) using tables of function pointers -- much like the C++ virtual table dispatch.

    Just next Monday there is an online conference on jQuery featuring John Resig himself - http://carsonified.com/online-conferences/jquery/

    Clients use the same set of calls regardless of whether they are talking to a local file system, a remote Network File System (NFS) or (today) fake file systems (e.g. /proc).

    Also, they now offer video tutorials via their membership scheme on the Think Vitamin blog,

    See the original Sun paper: Vnodes: An Architecture for Multiple File System Types in Sun UNIX

    Will we say the same things ten years from now about functional programming?

    Q-Fundamentals - by Rebecca Murphey mentioned anywhere here.


    I haven't seen JQ-Fundamentals - by Rebecca Murphey mentioned anywhere here.


    It is a very good book. It also explains the fundamentals of JavaScript required to understand the basics of JQuery.

    And OO is a pretty damn effective way to make your programs readable. Reuse or no reuse.

    Below link my be helpful for you if you know SQL (Only css selectors).

    p://karticles.com/2011/06/learning-jquery-with-sql-attribute-selectors" rel="nofollow">http://karticles.com/2011/06/learning-jquery-with-sql-attribute-selectors

    It seeks to re-invigorate the idea that the way forward lies in inventiveness, and that even well-accepted ideas should be questioned.

    Have you considered using conditional compilation to control what happens during debug/deployment?

    e.g.

    DateTime date;
    #if DEBUG
    date = new DateTime(2008, 09, 04);
    #else
    date = DateTime.Now;
    #endif
    

    Failing that, you want to expose the property so you can manipulate it, this is all part of the challenge of writing testable code, which is something I am currently wrestling myself :D

    If you get up from assembly routines. Assembly is an ordered sequences of pairs composed from labels and instructions. Assembly code is similar to the 'particle soup'. Now you can move to the subroutine. Subroutine picks a label from that label:instruction -soup, and hides the rest of labels inside the subroutine. As the effect code becomes more abstract and your namespace stays cleaner.

    Edit

    Now, if you think what subroutines do... Few of decades ago people were thinking that subroutines are at their best when they work on the arguments. That made them to give each object it's own protocol. Protocol would contain label:procedure -pairs. Now called selector:method -pairs. Procedures weren't bound directly to the other procedures anymore, explaining the 'late binding' -term. Along with keeping the history from the protocols (inheritance), this formed the 'object orientation' in the smalltalk.

    You've been incapacitated the late binding mechanism and forgotten what inheritance means. And you yet wonder what you are missing there. "Where's the value of OOP, and why has all the time and money failed to make software any better?" - I think you stuffed them into your arse. When you attempt to colonoscopy you will find them.

    In the first place, the observations are somewhat sloppy. I don't have any figures on software productivity, and have no good reason to believe it's not going up. Further, since there are many people who abuse OO, good use of OO would not necessarily cause a productivity improvement even if OO was the greatest thing since peanut butter. After all, an incompetent brain surgeon is likely to be worse than none at all, but a competent one can be invaluable.

    A big part of me would preference Blair's approach. This allows you to "hot plug" parts of the code to aid in testing. It all follows the design principle encapsulate what varies test code is no different to production code, its just no one ever sees it externally.

    That being said, OO is a different way of arranging things, attaching procedural code to data rather than having procedural code operate on data. This should be at least a small win by itself, since there are cases where the OO approach is more natural. There's nothing stopping anybody from writing a procedural API in C++, after all, and so the option of providing objects instead makes the language more versatile.

    Creating and interface may seem like a lot of work for this example though (which is why I opted for conditional compilation).

    Further, there's something OO does very well: it allows old code to call new code automatically, with no changes. If I have code that manages things procedurally, and I add a new sort of thing that's similar but not identical to an earlier one, I have to change the procedural code. In an OO system, I inherit the functionality, change what I like, and the new code is automatically used due to polymorphism. This increases the locality of changes, and that is a Good Thing.

    no changes. If I have code that manages things procedurally, and I add a new sort of thing that's similar but not identical to an earlier one, I have to change the procedural code. In an OO system, I inherit the functionality, change what I like, and the new code is automatically used due to polymorphism. This increases the locality of changes, and that is a Good Thing.

    The downside is that good OO isn't free: it requires time and effort to learn it properly. Since it's a major buzzword, there's lots of people and products who do it badly, just for the sake of doing it. It's not easier to design a good class interface than a good procedural API, and there's all sorts of easy-to-make errors (like deep class hierarchies).

    The downside is that good OO isn't free: it requires time and effort to learn it properly. Since it's a major buzzword, there's lots of people and products who do it badly, just for the sake of doing it. It's not easier to design a good class interface than a good procedural API, and there's all sorts of easy-to-make errors (like deep class hierarchies).

    Think of it as a different sort of tool, not necessarily generally better. A hammer in addition to a screwdriver, say. Perhaps we will eventually get out of the practice of software engineering as knowing which wrench to use to hammer the screw in.

    There are already a lot of answers on this as this is an old post but i thought i'd chime in.

    My preference is to have classes that use time actually rely on an interface, such as

    interface IClock
    {
    DateTime Now { get; }
    }
    

    You mention "class taxonomy" a bit which gets into subtyping and polymorphism. This all revolves around inheritance which in it heyday was considered the silver bullet of OOP. Nowadays, inheritance and large class hierarchies are actually discouraged, even among shops that do a lot of OOP. This is because the other pricinples of OOP, such as encapsulation, loose coupling, cohesion and so forth have been found to be far more useful than inheritance. I would even go so far to say that loose coupling is the reason for OO, not code reuse. Code reuse usually happens at the method/function level. I do sometimes reuse classes under different circumstances, but not that often. Loose coupling though helps organize a system quite a bit. Each object has its own scope, the data in the object isn't or should not be manipulated except by accessor methods or properties, each object should do one simple thing and should talk to other objects thru simple interfaces. This handful of principles helps code readability, helps isolate bugs and prevent you from having to make many changes in lots of different places to change one thing. When objects are not closely intertwined, you can change one without affecting others. This has been a huge benefit to me. Inheritance is useful only now and then.

    With a concrete implementation

    class SystemClock: IClock
    {
    DateTime Now { get { return DateTime.Now; } }
    }
    

    Code reuse is still important and if you are copying and pasting or rewriting the same code, thats a bad practice even under plain old procedural, structured or functional programming. That actually increases costs due to duplicated effort, increased maintenance and more bugs.

    Then if you want, you can provide any other kind of clock you want for testing, such as

    class StaticClock: IClock
    {
    DateTime Now { get { return new DateTime(2008, 09, 3, 9, 6, 13); } }
    }
    

    From my experience which started in C/Unix (non OOP) in the mid 1980s then moving onto C++ (OOP) in 1990 and then into Java around 1996 (OOP) I have found OOP to give a massive boost to productivity, maintainability and robustness compared with the large non OOP programs I was working on earlier.

    The main thing I have observed is that in non OOP applications I have worked on the complexity seemed to grow at an exponential rate with respect to the sophistication of the application whereas in the OOP applications I worked on the complexity seemed to have a much more linear relationship with repect to the sophistication of the application.

    There may be some overhead in providing the clock to the class that relies on it, but that could be handled by any number of dependency injection solutions (using an Inversion of Control container, plain old constructor/setter injection, or even a Static Gateway Pattern).

    In other words - with well designed OOP applications you never get that "OMG the source code for this app is getting waaaaay out of control" feeling that you get with large non OOP applications.

    Other mechanisms of delivering an object or method that provides desired times also work, but I think the key thing is to avoid resetting the system clock, as that's just going to introduce pain on other levels.

    The other things I can't do without as an OOP developer is the way I can write code that models the real world entities that exist in the application's problem domain. Objects take on a life of their own - way beyond what any structs (C) or Records (Pascal) did back in the bad old =] non OOP days.

    Also, using DateTime.Now and including it in your calculations doesn't just not feel right - it robs you of the ability to test particular times, for example if you discover a bug that only happens near a midnight boundary, or on Tuesdays. Using the current time won't allow you to test those scenarios. Or at least not whenever you want.

    The one stipulation is that the chief architect of an OOP project must know what he's doing and he has to usually put more thinking time into getting the design right than in actually implementing it but the payback for 'thinking things through up front' is truly amazing. Opportunities for reuse or awesomely cool design optimizations come to light that have you punching the air and doing touchdowns in the office... ok, that might look a bit strange to the others in the office but that kind of enthusiasm never happened in the non OOP days :)

    have you punching the air and doing touchdowns in the office... ok, that might look a bit strange to the others in the office but that kind of enthusiasm never happened in the non OOP days :)

    I've seen some pretty badly written OOP code and maybe that's what you've experienced which may have lead you to ask the question. As a contractor in the mid 90s I often found that the 'OO' design had already been started by someone who knew what a class was but not much more. It was a very painful experience and I often found that my first few months in a job involved educating the team in the very different way of 'OO' thinking. It was only after everyone's brain had been rewired that we could all proceed as a team to create something awesome.

    I've seen some pretty badly written OOP code and maybe that's what you've experienced which may have lead you to ask the question. As a contractor in the mid 90s I often found that the 'OO' design had already been started by someone who knew what a class was but not much more. It was a very painful experience and I often found that my first few months in a job involved educating the team in the very different way of 'OO' thinking. It was only after everyone's brain had been rewired that we could all proceed as a team to create something awesome.

    Many people find the 'brain rewiring' process too hard, painful or just too much effort and so spend their life dissin' OOP and so you'll find a lot of OO haters out there but I'm happy about that because it's those people that make people like me look good: "What, you can do it for $X and it will be ready in 2 months and you will give us a maintainable code base!!! Wow, can you start today?"

    To organize the code with abstraction, you will need encapsulation, inheritance, and polymorphism as well in your language. And SOLID OOP principles and design patterns come in to do better job at this organization. But I think whole point of OOP is abstraction because human thinks better in that way.

    OOP is about instancing... you want to reinstance the same thing over and over again, with a slightly different classification of its activity. shared activity means a shared class.

    If you dont want to think in that way, dont do OOP. it definitely twists the mind to start thinking about it after say pascal, hence the pissed off programmers.

    You detail your instancing robot to the every last difference, and you dont repeat yourself once.

    You only have 1 label/class for every classification difference (not every different thing!), thats the power of OOP... and thats how its similar to some super nueral network for ai, that never runs out of names for different things, because it relies apon the total distribution, to name it.

    -Magnus W.