Tips insane by Microsoft: JScript vs. JavaScript (part 1)

By now we expect from Microsoft pretty much everything, especially when it comes to the browser. Offend the intelligence community, however, is a little 'uncomfortable to accept.
On the Blog IE7 came out today an article ( IE + JScript Performance Recommendations Part 3: JavaScript Code Inefficiencies ), if we may so call Peter Gurevich, Performance PM for IE, with part III of his "advice" for developers.

First point: why Microsoft is so determined to implement its own version of JavaScript - JScript called just that - complicating life at all?

Second point: just because the JScript engine is owned by Microsoft, instead of wasting time to tell "us" how to get around the flaws, why not settle them once and for all?

Leaving aside the first suggestion of this Part III, which you can read directly on the Blog or on Ajaxian , the second is really striking, and I honestly do not diregisco own.

Do not use Property Accessor Functions

When you say progress! In full, 2007, a Project Manager of Microsoft is telling us developers to not use the get and set functions in JScript!
The madness, of course, is a strange evil that affects so sudden and misleading. JScript - in the style of Javascript - is implemented following an object model! It is an object-oriented language, in the wake of the C + +. The fact that the variables are accessible from the outside (as pointed out in the article - obvious by the way) is definitely not a boast, indeed. The encapsulation technique is its philosophy of OO programming. Encapsulate the properties, from virtual-method get and set is a force for Object Oriented language, not a limit. Advise you not to use them is nothing short of criminal, and any performance issues are the responsibility of the interpreter and of its authors, not the end-developer.
So in the end, JScript is used as a simple C, woe to treat it as C + +, otherwise "impallare" the browser or whatever.

Also, as noted on the blog, the whole is a false problem because JScript NOT implements the real functions get and set only Javascript does!

But the problem, obviously, remains. In JavaScript (JScript sorry but I just can not digest it) there are various techniques to create an object. For example you can create on the fly like this:

1
2
3
4
5
{ var myObject = {
, miaProprieta: 0,

( ) { alert ( "Hello" ) ; } mioMethodo: function () {alert ("Hello");}
};

In this way I have not declared a class. The object is so to speak declares and creates at the same time. It is a quick way when the object we need is unique.

Or, which is equivalent for practical purposes:

1
2
3
4
5
6
7
8
CMyObject function () {
= 0 ; this. miaProprieta = 0;

= function ( ) { alert ( "Hello" ) } this. myMethod = function () {alert ("Hello")}

}
/ /
new CmyObject ( ) ; iMyObject CMyObject var = new ();

) e poi si crea esplicitamente l'oggetto con new . In this case, we first define the class - using a function - ( CmyObject ) and then you explicitly create the object with new .

A part of the stylistic issues relating to the single developer, the problem of how to access properties of a class remains. I highly recommend to all interested parties, comumque, to read the answers to the Blog of Microsoft, really interesting.

On the Blog there were three access modes: with the Get and set functions, direct and moving from prototype. At the end of the nice thing was that on the blog there is a code to perform a testdrive, a test of the three methods mentioned above. The code is present on the blog but I report it here for completeness:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<Script>
/ / Slow Car definition
SlowCar function ()
{
= 17 ; this. m_tireSize = 17;
= 250 ; // One can always dream! this. m_maxSpeed ​​= 250, / / One can always dream!
= SlowCar_get_tireSize ; this. GetTireSize = SlowCar_get_tireSize;
= SlowCar_put_tireSize ; this. SetTireSize = SlowCar_put_tireSize;
}
SlowCar_get_tireSize function ()
{
; return this. m_tireSize;
}
value ) SlowCar_put_tireSize function (value)
{
= value ; this. m_tireSize = value;
}
</ Script>


<Script>
/ / Faster Car, no more property accessors
FasterCar function ()
{
= 17 ; this. m_tireSize = 17;
= 250 ; // One can always dream! this. m_maxSpeed ​​= 250, / / One can always dream!
}
</ Script>


