> Wouldnt the following example help the qx-generator shrink the function? 
> I would guess something like that is not done automatically and I think 
> its not to confusing for the developer as well. It would save some bytes 
> in your build output and at the same time save some lookups. As long as 
> you do not pass the local variables into other functions it neither 
> obscures any dependencies?
> 
> function toggle(element) {
> if (qx.bom.element.Class.has(element, ”selected”)) {
> qx.bom.element.Class.remove(element, “selected”);
> return false;
> } else {
> qx.bom.element.Class.add(element, “selected”);
> return false;
> }
> }
> 
> function toggle(element) {
> var QBES = qx.bom.element.Class;
> if (QBES.has(element, ”selected”)) {
> QBES.remove(element, “selected”);
> return false;
> } else {
> QBES.add(element, “selected”);
> return false;
> }
> }


Yes, it would save some bytes and some lookups. But it wouldn't "help
the qx-generator shrink the function", because there would be nothing
left to do for the generator, on the level of aliasing :). That's why I
said this should be done by the generator (BTW: I have opened an
enhancement bug to this end, bug#3644). Of course, it would also save
the developer a few key strokes, if you're after that ;).

> 
>>   
>>>  - limiting the use of var and return keyword to one for each function
>>>     
>>
>> I doubt that this would speed up JS processing in the interpreters.
>> Condensing all var statements of a function into a single one again
>> saves some transfer size. But I think it would be a requirement too
>> harsh for a developer's coding style. It should, again, be done
>> automatically by the compression tool.
>>   
> Does that mean the qx-generator is actually doing it?

No, it doesn't.

> Or is it just a 
> "should" :)

Nor this. My impression is the gain is not worth the effort.

> Something like changing:
> var a = 0;
> var b = 0;
> var c = 8;
> 
> into: var a = b = 0, c = 8;
> 
> could be easily done.

Yes.

> 
> Things like
> var a = 0;
> if (something) {
> var b=19;
> ... some code ...
> }
> are a bit more tricky to optimize.

Exactly. In this code b is always declared, but only defined after the
'var b=19;' statement. You'd need to leave the value assignment in place
when optimizing, e.g. 'var a=0, b;' not 'var a=0,b=19;'. Otherwise, you
might introduce subtle changes in the program semantics.

> Could make sense to do that 
> optimization by scope.

There is no block scope in JS.

> But I must admin that it might not save 
> Gigabytes... :)

Exactly.

T.


------------------------------------------------------------------------------
_______________________________________________
qooxdoo-devel mailing list
qooxdoo-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

Reply via email to