Stuck on Processing.js private and public variables

It’s been awhile since I posted, but I needed to create some time, which meant moving things around.

Warning, this may seem more like a rant, or crazy ramblings than a normal blog post. I’m just going to write it all down, in hopes that it helps me better understand all that I’m dealing with.

Alright, to start off I’m working on processing,js, specifically ticket #133 (still). It didn’t seem hard at first, and I had a lot of initial success, but as I went deeper, I kept finding more and more. This has really taken a lot to get right.

What I’m trying to accomplish, is to grab a class, so I can work with, and parse just the class, as to not parse non class related code. Once I’m in the class, I want to grab and remove the class functions, and constructors for later use, I don’t want to be parsing “var i” that is contained in a function, into a private variable. Outside the function, anything that’s private, is private, and public is public, but by default, it should be public. This is why I cannot be parsing functions and constructors, but I also have to know what’s public, and what’s private by the time I work with the functions and constructors, because when a public variable is used in a function or constructor, I need to add a “this.” in front of it.

I think some day, hopefully soon, all this class parsing code should have a major overhaul, as I keep coming to code that I don’t see any use for, but I’m not comfortable removing it yet. I’m starting to fix things, and as I do, other areas should be removed. I think that would be better suited for a separate bug once I got private and public working.

I did take an attempt at overhauling the class parsing, but I’m conflicted if I should just redo it, and go from there, or if I should use what’s already there. I believe most would say not to redo it, but it’s still tempting.

Right now, I’m dealing with some code that’s being “left behind” as I move parts of the class up, and other parts down. I know that classes with a constructor is parsed separately than a class without a constructor, but I don’t think we should be doing this. What we should do is, open the class up, from top brace to bottom brace, and deal with any constructors contained within, as we get to them. This also has the advantage of not needing constructors to be declared first thing, and any member variables can also be declared anywhere. I’ve made a work around for this, but now I think it’s causing my “code left behind” problem, as the code left behind is either the class declaration, or a constructor declaration. For example, imagine a class called Place, when I parse it, I’m left with a line of code like this “processing.Place = function” I think it’s a case of a regex somewhere just working with what’s between the {} and not what’s also in front of it.

Another issue that was solved about a day ago, is private and public functions, being declared with a custom “addMethod()” function, which for the longest time made no sense to me, and I hated it. I have since understood it, and although I still don’t like it much, I see the need and don’t want to remove it. This function wants an object, a String, and a function as it’s parameters, and it will then create a function, with that name, and add it to the object you send, also allowing for overloading (the reason why it’s there, is for overloading) I was stuck figuring out how to add a function to this. without making it public. I would send “this” as the object, into addMethod, I thought about intercepting it, and making private functions separately, but then we would be left with separate code for public functions, and private functions, not very ideal. I decided on adding a private object called private to the scope of the class, then when I want to add a function to the private scope, instead of sending “this” I would send my “private” object. The caveat with this is I now have to parse the functions and constructors in the class for any use of a private function, and add “private.” in front of it, much like how I add “this.” to public variables.

The other option would be to add a “with(this){with(private){ .. }}” around all the code. This would check all variable and function calls if it’s inside private (which I would create as “var private = {}”), if not, it would then check if it exists inside this, the problem is, if it doesn’t exist inside private, or this, it would be created as a global variable, I think, possibly overwritting any global instances of that variable already defined. Processing.js already uses “with(this) { .. }”, and I’m trying to remove it, with moderate success, but it’s extremely helpful in this case, and is the difference between 2 lines of code, vs 50 lines of code (I may be exaggerating, as I have not counted which lines are new, and which are being left, or modified, but it’s a lot). I plan on talking to David Humphrey in person about possibly, continuing the use of “with()” even with the dangers involved.

I have to admit, this has been quite challenging, and I’m getting kinda frustrated with it, but I guess that’s a good thing? *shrugs*


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: