Re: Express Generator - News and Updates
> What's the essence behind "programming style"?
Converting from EcmaScript 6 style to EcmaScript 5 style. Then collecting all variable declarations at the top of a function.
For example, replacing 'let' and 'const' with 'var' (deprecated) and collecting at the top of the function:
// Modern
function foo() {
for (let i = 0; i < 10; i++) {
const b = i * i;
...
}
}
// Deprecated style
function foo() {
var i, b;
for (i = 0; i < 10; i++) {
b = i * i;
...
}
}
Probably the benefit comes from the JavaScript engine having to create(allocate) a new variable "const b" for every loop.
It only sets a new value to "b" in the second case.
Replacing 'for of' with 'for i'
// Modern
for (const elem of array) {
elm ...
}
// Deprecated style
var i, elem;
for (i = 0; i < array.length; i++) {
elm = array[i];
elm ... ;
}
I do all this automatically.
- compile the project source code with TypeScritp compiler to "target" = "ES5".
- re-arranging the code and shortening the variable names with 'uglifyjs --compress --mangle"
The above commands also convert the modern "class" constructs to the "prototype" style.
I changed EA Studio to ES6 two years ago. However, Express Generator has a very different (more conservative) algorithm. For that reason, I decided to test to convert it to ES5.
I made the same test with EA Studio. It shows a 3%-5% performance benefit.
I'm reluctant to publish such deprecated code in the browser for EA Studio, but I'll decide in the following days.
If you want more info, watch the old "Douglas Crockford" videos: https://www.youtube.com/watch?v=JxAXlJE … YUILibrary. They are very funny for geeks.
I watched all of them years ago, and he inspired me to start making backtesting engines for the browser ))
Trade Safe!