473,883 Members | 1,659 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

When not to use Object Oriented Programming?

Curtis Rutland
3,256 Recognized Expert Specialist
I was reading through some job postings on a game developer's web site (without any real interest of applying). One of the ones that I saw had this bullet point in the requirements:
  • Appreciation of when not to use Object Oriented Programming.
I've done almost all my work in OO languages...so can someone enlighten me? When do you not want to use OOP?
Dec 23 '08
41 18866
NeoPa
32,584 Recognized Expert Moderator MVP
Ludicrous may be pushing the point a bit far, but I certainly feel that a solution within the concepts of the current model is advisable where possible.

Mix-and-match is likely to introduce confusion when it comes to maintenance etc etc.

PS. Don't be too surprised if you encounter strong partisan feelings on this of all subjects. The discussion is likely to be intelligent and informed - but the feelings may get hotter than the subject matter would indicate.
Jun 12 '09 #31
JosAH
11,448 Recognized Expert MVP
@JohnBoy2
True, but you are changing the problem space now; something that's supposed to be in the list of requirements. The solution you described was just plain stupid; the solution I gave was the best you can get before you came up with the static list requirement.

Indeed if a list doesn't change much and one needs that list all the time, a precomputed total might be the best solution. It all depends on the requirements and feeding parts of the requirements piece meal is not fair play.

kind regards,

Jos
Jun 12 '09 #32
Atli
5,058 Recognized Expert Expert
How about if you... could pass a parameter to the method that lists the reports, and if set, the parameter would have that method count the total when listing the reports, return it via the parameter and set a private variable which the total function would return.

Efficient, no?
Jun 12 '09 #33
JohnBoy2
8 New Member
It all depends on the requirements and feeding parts of the requirements piece meal is not fair play.
It's absolutely not fair, but that is the way the world works. I have never - ever - experienced a project where all the requirements showed up in a nice organized pile right at the beginning of development. And even if you could get it that way, software requirements change over time. What worked last year doesn't fit the bill this year. New products, different ways of doing business, new laws, new taxes, new challenges. Software is a living thing.

Indeed if a list doesn't change much and one needs that list all the time, a precomputed total might be the best solution.
Yes, I agree, and that's the spirit! It just depends. What I've seen time and again is that what we implement during the initial development of a project is optimized for the way the we envision the software at that time. Not long after deployment, however, it becomes clear that the needs of the business change, and usually in ways that were difficult or impossible to foresee (or else we would surely have architected the software to accommodate it). And since the whole thing was optimized for the previous needs, we now have something that is going to be quite difficult to overhaul. Indeed, usually the software is thrown away and a whole new initiative is embarked upon.

Now that's wasteful.

How about if you... could pass a parameter to the method that lists the reports, and if set, the parameter would have that method count the total when listing the reports, return it via the parameter and set a private variable which the total function would return.
That's more like what I would have done, although it might have broken existing code. Since there was only one place that these totals were being asked for, I didn't feel the need to publish some api to encapsulate the totaling of these beans. As soon as we would have received a new set of requirements that dictated totals of these things all over the place, then I might invest the time in re-factoring to take advantage of organizing code that way. Note that what we're talking about now is not really an OO thing, but just good, structured programming.

Back to the OP's question: even optimized, straight-C routines are often nowhere near efficient enough to be used in the inner loops of some aspects of a game engine. I've written compilers that will take elements of the problem space and generate assembly code to get to where we needed to be performance-wise. The more sophisticated the features of a language get (OO or otherwise), the more room there is for the compiler to produce crappy code. It's a well-understood problem in certain areas of software development - games and other real-time sims. certainly among them.

Cheers,

John
Jun 12 '09 #34
JosAH
11,448 Recognized Expert MVP
@JohnBoy2
That is definitely not true: the complexity of the source language doesn't affect the complexity of the target language; for OO languages with single inheritance of implementation one single 'this' pointer per object is enough; it points to the class the object belongs to; the class stores a vft (Virtual Function Table) for all the virtual functions. A simple indirect subroutine call is enough to call one of those functions.

