Page 1 of 2 12 LastLast
Results 1 to 10 of 21

Thread: Procedural v.s Object oriented programming?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25
    Well if you wanted to take a step back in time and make a non-OOP [Standard] Pascal program, don't declare any classes or lists. Instead use records and arrays alone. This had proved memory intensive for large arrays of records so you could instead allocate a raw chunk, or chunks of memory and then count your data as you go along, this however is instruction intensive, but you have to weigh the benefits of the one to fit the needs of the other. Starting to see one of the reasons why the object oriented approach to allocating 'objects' was something of a breakthrough?

    Also instead of having a triggered reoccurring method (a nono in the pre-OOP world) where your application would cycle, you'll have to keep your code executing inside of a single repeating loop. This means of structuring is still useful today, though it will negate the ability to use multi-threading, a now mainstay in most desktop or laptop computing. Probably not something a super-3D engine would want, but for some smaller and more independent scale games, this works just fine too.

    OOP is great and it adds all kinds of benefits, --such as more organized code, more optimized memory allocation and multi-threading-- however it is still possible to over-objectify all your project code and add more work to what should be a small or quick and dirty game project. As programmers we're allowed to cheat a little to get the job done, like my old highschool CS teacher used to say "programmers are lazy, so we should always try to do things in a way so that we can be lazy." It's a weird way of putting it, but the idea behind it was to code to make your job easier not harder. At least I sure hope that was his message.
    Jason McMillen
    Pascal Game Development
    Co-Founder





  2. #2
    I like procedural more than OOP, in FARC in only use OOP for only one system which is used only in the first part of the game and useless after, it's better to free it.
    I'll use it also for production caculations threads.
    But apart that, it's mainly records/procedures/functions formatted following strict rules.

  3. #3
    PGD Staff code_glitch's Avatar
    Join Date
    Oct 2009
    Location
    UK (England, the bigger bit)
    Posts
    933
    Blog Entries
    45
    And I still don't know what I code in... Don't really want to know either since half the time it's a mess.

    Apart from that, I have written some programs with only procedure, but I would recommend against it for your own moral sanity. In my experience, I would agree with farcodev:
    it's mainly records/procedures/function
    and that would be as far as my vocabulary goes, and seems sufficient.
    I once tried to change the world. But they wouldn't give me the source code. Damned evil cunning.

  4. #4

    re

    I think i use OOP where it belong, I mean mostly when writing libs for been used for me or others programmers, when i want complicated things be translated to be used in an easier way; and where instancing that piece of code has sense.

    I still use plain Procedures & functions with Var parameters and simple Records in my programs when they are just more that enough to implememt somthing;

    I have seen people create class just becouse they can, but not becouse it is necesary; i have seen classes which are too short that with one simple records and 2 or 3 simple procedures should have been enough.

    the other day i was reading a game programming book for C++ where the autor difined into a class the matrix and vectors maths; so he like to use things like mymathlib.vectoradd(v1,v2);

  5. #5
    i've seen some big projects using procedural programming like Blender and Quack .. , personally i like procedural in C/C++ ,and OOP in delphi

  6. #6
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25
    I sort of do both really. I use the structure of OOP to make all my game objects (player or players, enemies, pick-ups, etc) and the game world (map ro level) into an object. And inside of those I create functions and procedures that do the majority of the manipulation of those objects to control that game mechanics.

    Then my main code block is a single loop (no real multi-threading for me like this unfortunately) where I check for what game mode state the game is in and place all my objects' functions in there. I may also have supporting functions which are placed above the main game loop, such as the game reset/initialization block, program startup (init all my SDL, OpenGL, textures, input options, menus, etc...) and clean up after quitting code too.

    Unless you are working for a professional development company, there is no set rule that you have to be all OOP or all procedural, it's all up to you and what is availible with the tools you use. As an indie game rpgrammer, it's about doing it the way YOU want.
    Jason McMillen
    Pascal Game Development
    Co-Founder





  7. #7
    I use OOP mainly. Just something like math unit contains functions and i have no desire to make them classes.. nor should anyone. There are millions of benefits from using classes and i'm pretty sure they're discussed through plenty of times

  8. #8
    Legendary Member NecroDOME's Avatar
    Join Date
    Mar 2004
    Location
    The Netherlands, Eindhoven
    Posts
    1,059
    To work OO with procedures, you can make something like List.pas. This has a function CreateList(): Pointer;
    From this on you can make functions like
    ListAdd(ListPointer: Pionter; item: Pointer);
    ListRemove(ListPointer: Pionter; item: Pointer);
    List...();
    NecroSOFT - End of line -

  9. #9
    Quote Originally Posted by virtual View Post
    i've seen some big projects using procedural programming like Blender and Quack .. , personally i like procedural in C/C++ ,and OOP in delphi
    Now that is interesting. Does anyone know any other big opensource projects that are using the procedural paradigm? I would like to browse through the code to see how they solve problems (that are otherwise solved using Inheritance or other OOP techniques).

    @NecroDOME: Yes, I know what the idea is. OpenGL uses that kind of routines. I kinda like it, but I also like OOP.
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  10. #10
    In my personal projects I tend to use OOP as much as I can, although probably not good enough .

    On the other hand, In my current work I can not do that (although I try hard) since most of our codebase (1.2 million loc approx) is made in procedural and drag-and-drop-onto-the-form style.

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

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