A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: Procedural or Object-Oriented Programming?

  1. #1
    Senior Member
    Join Date
    Oct 2000
    Posts
    518

    resolved

    Perl and PHP code can be written in both procedural and object-oriented style. My question is simple. When to use which?

    I heard that OOP style code executes much slower, because usage of objects and classes slow down the execution of scripts. But I don't know how true this is.

    Anyone?

  2. #2
    Registered User
    Join Date
    Feb 2001
    Posts
    13,041
    Hi,

    it is sort of personal taste...
    but of course use of OO features can make programs more readable, easier to maintain, ....
    So you are sort of trading man hours developing the script for microseconds of computer time. You must be kidding

    Musicman

  3. #3
    Senior Member
    Join Date
    Oct 2000
    Posts
    518

    resolved

    Then how about slowing the program down by using OOP? Is this true or not?

  4. #4
    Senior Member
    Join Date
    Feb 2001
    Posts
    475
    Hi

    well classes execute "slower" that's right. But developing object oriented code ist a lot faster and produces more readable code in the end. Keep in mind that slower doesn't mean it's 3 times slower or sth., it's just a few percent slower. To create fast code it's important to use suitable algorithms and design the memory usage in a reasonable way - not to skip the use of OOP and create hard to debug, non modular spagetty code.
    If you create huge projects like full blown online shops or the likes, not using OOP will end up in a horrible mess of global variables and functions. And such huge projects normally have a powerful server with some caching technology, so the overhead of using classes instead of procedural code doesn't make a big difference for server performance.
    You'll start to love OOP when it comes to severe changes like the switch to another Database - there's quite a difference when u use Pear DB class and just change the login string to switch from mysql to postgres versus replacing all DB functions in all files where they are used...

    my 2 Euro cents on this one
    Yours
    HTD

  5. #5
    Senior Member catbert303's Avatar
    Join Date
    Aug 2001
    Location
    uk
    Posts
    11,222
    You'll start to love OOP when it comes to severe changes like the switch to another Database - there's quite a difference when u use Pear DB class and just change the login string to switch from mysql to postgres versus replacing all DB functions in all files where they are used...
    It is possible to create your own set of database query functions without using OOP though. Whether you use OOP or not it's something everyone should do. Save yourself the hassle of going through hundreds of pages changing all the queries if you ever change your database.

    Is which style of coding is better? I guess it all come down to a matter of taste and in what style you feel more comfortable writing your code. Personally I prefer procedural but...

  6. #6
    Registered User
    Join Date
    Feb 2001
    Posts
    13,041
    Hi,

    lets say everyone should find his/her personal balance. Procedural code does not necessarily imply many globals, and exaggerated OOP probably is not good either.
    The obvious goal is to create maintainable code - this simply means to group related variables and functions in a way that reflects their relations, and to use global variables sparingly
    Commenting on DB functions: neither mysql nor postgres support the sql standard fully, and both add extensions not in the standard. If you want to use pear or access functions of your own, you have to rework your sql so it is a common subset of all the databases that might eventually be used.

    Musicman

  7. #7
    Senior Member
    Join Date
    Feb 2001
    Posts
    475
    lets say everyone should find his/her personal balance.
    Yep that's right. Packing everything in OOP structures is impossible (or at least not maintainable) and not the idea of OOP. the optimal balance should be found, which is probably the most important part when starting any software project.

    My example of switching to a different DB system was just a worst case scenario - if you used lots of addons some DB has another hasn't, it's again much work that's true. I think when using OOP you shouldn't rework what's already there, e.g. create a class that inherits pear DB and add the extensions you need for your DB.

    Procedural code does not necessarily imply many globals
    That's true, but most procedural projects i've seen so far have a lot globals, take phpMyAdmin for example.

    conclusion - i wouldn't stick to one coding style too, my writing about some advances of OOP was adressed to people that don't even consider using it just because they've heard it's "slower". So it was not meant as a general attack against procedural coding.

    Yours
    HTD

  8. #8
    Junior Member
    Join Date
    Dec 2001
    Posts
    14

    MX object-orient or object based

    Is flash MX fully object oriented or is it object based?

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center