Data member access is completely equal to structure member access; the compiler figured out the offsets and all so the target code is as simple as can be. You haven't been in the correct compiler writers team if you think that target code for complex (OO?) source languages is more complex than others ... Granted the compilers themselves may be more complex than a compiler for a toy language but that's about it.

kind regards,

Jos
Jun 13 '09 #35
weaknessforcats
9,208 Recognized Expert Moderator Expert
What you say is true.

However, JohnBoy is hung up on games and real-time sims. There's no time here for properly created and intialized objects. Everything is hand-made, highly optimized and will never be reused again. These folks don't need OO or OOP by any stretch. Neither do operating system kernal writers.

OO and OOP are for complex systems consisting of hundreds, or thousands of interacting objects where re-use is the prime driver, where the current version that works is the result of an earlier version that also worked. No hand-tailoring here. If there's a resource problem, get a faster computer, or more cores. When changes are made, the ripple of change must be minimal. Therefore, no spaghetti code but instead strict encapsulation. Polymorphism helps to shield the details of the object from the application allowing new obejcts to be added without having to change the application.

Has anyone on this thread read any Grady Booch?
Jun 15 '09 #36
JohnBoy2
8 New Member
Well, I think I can agree with the spirit of what you're saying, but there are a couple points I'd like to clarify:

- I'm not hung up on any particular kind of software - the OP noticed a posting that was from a game company, which is why I am using it as an example.

- Properly initialized data is just as important in high-performance apps. as it is elsewhere, and is definitely not exclusive to OO. There are cases where it won't matter, however, and you can get a marginal boost in performance by not initializing things.

- Re-use is also not exclusive to OO. Many of the highly-optimized processes that have been made for high-performance apps. have been bundled into ibraries that are used again & again. Sometimes those libraries have to be doctored, because some of it is hardware-dependent. I remember having to alter my compiled bitmaps engine to take advantage of 64-bit processors and the new barrel shifters of the time.

- Modern sims and scientific apps. often deal with billions of objects per second, and this is the context that is often difficult for "business developers" to understand. Small increases in performance really matter here. It can mean the difference between being able to model a certain pathogen's mitosis stages fast enough to find a cure or not.

It isn't so much OO as a principle that leads to overkill software, but the silly applications of OO techniques that can lead to large-scale inefficiencies and bad software design. Case in point: JavaBeans. The "specificat ion" for a JavaBean is that it has to have a no-args constructor (no big deal), it must implement the Serializable interface (no big deal), and that its attributes must all be private, accessible only through public getter and setter methods, which imo is a joke.

And it is this kind of thinking that leads to inefficiencies.
Jun 15 '09 #37
JosAH
11,448 Recognized Expert MVP
@JohnBoy2
The example you mention is just a language deficiency: you can't have a publicly read-only property, i.e. if the property is publicly readable it is publicly writeable and vice versa. Setters that simply set a value of an object are silly but I don't see the inefficiency here; C# just camouflages the setters and getters but they are still present behind the scenes. The advantages of those getters and setters are instrumented code, sandboxed code, generated code etc.

Care to elaborate on the 'kind of thinking that leads to inefficiencies' ?

kind regards,

Jos
Jun 16 '09 #38
serdar
88 New Member
I'm not that expert in programming to discuss benefits of OOP but here is a short article by Paul Graham about the matter:

Why Arc Isn't Especially Object-Oriented
Jun 16 '09 #39
JohnBoy2
8 New Member
The example you mention is just a language deficiency: you can't have a publicly read-only property...
I don't know enough about other lang's to say that, but I trust that you do. I think the larger issue for Java is specifications. More than 95% of the JavaBeans I have ever written (or seen others write) all have getters and setters which simply get and set the private variable directly without any processing. This is annoying to code with, and it bloats the software by substantially increasing the size of the codebase, the compiled byte-code to be deployed, the number of methods that need to be unit-tested (even trivially to satisfy coverage metrics from the likes of Clover, et. al.) and even the amount of network traffic in the cases where you are passing these objects over the wire. Moreover, method calls are not free, so every time you want to merely access an attribute on your bean, you're pushing another method call onto the stack.