<Script>
/ / Prototype Car, use the language features!
PrototypeCar function ()
{
= 17 ; this. m_tireSize = 17;
= 250 ; // One can always dream! this. m_maxSpeed ​​= 250, / / One can always dream!
}

= function ( ) { return this . m_tireSize ; } ; PrototypeCar. Prototype. GetTireSize = function () {return this. M_tireSize;}
= function ( value ) { this . m_tireSize = value ; } ; PrototypeCar. Prototype. SetTireSize = function (value) {this. M_tireSize = value;};
</ Script>


<Script>
TestDrive function ()
{
new SlowCar ( ) ; // Safe and reliable, probably not fast slowCar SlowCar var = new () / / Safe and reliable, probably not fast
new FasterCar ( ) ; // Lacks air-bags, probably faster fasterCar FasterCar var = new () / / Lacks air-bags, probably faster
new PrototypeCar ( ) ; // Can technology win the day? protoCar PrototypeCar var = new () / / Can technology win the day?


( new Date ( ) ) . getTime ( ) ; var start = (new Date ()). getTime ();
var i = 0 ; i < 100000 ; i ++ ) { slowCar. SetTireSize ( slowCar. GetTireSize ( ) + 1 ) ; } for (var i = 0; i <100000; i + +) {slowCar. SetTireSize (slowCar. GetTireSize () + 1);}
( new Date ( ) ) . getTime ( ) ; var end = (new Date ()). getTime ();
"Slow Car " + ( end - start ) + "<br>" ; output. innerHTML + = "Slow Car" + (end - start) + "<br>";


new Date ( ) ) . getTime ( ) ; start = (new Date ()). getTime ();
var i = 0 ; i < 100000 ; i ++ ) { fasterCar. m_tireSize += 1 ; } for (var i = 0; i <100000; i + +) {fasterCar. m_tireSize + = 1;}
new Date ( ) ) . getTime ( ) ; end = (new Date ()). getTime ();
"Faster Car " + ( end - start ) + "<br>" ; output. innerHTML + = "Faster Car" + (end - start) + "<br>";


new Date ( ) ) . getTime ( ) ; start = (new Date ()). getTime ();
var i = 0 ; i < 100000 ; i ++ ) { protoCar. SetTireSize ( protoCar. GetTireSize ( ) + 1 ) ; } for (var i = 0; i <100000; i + +) {protoCar. SetTireSize (protoCar. GetTireSize () + 1);}
new Date ( ) ) . getTime ( ) ; end = (new Date ()). getTime ();
"Prototype Car " + ( end - start ) + "<br>" ; output. innerHTML + = "Prototype Car" + (end - start) + "<br>";
}
</ Script>

"TestDrive();" > Test Drive Cars !</ button > <Button onclick = "TestDrive ();"> Test Drive Cars! </ Button>
"output" ></ div > <Div id = "output"> </ div>

Now, this is the output (relative to my machine) with IE7:
Slow Car 515
Faster Car 63
Prototype Car 547

With FireFox (v.2.0.0.1):
Slow Car 156
Faster Car 47
Prototype Car 172

With Opera (v.9.10):
Slow Car 172
Faster Car 47
Prototype Car 172

In short :) IE7 comes out really bad ... I do not know if you notice the huge difference. So I would say JScript could be abolished, deleted, erased, vaporized. We hope that Microsoft decides to adopt her too Javscript and not surrogates.

There are no comments for this post

Leave a comment

TAG XHTML PERMITS: CODE ENTRY:
 <pre></pre> // blocco generico <code></code> // blocco generico [cc_actionscript][/cc_actionscript] // Actionscript [cc_actionscript3][/cc_actionscript3] // Actionscript 3 [cc_css][/cc_css] // CSS Style Sheet [cc_html][/cc_html] // HTML [cc_js][/cc_js] // Javascript [cc_objc][/cc_objc] // Objective-C [cc_php][/cc_objc] // PHP [cc_sql][/cc_sql] // SQL