# OOP vs Procedural

**URL:** <https://forum.kirupa.com/t/oop-vs-procedural/262869>\
**Category:** classic bestof\
**Created:** [June 10, 2008, 6:22pm UTC](https://forum.kirupa.com/t/oop-vs-procedural/262869 "2008-06-10T18:22:30Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![digitalmatt](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/digitalmatt/32/694_2.png) [@digitalmatt](https://forum.kirupa.com/u/digitalmatt)\
**Post date:** [June 10, 2008, 6:22pm UTC](https://forum.kirupa.com/t/oop-vs-procedural/262869/1 "2008-06-10T18:22:30Z")

</div>

I’m sure this has been asked around here before. But now that we have Actionscript 3.0, there is so much temptation for me to attempt to build every project to be object-oriented.

How can we know when to choose OOP over Procedural? What should be considered?

The only thing that I can really think of is that if the project is huge, OOP would be a safer bet. But, then again, that might not necessarily be true.

How do I decide?

---

<div class="post-metadata">

**Author:** ![Iamthejuggler](https://avatars.discourse-cdn.com/v4/letter/i/ecc23a/32.png) [@Iamthejuggler](https://forum.kirupa.com/u/Iamthejuggler)\
**Post date:** [June 10, 2008, 6:40pm UTC](https://forum.kirupa.com/t/oop-vs-procedural/262869/2 "2008-06-10T18:40:44Z")

</div>

Once you get into the habit of programming with an OOP mentality i don’t think i would approach any project, no matter the size, in a non-OOP way. It’s just far more maintainable, tidy, and easier to organise. A project would have to be really really small to justify procedural based programming. But then i know some people think otherwise.

---

<div class="post-metadata">

**Author:** ![Anogar](https://avatars.discourse-cdn.com/v4/letter/a/ed655f/32.png) [@Anogar](https://forum.kirupa.com/u/Anogar)\
**Post date:** [June 10, 2008, 6:43pm UTC](https://forum.kirupa.com/t/oop-vs-procedural/262869/3 "2008-06-10T18:43:36Z")

</div>

An object oriented approach is pretty much always better. I can’t think of a situation that should be approached with outdated coding practices. 😛

---

<div class="post-metadata">

**Author:** ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)\
**Post date:** [June 10, 2008, 6:47pm UTC](https://forum.kirupa.com/t/oop-vs-procedural/262869/4 "2008-06-10T18:47:33Z")

</div>

[QUOTE=Anogar;2340232]An object oriented approach is pretty much always better. I can’t think of a situation that should be approached with outdated coding practices. :P[/QUOTE]

Performance 😉

---

<div class="post-metadata">

**Author:** ![Anogar](https://avatars.discourse-cdn.com/v4/letter/a/ed655f/32.png) [@Anogar](https://forum.kirupa.com/u/Anogar)\
**Post date:** [June 10, 2008, 6:49pm UTC](https://forum.kirupa.com/t/oop-vs-procedural/262869/5 "2008-06-10T18:49:11Z")

</div>

> [@senocular;2340238](#):
>
> Performance 😉

Okay, I suppose that certain especially simple tasks should be done the old fashioned way. Banners come to mind, using a complex OOP approach on something like that could be kinda dumb.

Don’t shatter my illusion Senocular, I like to think I’m a real programmer! :lol:

---

<div class="post-metadata">

**Author:** ![rumblesushi](https://avatars.discourse-cdn.com/v4/letter/r/b38774/32.png) [@rumblesushi](https://forum.kirupa.com/u/rumblesushi)\
**Post date:** [June 10, 2008, 6:51pm UTC](https://forum.kirupa.com/t/oop-vs-procedural/262869/6 "2008-06-10T18:51:57Z")

</div>

> [@senocular;2340238](#):
>
> Performance 😉

Could you elaborate please sen?

Creatify kindly converted a function of mine (motion graphics) into classes, and he did a perfect job, it’s exactly the same, but it uses 10% more CPU power.

---

<div class="post-metadata">

**Author:** ![digitalmatt](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/digitalmatt/32/694_2.png) [@digitalmatt](https://forum.kirupa.com/u/digitalmatt)\
**Post date:** [June 10, 2008, 7:32pm UTC](https://forum.kirupa.com/t/oop-vs-procedural/262869/7 "2008-06-10T19:32:37Z")

</div>

> [@Iamthejuggler;2340228](#):
>
> Once you get into the habit of programming with an OOP mentality i don’t think i would approach any project, no matter the size, in a non-OOP way. It’s just far more maintainable, tidy, and easier to organise. A project would have to be really really small to justify procedural based programming. But then i know some people think otherwise.

Okay, maybe we could discuss an example. Let’s say I was going to build a portfolio site. I’ve got three basic sections: about, contact, and of course, portfolio.

The only semi-complex part of this site is the portfolio section. The portfolio is broken up into five subcategories. And each category has an average of seven or so projects. All the information about each project is, of course, stored in a database. That data is retrieved with a server-side script that formats it into XML. We, of course, pull it into flash and sort through it with the XML object.

Would it be a pain to give me a summary of how you might achieve this with OOP?

---

<div class="post-metadata">

**Author:** ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)\
**Post date:** [June 10, 2008, 8:28pm UTC](https://forum.kirupa.com/t/oop-vs-procedural/262869/8 "2008-06-10T20:28:04Z")

</div>

[QUOTE=rumblesushi;2340242]Could you elaborate please sen?

Creatify kindly converted a function of mine (motion graphics) into classes, and he did a perfect job, it’s exactly the same, but it uses 10% more CPU power.[/QUOTE]

Basically its the extra overhead resulting from the creation of objects and method calls needed to facilitate communication between those objects. Obviously as you start reducing that overhead and take a more direct, procedural approach, you’ll gain some performance benefits. But usability, extensibility, and maintainability (+ ility of your choice) start to waver.

---

<div class="post-metadata">

**Author:** ![Anogar](https://avatars.discourse-cdn.com/v4/letter/a/ed655f/32.png) [@Anogar](https://forum.kirupa.com/u/Anogar)\
**Post date:** [June 10, 2008, 8:33pm UTC](https://forum.kirupa.com/t/oop-vs-procedural/262869/9 "2008-06-10T20:33:56Z")

</div>

You might do it something like this:

```auto

--DocumentClass 
------SiteDataClass
             ----LoadXML() method
             ----get XML method
------SiteInterfaceClass
             ----DrawPortfolio() method
             ----DrawAbout() method
             ----DrawContact method

```

Obviously that’s really loose, but it might give you a brief idea of how you could do it.

---

<div class="post-metadata">

**Author:** ![digitalmatt](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/digitalmatt/32/694_2.png) [@digitalmatt](https://forum.kirupa.com/u/digitalmatt)\
**Post date:** [June 10, 2008, 8:40pm UTC](https://forum.kirupa.com/t/oop-vs-procedural/262869/10 "2008-06-10T20:40:13Z")

</div>

[quote=Anogar;2340292]You might do it something like this:

```auto

--DocumentClass 
------SiteDataClass
             ----LoadXML() method
             ----get XML method
------SiteInterfaceClass
             ----DrawPortfolio() method
             ----DrawAbout() method
             ----DrawContact method

```

Obviously that’s really loose, but it might give you a brief idea of how you could do it.[/quote]

That’s a good diagram. What happens if you have tons of complex animation in your portfolio movie. I know I could have a movieclip in my library with a class name of “portfolio.” And I could put it on the stage from the document class by referencing its class name. What would be the real difference if that movieclip sits on say frame 15 of the main timeline?

---

<div class="post-metadata">

**Author:** ![snickelfritz](https://avatars.discourse-cdn.com/v4/letter/s/7ea924/32.png) [@snickelfritz](https://forum.kirupa.com/u/snickelfritz)\
**Post date:** [June 10, 2008, 9:04pm UTC](https://forum.kirupa.com/t/oop-vs-procedural/262869/11 "2008-06-10T21:04:26Z")

</div>

It would be silly to write \>2000 lines of custom actionscript on the timeline.  
Use classes to break down large complex scripts into more manageable sections.  
50 lines of basic website navigation code is easier to manage on the timeline IMO.

BTW, Lee Brimelow recently released the “[[COLOR=“Blue”][U]snippet panel[/U][/COLOR]](http://theflashblog.com/?p=336)” for Flash.  
It’s a nifty place to store frequently used blocks of code, and makes scripting on the timeline a snap.  
For example, I have all of the code required to set up a complete website stored in the snippets panel.  
Takes about 30 seconds to set up the basic code for the entire site, and it works correctly the first time, every time.🙂

---

<div class="post-metadata">

**Author:** ![krilnon](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/krilnon/32/34_2.png) [@krilnon](https://forum.kirupa.com/u/krilnon)\
**Post date:** [June 10, 2008, 10:49pm UTC](https://forum.kirupa.com/t/oop-vs-procedural/262869/12 "2008-06-10T22:49:30Z")

</div>

You might want to consider interestingness when deciding which programming style you want to use. Personally, my projects seem to turn out better when I am able to find an amusing way to solve some given problem.

---

<div class="post-metadata">

**Author:** ![Fidodo](https://avatars.discourse-cdn.com/v4/letter/f/779978/32.png) [@Fidodo](https://forum.kirupa.com/u/Fidodo)\
**Post date:** [June 10, 2008, 10:51pm UTC](https://forum.kirupa.com/t/oop-vs-procedural/262869/13 "2008-06-10T22:51:26Z")

</div>

Well you should always be using the Document Class so you would always be working with classes and at least one object. And you are always using other object oriented classes because your going to extend a DisplayObject, so technically you can’t program procedurally. But I’d say only program procedurally if you don’t happen to need any other classes. But that would be a pretty simple program.

---

<div class="post-metadata">

**Author:** ![Pier25](https://avatars.discourse-cdn.com/v4/letter/p/4af34b/32.png) [@Pier25](https://forum.kirupa.com/u/Pier25)\
**Post date:** [June 11, 2008, 12:42am UTC](https://forum.kirupa.com/t/oop-vs-procedural/262869/14 "2008-06-11T00:42:42Z")

</div>

[QUOTE=Krilnon;2340379]Personally, my projects seem to turn out better when I am able to find an amusing way to solve some given problem.[/QUOTE]

You’re totally right 🙂

---

<div class="post-metadata">

**Author:** ![digitalmatt](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/digitalmatt/32/694_2.png) [@digitalmatt](https://forum.kirupa.com/u/digitalmatt)\
**Post date:** [June 11, 2008, 12:51am UTC](https://forum.kirupa.com/t/oop-vs-procedural/262869/15 "2008-06-11T00:51:27Z")

</div>

> [@Krilnon;2340379](#):
>
> You might want to consider interestingness when deciding which programming style you want to use. Personally, my projects seem to turn out better when I am able to find an amusing way to solve some given problem.

If you don’t mind, can you give me an example? 🙂

---

<div class="post-metadata">

**Author:** ![krilnon](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/krilnon/32/34_2.png) [@krilnon](https://forum.kirupa.com/u/krilnon)\
**Post date:** [June 11, 2008, 3:35am UTC](https://forum.kirupa.com/t/oop-vs-procedural/262869/16 "2008-06-11T03:35:03Z")

</div>

^ Check your PMs.

---

<div class="post-metadata">

**Author:** ![TheCanadian](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@TheCanadian](https://forum.kirupa.com/u/TheCanadian)\
**Post date:** [June 11, 2008, 4:32am UTC](https://forum.kirupa.com/t/oop-vs-procedural/262869/17 "2008-06-11T04:32:58Z")

</div>

[QUOTE=Krilnon;2340473]^ Check your PMs.[/QUOTE]

Yeah PMS is a \*\*\*\*\*.

har har har 😑

---

<div class="post-metadata">

**Author:** ![digitalmatt](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/digitalmatt/32/694_2.png) [@digitalmatt](https://forum.kirupa.com/u/digitalmatt)\
**Post date:** [June 11, 2008, 5:17am UTC](https://forum.kirupa.com/t/oop-vs-procedural/262869/18 "2008-06-11T05:17:44Z")

</div>

[quote=TheCanadian;2340504]Yeah PMS is a \*\*\*\*\*.

har har har :|[/quote]

yuk yuk :hugegrin:

---

<div class="post-metadata">

**Author:** ![ajcates](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/ajcates/32/2435_2.png) [@ajcates](https://forum.kirupa.com/u/ajcates)\
**Post date:** [June 11, 2008, 5:42am UTC](https://forum.kirupa.com/t/oop-vs-procedural/262869/19 "2008-06-11T05:42:08Z")

</div>

I use like a very basic oop way of handling even the smallest of things, I write out functions to handle alot of stuff, have like a main function. So its like I only use one class, except I don’t put it in the document class rather on the frame because I like the way I don’t have to type out public or private before my functions and variables.

For a web site project like digitalmatt was talking about, I would use Anogar method, but you can have like animation classes and other things to go along with his method it’s just an outline.

---

<div class="post-metadata">

**Author:** ![digitalmatt](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/digitalmatt/32/694_2.png) [@digitalmatt](https://forum.kirupa.com/u/digitalmatt)\
**Post date:** [June 11, 2008, 5:53am UTC](https://forum.kirupa.com/t/oop-vs-procedural/262869/20 "2008-06-11T05:53:45Z")

</div>

[quote=ajcates;2340511]I use like a very basic oop way of handling even the smallest of things, I write out functions to handle alot of stuff, have like a main function. So its like I only use one class, except I don’t put it in the document class rather on the frame because I like the way I don’t have to type out public or private before my functions and variables.

For a web site project like digitalmatt was talking about, I would use Anogar method, but you can have like animation classes and other things to go along with his method it’s just an outline.[/quote]

That’s sort of the way I program. For a task I know I’ll repeat over and over, I write flexible functions I can easily call and maybe pass some arguments to – though that’s probably considered programming 101.

To me, though code can be more manageable written in custom classes, it seems like there’s a time and place for it. But, since I’ve been practicing with AS3’s document class, it makes so much more sense to write custom classes. At the same time, however, I feel I’m writing a whole lot more code to simple things that can be achieved with basic functions sitting in a frame on the main timeline.

Am I making sense?

[Next page](https://forum.kirupa.com/t/oop-vs-procedural/262869.md?page=2)
