View Poll Results: Which one do you prefer, in general?

Voters
19. You may not vote on this poll
  • OOP

    6 31.58%
  • Procedural

    13 68.42%

OO vs. Procedural Programming

This is a discussion on OO vs. Procedural Programming within the Tech Board forums, part of the Community Boards category; After doing OOP for so many years, I've come to realize that programs are shorter, easier, and simpler to write ...

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    648

    OO vs. Procedural Programming

    After doing OOP for so many years, I've come to realize that programs are shorter, easier, and simpler to write without it. You don't need classes for basically anything. Take a look at VB, it does everything without classes (except COM) using types and handles.

    Quote for horstmann.com:
    Code:
    C
       printf("%10.2f", x); 
    
    C++
       cout << setw(10) << setprecision(2) << showpoint << x; 
    
    Java
       java.text.NumberFormat formatter    = java.text.NumberFormat.getNumberInstance();
       formatter.setMinimumFractionDigits(2);
       formatter.setMaximumFractionDigits(2);
       String s = formatter.format(x);
       for (int i = s.length(); i < 10; i++)
         System.out.print(' ');
       System.out.print(s);
    What are your thoughts on OOP? For the majority of all programming, is it truly neccesary?

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    All the stuff I do, at home (which isn't much nowadays) and at work is done in C. I encapsulate where ever I can, and try to make the code re-usable, but none of that is true OOP. I've looked at OOP in the past, but have basically found that (to me), "programs are shorter, easier, and simpler to write without it".

    I guess if I'd learnt OOP before procedural I'd think different, but changing old habits is hard.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    I learned OOP first, and I personally do like C's way of doing things. I find it much less bloated.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  4. #4
    ~- Y u n a -~ beely's Avatar
    Join Date
    Dec 2001
    Posts
    291
    l'd love using C rather than Java, i don't know why i would make this decision eventhough java is popular nowadays and even lot of ppl still using it. i kinda very lazy to include some of the classes.

  5. #5
    The Defective GRAPE Lurker's Avatar
    Join Date
    Feb 2003
    Posts
    949
    Cout is OOP.
    Do not make direct eye contact with me.

  6. #6
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Thank you, Mr. Obvious.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  7. #7
    Registered User khpuce's Avatar
    Join Date
    May 2003
    Posts
    165
    I am kinda a newbie in OOP but I think OOP is not suitable for small projects (its a pain in my opinion) but is particularly helpful for large projects.

    P.S. Please don't ask me to define large projects cause I can't

  8. #8
    5|-|1+|-|34|) ober's Avatar
    Join Date
    Aug 2001
    Posts
    4,429
    Procedural........ because I really know no other way. I've done tiny bits of OOP, but for most of the stuff I do, it's unnecessary.

  9. #9
    Registered User
    Join Date
    Mar 2004
    Posts
    15

    Re: OO vs. Procedural Programming

    Originally posted by Speedy5
    Take a look at VB, it does everything without classes (except COM) using types and handles.
    Nope, VB can do everything except COM without classes, or it can use classes extensively. Essentially the same choice as you have with C++ (except C++ does classes better).

    Code:
    C
       printf("%10.2f", x);
    %10.2f is essentially another language to learn in addition to C.

    Code:
    C++
       cout << setw(10) << setprecision(2) << showpoint << x;
    The first time you see this you are likely to guess that setprecision(2) sets some sort of precistion to 2, and that showpoint means that points are, em, shown.
    setw(10) is easy to remember once you learn also.

    Hardly a conclusive defense of C++'s streams over C's but there are some ways in which C++'s is simpler.

    Really, OO owns for large complex projects. Getting to know and love OO from those projects may lead you to use it for smaller projects also, but procedural will do fine.

  10. #10
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,484
    > large projects
    There is a unit called a "head full", which measures the amount of information (say a program) which you can imagine and understand all at the same time.

    A small program would be say a simple calculator.
    A large program would be say DOOM.

    Somewhere along the line, the number of headfull's gets too big for you to handle, so its time to start writing things down and making a decent job of the design in the first place.

    OO has nothing to do with the language you choose to implement your solution in, it is simply a way of thinking about the problem. Sure it may make sense to use an OO language if your design is heavy with inheritance and polymorphism, but its not a given.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  11. #11
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    OOP is simply a way of organizing a project. For smaller projects there is little or no use in OOP, but for large projects it can simplify things considerably. If all you think of is code size then procedural programming will almost always be superior, but when you tack on analysis and design (as you should), OOP begins to show its strengths.

    In the end it comes down to the needs of the project. Most of my work doesn't need a heavy hitter like OOP, and I have never come across a need for inheritance. However, I don't work in fields where OOP would be more appropriate than procedural programming, such as Windowing systems.

    Many of OOP's traits are used by procedural programmers as well. Encapsulation and abstraction are two big ones. If you've ever written a data structure library in C then you know that the lessons of OOP play a part even though you technically aren't using OOP. Which brings me around in a full circle, OOP is simply a way of organizing your project. Some of its parts are useful all of the time, but as a whole, it depends on the needs of the project.
    My best code is written with the delete key.

  12. #12
    Registered User
    Join Date
    Mar 2004
    Posts
    15
    Originally posted by Lurker
    Cout is OOP.
    Yes, but it's not very OO to just make use of cout.
    cout is also template-based, but you wouldn't know it from just looking at the code example above.

    There are degrees of how OO something is. While it makes little sense to begin a very small project by designing an object model and then implementing it you can make use of OO throughout a mainly procedural project such as using cout rather than printf if you find it preferable to printf (I do) or if RAII makes sense for a given resource.

    Things aren't necessarily as polarised as the question above suggests.

  13. #13
    The Defective GRAPE Lurker's Avatar
    Join Date
    Feb 2003
    Posts
    949
    No matter how you look at it (and no matter how obvious it is ), cout is basic OOP .
    Do not make direct eye contact with me.

  14. #14
    Registered User
    Join Date
    Jan 2003
    Posts
    648
    OOP is a way of organizing your code and in some cases making it easier to understand and write. However, procedural programming works for basically everything. Most operating systems are written in C, most compilers are written in C, games like DOOM and Descent were written in C (newer games have OOP in them).

    Procedural programming seems to be the best for all small projects. For example, web sites don't need OOP. Games don't neccesarily need OOP. Most practical applications, such as those written in VB, don't use OOP at all.

    OOP might be needed in large projects but thinking about the majority of all programs, is it really needed? Is it worth spending the time and effort designing classes if you could acheive the same thing easier with functions?

    Say you were making a client/server application where the client send data for the server to process, resulting in an image presented in the client's screen. It seems like an average project. OOP isn't needed for it, it can easily be acheived using just functions. Having SocketListener interfaces and DataStreamReaderFormatConverter and stupid classes that really don't do much other than marshall data is dumb (I made those classes up).

  15. #15
    ~- Y u n a -~ beely's Avatar
    Join Date
    Dec 2001
    Posts
    291
    hmm ... i don't think it might have different between OOP and procedural language. it's only different is about how the statements were arranged, structured and so on. beside, if i'm not mistaken, procedural languages still can work and solve the situation althought it couldn't support poly, inheritance, and etc. any comments ?

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Procedural Noise and OpenGL Help!
    By Freestyler in forum C Programming
    Replies: 8
    Last Post: 04-18-2008, 08:06 AM
  2. array bounds overflow
    By BendingUnit in forum C Programming
    Replies: 3
    Last Post: 06-18-2006, 10:45 PM
  3. OO Design regarding returning a value from an object
    By filler_bunny in forum C++ Programming
    Replies: 6
    Last Post: 08-24-2003, 05:57 AM
  4. OO in C
    By Shiro in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 01-05-2002, 10:02 PM
  5. OO programming
    By iwod in forum C++ Programming
    Replies: 1
    Last Post: 11-15-2001, 07:31 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21