Small wonder Java has a reputation for being a performance dog and a resource hog. It's not Java itself - it's how it's used by most Java developers.

It's not that getters and setters should never be used, it's that they should only be used when it makes sense. There are occasions when you really don't want anyone to be able to directly change an attribute on a bean. In those cases, by all means make the attribute(s) in question private, and provide accessors to manipulate them.

My argument is that for most routine development, these occasions are the exception not the rule, and we should not be making private attributes with getter/setter methods into a specification that every certificated trendoid instantly takes as gospel and clutters the codebase with.

John
Jun 16 '09 #40

Sign in to post your reply or Sign up for a free account.

Similar topics

34
3218
by: Pmb | last post by:
Hi. I'm new to this group. I'm refreshing/learning C++ and am starting to learn Object Oriented Programming (OOP). In discussing this with people I came up short as to what the benefits of OOP are. For example: As I understand it, OOP has its main benefit in software reuse. Thus one develops a software library of classes and this cuts down the overhead of reinventing the wheel. Someone might say that this can be done with structured...
14
2945
by: Rookie | last post by:
Is C an object oriented programming language?
8
2391
by: Dale | last post by:
I've searched Amazon and read probably 100 reviews but can't find what seems to be any book that is widely accepted as the definitive book on object oriented programming design and techniques. And most of the highest rated are all written 10 to 15 years ago. Any good suggestions?
3
1419
by: David Lozzi | last post by:
Howdy, I've discovered how to create and use a class in ASP.NET. However, when is the best time to use a class? For example, I am currently using session variables to store user information (user id, user name, full name, security level, department, etc.). Would I do better to create a class instead? Also, if I did, would I simply store the ID in the session and when accessing the class (User.FullName, User.SecurityLevel, etc.) then check the...
22
2345
by: Mike Polinske | last post by:
I am new to the C programming language but have been programming in Cobol for over 10 years. When I compile the following code, it compiles clean but I get an application error both under Windows XP and Win2K. #include <stdio.h> #include <ctype.h> char title = "Year End Report";
47
5978
by: Thierry Chappuis | last post by:
Hi, I'm interested in techniques used to program in an object-oriented way using the C ANSI language. I'm studying the GObject library and Laurent Deniau's OOPC framework published on his web site at http://ldeniau.web.cern.ch/ldeniau/html/oopc/oopc.html. The approach is very instructive. I know that I could do much of this stuff with e.g. C++, but the intellectual challenge of implementing these concepts with pure ANSI C is relevant to...
46
3047
by: ajba74 | last post by:
Hi fellows, I am reading some books to learn the C programming language, and sometimes I have the feeling that when somebody becomes a C expert, he must learn a more modern and object-oriented language. When I read things like "... C++ is an evolution of C ..." or "... C is a subset of C++ ..." I tend to believe that I will have to learn C+ + sooner or later. It sounds like C++ is the future and C is the past (and will be no longer...
139
6035
by: Joe Mayo | last post by:
I think I become more and more alone... Everybody tells me that C++ is better, because once a project becomes very large, I should be happy that it has been written in C++ and not C. I'm the only guy thinking that C is a great programming language and that there is no need to program things object oriented. Many people says also that they save more time by programming projects object oriented, but I think its faster to program them in a...
3
1551
by: notnorwegian | last post by:
i have some confusion over this. sure a class is basically a classification, like for example an animal or flower. and an object/instance of that class is then for example a cat. an object is an instance of a class. that i know, i also know how to program with classes etc. i am just confused about the term object-oriented.
0
9789
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11137
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10736
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9570
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7969
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7120
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5795
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5989
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4608
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.