Results 1 to 10 of 10

Thread: What is the difference b/w Procedural/Object oriented programming?

  1. #1
    Join Date
    Dec 2011
    Location
    -bash
    Posts
    515
    Mentioned
    0 Post(s)
    Quoted
    27 Post(s)

    Default What is the difference b/w Procedural/Object oriented programming?

    Basically what the title says

  2. #2
    Join Date
    Dec 2011
    Location
    Nj
    Posts
    2,341
    Mentioned
    1 Post(s)
    Quoted
    18 Post(s)

    Default

    It'll take a long time to explain, everything is different:

    The functions, syntax, and what exactly can be done with it.

    Edit: I think this could be in a more appropriate section of the forums, Perhaps it should be moved to:
    SRL-Forums > Programming > Programming

    For the basics of the basics of pascal, try my TuT. ||Photoshop Editing ||MapleResourceDung Script || Book a flight! BuySellTrip

  3. #3
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    Quote Originally Posted by JoeyGupta View Post
    It'll take a long time to explain, everything is different:

    The functions, syntax, and what exactly can be done with it.

    Edit: I think this could be in a more appropriate section of the forums, Perhaps it should be moved to:
    SRL-Forums > Programming > Programming

    Functions are the exact same in Procedural Programming vs. Object Oriented programming in C/C++

    The difference is the objects of course.

    Procedural Programming uses mostly functions to get everything done. To simulate an object, you'd use a function with a bunch of variables and return a value that can be used to do something else.

    Object Oriented programming is a structural type of programming which has a heavy utilization of Classes, Structs, Unions, Inheritance, Polymorphism, Pimpl Idioms, RAII, Interfaces, and Abstracts.
    Object Oriented programming is mainly used for encapsulation!

    You can say that Objects have Properties and accessors whereas Procedural programming does not.

    How would you represent A Table In Procedural Programming? Well you'd probably make a bunch of vars like so:

    C++ Code:
    int TableTopW = 10;
    int TableTopH = 10;
    int LegLength = 10;
    int LegThickness = 5;
    int TableTopArea = TableTopWidth * TableTopHeight;
    bool RoundTable = false; //Square = True;
    bool RoundLegs = true; //Square = False;

    void CreateTable(int &TopWidth, int &TopHeight, int &LegLen, int &LegThick, bool &RoundTop, bool &RoundLegs)
    {
    //Create Some Tables and have our Parameters hold the values for each table made! This can probably be thousands of variables.
    }


    //The above code provides no encapsulation and can be accessed and changed at any moment in time.
    //The above can represent anything.. Any table. We cannot have two tables with the same variables because
    //editing one will change the other.. Another thing, Tables variables if allocated on the heap will not delete
    //automatically!


    class Table
    {
    private:
    int TTW, TTH, LL, LT;
    int TTA;
    bool RT, RL;

    public:
    Table(int TopWidth, int TopHeight, int LegLen, int LegThick, bool RoundTop, bool RoundLegs);
    ~Table();

    int GetTopArea();
    }

    Table::Table(int TopWidth, int TopHeight, int LegLen, int LegThick, bool RoundTop, bool RoundLegs) : TTW(TopWidth), TTH(TopHeight), LL(LegLen), LT(LegThick), RT(RoundTop), RL(RoundLegs){}
    Table::GetTopArea(){ return TTW * TTH;}

    //Now this provides the user an interface. Every time you want to make a new table, you simple call the constructor like so:
    Table FirstTable = Table(10, 10, 10, 5, true, false);
    Table SecondTable = Table(50, 50, 25, 15, false, true);

    //I've just created two tables without extra variables and stuff.. These tables have properties that can be accessed through the . operator or -> operator depending
    //on how it was constructed.

    //In Procedural programming, I'd have to make separate variables for EACH table! And Creating a new table will not be so easy!

    Now referring to RAII classes, if your object has a pointer member, the class will automatically delete it on deconstruction if implemented right. You don't have to worry about anything. The user will be a happy lad.

    Now in Procedural programming, you miss one thing and bam your code blows up in your face. For every new/new[] you have to remember to delete/delete[] respectively.

    The functions within an object and outside an object are the same syntax and thus the same thing except one is encapsulated and the other isn't. One can use the same variables for different objects constructed whereas the other may need to be passed these variables as parameters for every thing you want.

    Now this may not be a practical answer but it explains what is needed to know. The reason it's not practical is because I used basic functions and strict Procedural programming with no classes or objects. But because of this example, it shows a far better understanding than if I were to mix them both. Hope you understand.

    Now I know this example fails to show the usefulness of Procedural programming but think of it this way. Without Procedural programming, for everything you'd be constructing an object that contains the function you need. Or accessing some random namespace.

    No one wants to do that for every single thing! So hence we have Procedural programming for global things, for things we will be doing over and over (we just call a simple function, etc).

    If you check out a fully object oriented language such as C#, you will notice there are no such things as global functions. A class must be constructed within the same namespace. That class will contain your function and you have to access it through that class/object.

    In other words, Learn both Procedural and object oriented programming because BOTH have their advantages over the other!
    Last edited by Brandon; 06-30-2012 at 08:50 AM.
    I am Ggzz..
    Hackintosher

  4. #4
    Join Date
    May 2012
    Location
    Texas
    Posts
    365
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    +1 After 2 years of computer science I was asking myself the same question
    Mostly Inactive, School

  5. #5
    Join Date
    Sep 2006
    Posts
    6,089
    Mentioned
    77 Post(s)
    Quoted
    43 Post(s)

    Default

    Brandon, you are talking about procedural, not functional programming.
    Chig, just consult Wikipedia.
    Hup Holland Hup!

  6. #6
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    Quote Originally Posted by nielsie95 View Post
    Brandon, you are talking about procedural, not functional programming.
    Chig, just consult Wikipedia.
    His thread Title says: "What is the difference b/w Procedural/Object oriented programming?"I tend to call Procedure Functional because Functional is also sometimes called Statistical programming and calling it the other way confuses me sometimes. Logic is there though.
    I know what you mean though.. That O^N* Sorting Algorithms, recurssion, lambdas and what not. I'll edit my Post terms so OP doesn't get confused.
    Last edited by Brandon; 06-30-2012 at 08:50 AM.
    I am Ggzz..
    Hackintosher

  7. #7
    Join Date
    May 2007
    Posts
    526
    Mentioned
    12 Post(s)
    Quoted
    109 Post(s)

    Default

    Quote Originally Posted by Brandon View Post
    Functions are the exact same in Procedural Programming vs. Object Oriented programming in C/C++

    ...
    For the reference, there is no such language as C/C++. There is C and then there is C++. You don't have objects/classes in C.

  8. #8
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    Quote Originally Posted by superuser View Post
    For the reference, there is no such language as C/C++. There is C and then there is C++. You don't have objects/classes in C.
    Why so picky? I've used C/C++ only once in my answer and it simply explains the concept to the OP. That statement is completely untrue and doesn't answer OP's question. This is object oriented programming in C:

    http://msdn.microsoft.com/en-us/libr...ice.12%29.aspx

    It's done with a C++ concept using vTables and polymorphism. You don't have provided classes in C but it doesn't mean you cannot program objects. There are tons of examples showing OOP programming in C on google and StackOverflow. Not only that, a lot of programmers use C/C++ when referring to thigns that can possibly be done in both or sometimes completely unrelated. The reason is because we all know that C/C++ go almost hand in hand and in this case, I used it "once" and correctly.
    Last edited by Brandon; 06-30-2012 at 03:11 PM.
    I am Ggzz..
    Hackintosher

  9. #9
    Join Date
    May 2007
    Posts
    526
    Mentioned
    12 Post(s)
    Quoted
    109 Post(s)

    Default

    Quote Originally Posted by Brandon View Post
    Why so picky? I've used C/C++ only once in my answer and it simply explains the concept to the OP. That statement is completely untrue and doesn't answer OP's question. This is object oriented programming in C:

    http://msdn.microsoft.com/en-us/libr...ice.12%29.aspx

    It's done with a C++ concept using vTables and polymorphism. You don't have provided classes in C but it doesn't mean you cannot program objects. There are tons of examples showing OOP programming in C on google and StackOverflow. Not only that, a lot of programmers use C/C++ when referring to thigns that can possibly be done in both or sometimes completely unrelated. The reason is because we all know that C/C++ go almost hand in hand and in this case, I used it "once" and correctly.
    Encapsulation is pretty easy, polymorphism is doable, but inheritence is tricky. Ok, I got your point I shall stand corrected!

  10. #10
    Join Date
    Apr 2007
    Posts
    581
    Mentioned
    1 Post(s)
    Quoted
    2 Post(s)

    Default

    Wikipedia actually has a really good comparison of the two.

    Quote Originally Posted by Wikipedia
    The focus of procedural programming is to break down a programming task into a collection of variables, data structures, and subroutines, whereas in object-oriented programming it is to break down a programming task into objects that expose behavior (methods) and data (members or attributes) using interfaces. The most important distinction is whereas procedural programming uses procedures to operate on data structures, object-oriented programming bundles the two together so an "object", which is an instance of a class, operates on its "own" data structure.
    Nomenclature varies between the two, although they have similar semantics.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •