The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 42

Thread: OOP vs Procedural

  1. #16
    ^ Check your PMs.
    “Who were you, Krilnon, and how did you know so much about AS4?”
    The historian sighed as she gazed up at the sky and saw… not stars. A story.

  2. #17
    TheCanadian's Avatar
    10,305
    posts
    Noo doot aboot it, eh?
    Quote Originally Posted by Krilnon View Post
    ^ Check your PMs.
    Yeah PMS is a *****.


    har har har
    Proud Montanadian
    We tolerate living and breathing. And niches.

    Name Brand Watches

    Maybe getTimer() or TweenMax is the answer to your problem . . .

  3. #18
    Quote Originally Posted by TheCanadian View Post
    Yeah PMS is a *****.


    har har har
    yuk yuk

  4. #19
    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.

  5. #20
    Quote Originally Posted by ajcates View Post
    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.
    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?

  6. #21
    Quote Originally Posted by ajcates View Post
    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.
    There are some very real reasons to do object oriented programming the way it's intended, in class files. Things like public and private have very real meanings, and when used properly they make your life a whole lot easier - especially when working with multiple developers or sharing classes between multiple projects.

    It's hard to understand the power of OOP until you've spent some good time using it, and seeing how much time it saves you over the course of a few projects.

  7. #22
    Quote Originally Posted by Anogar View Post
    There are some very real reasons to do object oriented programming the way it's intended, in class files. Things like public and private have very real meanings, and when used properly they make your life a whole lot easier - especially when working with multiple developers or sharing classes between multiple projects.

    It's hard to understand the power of OOP until you've spent some good time using it, and seeing how much time it saves you over the course of a few projects.
    Yeah, that's another thing that the Java developers I work with tell me...OOP makes working on large team projects immensely easier. Especially if all the developers are working on different, but related chunks of code.

  8. #23
    It's also very helpful when you want to reuse a class between projects. The whole thing is really more about ways to make your projects easier over the long run.

  9. #24
    TheCanadian's Avatar
    10,305
    posts
    Noo doot aboot it, eh?
    I do every Flash project solely with AS3 (I don't even own CS3, wtf right) so without OOP it would be freaking redic. One of the cool things about AS3 is helper classes. It allows you to fully utilize OOP but without having to create a billion different classes which you'll never ever use again in a million years.

    Take this for example:
    Code:
    package {
    	import flash.display.Sprite;
    	import flash.events.Event;
    	import flash.events.MouseEvent;
    	import jm.geom.Point3D;
    	public class ShiftingNodeNetwork extends Sprite {
    		private var nodes:Array = new Array();
    		private var maxDistance:Number;
    		public var axisRotations:Object = new Object();
    		public function ShiftingNodeNetwork(width:Number, height:Number, depth:Number, distance:Number, ease:Number, numNodes:Number) {}
    		public function start():void {}
    		public function stop():void {}		
    		private function connect(evt:Event):void {}
    	}
    }
    
    import flash.display.Shape;
    import flash.events.Event;
    import jm.geom.Point3D;
    import jm.math.Random;
    class RandomNode extends Shape {
    	private var coord:Point3D;
    	private var targCoord:Point3D;
    	private var ease:Number;
    	private var wc:Number;
    	private var hc:Number;
    	private var dc:Number;
    	public function RandomNode(w:Number, h:Number, d:Number, e:Number) {}
    	private function move(evt:Event):void {}
    	public function get location():Point3D {}
    	public function start(evt:NodeEvent):void {}
    	public function stop(evt:NodeEvent):void {}
    }
    That's just a snippet from one of my experiments with mose of the code removed for clarity. I used the RandomNode as a helper because when would I ever need that class again? Now the classes in there that I do use between multiple projects (like NodeEvent, Point3D) have there own class file so I can import them for another project.

    After a while you can start making your own library, organized into packages, that you can access from any file. Saves you from having to search through multiple timelines of code to find what you're looking for.
    Proud Montanadian
    We tolerate living and breathing. And niches.

    Name Brand Watches

    Maybe getTimer() or TweenMax is the answer to your problem . . .

  10. #25
    I've been wondering that too, but seems like no body answer digitalmatt's question about animation, how to we structure it with OOP style without using timeline. and it is better to animate it in that movieclip's timeline and then instantiate it from the document class?

  11. #26
    Quote Originally Posted by ismejks View Post
    how to we structure it with OOP style without using timeline. and it is better to animate it in that movieclip's timeline and then instantiate it from the document class?
    That's a good question!

    But I don't think you have to throw the baby out with the bathwater. The timeline is great for doing animation. Could you not just do all your animation in the Flash IDE, embed the SWF into a class, and then control the animation from that class?

    Or, if you don't want to use the Flash IDE, create the animations in a tilesheet, cache them as Sprites or Bitmaps in an array when the class initializes, and then build your own custom AnimationPlayer class that does the job of displaying them in sequence. That might be reinventing the wheel, but then again it might give you a bit more control too.

    Regarding OOP vs. Proceedural... when I'm testing out new techniques, I always code procedurally. Because everything is on one place, it helps me to better see and understand the relationships. I then OOPify it later to incorporate it into a big project.

    Also, for really small projects (say under 100 lines or so, like the banner add or a simple interactivity) procedural programs are really much quicker and more efficient to code.

  12. #27
    1,596
    posts
    Holosuite User
    AS1, AS2 and AS3 all are OO languages. You cannot code in procedural way in AS because everything in AS is an object - procedural doesn't have a concept of object. Flash IDE gives you a template, which is the timeline, where some necessary stuff (like class declaration) is hidden from you, but that's about it. It is also a bit confusing question because if you break OO language down to the very basic pieces, you may find it out that every such piece may be defined as procedure, but this again doesn't mean that the language is procedural.
    It's like lego - when you put pieces together you may get a new entity, that won't be just a collection of lego pieces, and you'd call it differently, while, at the same time it will be de facto a collection of lego pieces.

    I support FlashDevelop (the .NET open source editor for Flash and web developers)
    couchsurfing if you need it

  13. #28
    Quote Originally Posted by wvxvw
    It's like lego - when you put pieces together you may get a new entity, that won't be just a collection of lego pieces, and you'd call it differently, while, at the same time it will be de facto a collection of lego pieces.
    It's not just a collection of Lego pieces, but it is still a collection of Lego pieces. A MovieClip is not just an Object, but it is still an Object, and it's (often) okay if a particular programmer just treats it as an Object. Similarly, if you just treat ActionScript as a procedural language, it is okay that it is also object oriented. (I'm not trying to imply that there is a hierarchical relationship between procedural and OO languages, though. More on that later.)

    I disagree with you pretty strongly, wvxvw, but I think that it is almost just a quibble over term definitions. Procedural languages support all of the things that you might see in what people might call procedural ActionScript. They allow variables, procedures, and data structures, and rely mostly on step-by-step code with side effects. It may just so happen that in a specific procedural language implementation, data structures are implemented by objects, procedures by functions, and variables by variables. However, it's not required that programs follow the pattern or paradigm set forth by object-oriented languages. Sure, you may initialize a data structure with new instead of a plain procedure call, but the structure of the program and a person's mental model of what is happening with program data does not need to be influenced by that difference.

    On the other hand, you can have object-oriented languages that aren't procedural. That's why I tried to avoid saying that object-oriented languages are a subset of procedural ones.

    Quote Originally Posted by wvxvw
    Flash IDE gives you a template, which is the timeline, where some necessary stuff (like class declaration) is hidden from you, but that's about it.
    But class declarations weren't always necessary, and they weren't even automatically generated by the compiler for timeline code before AS3. That process (in AS3) is mostly transparent to the end-user programmer.

    Imagine something that would be the reverse of Mascara. Obviously there'd be little practical use of such a thing, but you could at least imagine creating a compiler that translates JavaScript into that weirdly non-standard EcmaScript dialect that Mascara uses. However, if you were a happy user of the JavaScript language that just so happens to be translated into Mascara code and run in some hypothetical interpreter, you hopefully wouldn't say that constructs like generics and strict, compile-time type checking were a feature of JavaScript, even though the compiler translates the JavaScript into such a language. The programmer who wrote the JavaScript may never have even imagined that it would eventually be translated into a language with such concepts.

    It seems that programming language paradigms are defined by the way that programmers perceive and interface with the language, and not as much by how those programs are actually modeled by a compiler or interpreter. It may be that myThing.someOtherThing is a struct access in C, or it could be a property access of an object in ActionScript, but that difference does not necessarily matter to the programmer, who is trying to translate some mental model of an algorithm to an admittedly formal programming language. If that programmer's mental model is a procedural one, then the difference may not matter because that person is simply thinking of accessing a data structure. If the model were to be an object-oriented one, then the difference may matter because myThing could be an instance of a specific class that implies certain things about the meaning of myThing.someOtherThing that a plain data structure would not.

    Languages can make it difficult or (maybe) impossible to think about realizing an algorithm in a certain way, but they (programming languages in general) are very often so-called multi-paradigm languages that allow, but do not force, programmers to think in various ways and apply multiple, different programming paradigms simultaneously. ActionScript is one such language, and I don't think that the procedural and object-oriented programming paradigms are mutually exclusive.

  14. #29
    1,596
    posts
    Holosuite User
    But class declarations weren't always necessary, and they weren't even automatically generated by the compiler for timeline code before AS3. That process (in AS3) is mostly transparent to the end-user programmer.
    #initclip and #endinitclip existed ever since I remember AS1 - this is the "class template" for AS1 if you want it.

    Besides, I didn't say that OO language will always be built of procedural pieces. I said exactly, that it may happen that it will all be built of such pieces.
    There are examples in AS, which aren't procedures on the language level - "new" and "throw" are statements.

    I think that the term "procedural" made much more sense, when there wasn't a concept of compiling the same language into different machine codes, and if anyone chooses to call his coding in AS a procedure, then it's just a confusing choice of word. For me it is like if someone would suggest that a printer machine and a pencil are technically the same thing because in certain situation they have the same function.

    I support FlashDevelop (the .NET open source editor for Flash and web developers)
    couchsurfing if you need it

  15. #30
    So I use OOP when I am creating all of my projects. There is one thing that I have always wondered about, which is better to have all of your code in a single .as file or split each class in its own .as file? What are the positives and negatives of both and which would you guys recommend?

Page 2 of 3 FirstFirst 123 LastLast

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
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012