ryanm wrote:

I cannot decompile to test my sayings, but 'this' adds more bytecode to the file ??

No, if you leave it off, it is added at compile time. Like I said, you can't call methods that aren't members of an object; all functions must be members of some object. AS1/2 allows you to *pretend* like you're calling a method that doesn't belong to an object, but only by assuming that it is a member of the current timeline (which is an object). Similarly, a method call in a class without an object specified will assume that it is of the current scope (this), and add that object reference during compilation (or, technically, just before). The bytecode is exactly the same, except in the (admittedly rare) case where there is a name conflict with a method in a superceding scope, in which case the object reference inserted by the precompiler will point to a different (and probably wrong) object.

ryanm
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Two things:

1. Personally, in the end, i think the concept of "readability" is a matter of taste. Omitting "this" because it "clutters the code" is a strange notion to me, because to a lot of people it actually humanizes the code somewhat. If you're going to ask me about code clutter, i'd point you to classes such as Robert Penner's tween functions, which have about as nondescriptive variable names as i can imagine and do little to educate you. They supply the functionality, and that is that: Cue reference to how the quintessential software developer often denies himself the role of the teacher by force of habit. I'm the guy that types long variable names so i can pass the class on to the next man without figuring 15 minutes of tutoring into the idea, and this happens when you're the one scripter guy in an office full of designers. To pertain to self-imposed rules of truncated code because you have some idea as to what reads better TO YOU and what other people SHOULD strive for is arrogance, not craftsmanship. To me, clutter is obfuscated script that makes no sense on first glance, and that takes you several reads through to catch the functionality and scope. A few "this"es here and there in addition to commentary is not a matter of bad form insofar as it helps the next man make sense of your work. You may be engineers on the lowest level, but to a certain extent you are also educators and authors, which is an element to programming too many ignore. What good does your script do if all it becomes is an interchangable cog in the system which only you can make sense enough of to alter or customize?

Of course this has less to do with spamming "this" and more with general programming form, but i think "this" as a descriptor is a good symbolic measure of how too much is sometimes just enough.

2. What the hell is going on with "this" here

class ParseXML{
   private var xmlDoc:XML;
   private function handleXML(){
       trace(this);
   }
   function ParseXML(url:String){
       xmlDoc = new XML();
       xmlDoc.ignoreWhite = true;
       xmlDoc.onLoad = handleXML;
       xmlDoc.load(url);
   }
}

"trace this" in this case traces out the xml doc. Is this because onLoad = handleXML declares the scope of handleXML as being the xmlDoc? Sometimes the onLoad = functionReference; syntax weirds me out. I tend to go for the onLoad = function(){ more specific functionality here } method

- Andreas
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to