Wednesday, February 27, 2008

download the file in your es4 folder, where there is the run.exe and the es4.bat file

double click

Basically, there is a place to write something, where for some reason TABS are usable only with CTRL + TAB instead of single TAB key, a panel where errors or output will be showed, and finally, 5 buttons:

Run, to execute the code

Clear, to clear the code in the area

Add Before, to add area code before execution

Get Before, to add in area the code added before

Clear Before, to clear content added before

Here some example:

var i:int = 123;print(i);

Press Run, and You'll read 123 on output panel.Now press clear, and area will be without text.Write again ...

var i:int = 123;

Without the print, now press Add Before, area will be clean again ... BUT, write this:

print(i);

and press Run, you'll read 123 in the output panel.This mean that precedent code is in ram, and is present on output but not in the area.Of course, if you Add Before print(i); , this will be executed after var i:int = 123;

This is useful to add classes or other scripts, just tested.Now, if you press Get Before, the entire content will be added to the area, after current one, if any.

Finally, with Clear Before, everything in the Ram will be cleaned.

Simple? Last thing: every time you press Run, code is compiled in a new enviroment.

That's it, and sorry for this horrible debugger ... but time is never enough :)

Basically, the reason that make prototype better than constructor with privileged methods, as get one is, is that core doesn't need to parse and/or create functions for each instance.Another reason to prefer them is that you can add, remove, or change, a single function affecting every instance.A good behaviour specially with a browser based language, as JavaScript is, that allow developers to write dedicated browser methods once, instead of check and change behaviour each time and for each instance.

The bridge strategy

One way to solve scope problems betwen external prototype based methods and private constructor functions, is to use a bridge.

Basically, the bridge method is a privileged wrapper, but it is inside the correct scope and that's why it can call function privateMethod without errors.Seems cool? But it isn't so cool .. and that's why:

the bridge method is public, everyone could override them in every other place and for every instance

last but not least, we are using eval ... and this means, for 99% of times, that we are using a bad code design

Public methods overload strategy

A different way to solve this problem is to inject your private methods inside the instance each time you call a public one.You can do it once, and forget private scope methods for ever, using them in a natural way inside every other one.To do it, you need to change at least one time each public method, overloading them during constructor assignment.This is a final result example:

var demo = new MyClass(3);alert(demo._checkNumAndSum); // undefinedalert(demo.sum(2)); // alert true and after them returned value is 5alert(demo._checkNumAndSum); // undefined

This list rappresents Create function goals:

prototype based, it overloads directly the prototype object and it does not create protected functions each time

natural code, you do not need to change your code as is for bridge, during protected method execution

This one rappresents Create function limits:

you cannot share a prototype object, even if this phrase doesn't make sense for most of you

public methods execution time will be a bit slower, where that "bit" is not a real problem but for performances maniacs it will

injected methods are protected and not private, these are visible during method execution itself

To better understand last point, look at this example:

function visibleMethod(instance){ alert(instance._checkNumAndSum);};

// ... same code of precedent example with this change

// one or more prototypes sum:function(num){ visibleMethod(this); return this._checkNumAndSum(num); }

Since I guess that above situation is not so common, I think that's a good thing to let you know that protected methods are visible during each protected or public method execution.Pure OOP has a different meaning for protected methods, it is based on possibility to use those methods from a subclass.In my case, I choosed protected word because private one, usually not accessible from subclasses, is a word that loose its concept in the instant you can access that method outside the object.I know probably my choice wasn't so serious, but for a prototype based inheritance I think it makes sense :)

Wednesday, February 20, 2008

... or, to be honest, that's what it's gonna do in few days, but PHP version is out!

You can find every information about server side version of packed it directly in this page.

I am not joking when I said that packed.it is probably the fastest optimized client files server you can find over the net, even with an uncompiled program language like PHP.

The key is the JOT compiler, compile one time, serve all the time without paranoia, saving bandwidth for both server and client, avoiding the usage of gz handlers, avoiding runtime compression, avoiding whathever you want, and finally, having the possibility to serve js, css, or both with a single file.

Discover by yourself how long server need to serve, for example, jQuery ... less than one millisecond without louds of requests ... please look at X-Served-In header, if you do not trust me :P

What's new? You do not need to pass in packed.it site to compile your projects, you can just serve and compile them directly from your one.

To Do:Python PSP and SWGI version, C# version and finally, Jaxter version for server side JavaScript auto compilation in itself language ... does it sound good?

updateHonestly, I need right arguments and my first implementation put partial arguments before the others and not at the end.

With this update you can use, by default, argments at the end of the function, but if you want to use them before, just call rinvoke or rinvokeArgs (r means put recieved arguments, during invoke or invokeArgs, on the right, at the end)

Wednesday, February 13, 2008

Don't You trust me? It's so diabolically simple with packed.it ... and more than a professional Web Developer complained about "why on heart noone talk about that service" :D

It's not packer, it's not YUICompressor, It's the only one that cache both CSS and JavaScript in a single file ... it's for PHP4, PHP5, Python wsgi, Python psp, C#.NET ... so, what are you waiting for?

One thing to take care about is the usage of a function instead of a variable.Since some script could run other scripts dinamically, you can't trust in a single time check.

The second trick is really useful for function that accept a switcher argument.For switcher argument I mean methods or function that accept true or false as argument.The simplest way to have a switcher is obviously sending the value, but in this case we can't have a default behaviour.