{"id":63,"date":"2008-04-29T20:33:03","date_gmt":"2008-04-29T22:33:03","guid":{"rendered":"http:\/\/www.ragestorm.net\/blogs\/?p=63"},"modified":"2010-06-29T19:07:42","modified_gmt":"2010-06-29T21:07:42","slug":"javascript-sucks","status":"publish","type":"post","link":"https:\/\/www.ragestorm.net\/blogs\/?p=63","title":{"rendered":"JavaScript Sucks"},"content":{"rendered":"<p>I really know many languages pretty well, but this language is really ugly or stupid or what not. So many features are only &#8220;hacks&#8221;, browsers do whatever they want with the code differently from each other and there&#8217;s chaos about JS everywhere you go.<\/p>\n<p>For example, what we call a &#8216;dictionary&#8217;, which is an associate array is a big hack in the language. It is practically an object which you can set properties, and then iterate over them. There&#8217;s no formal way to remove a key from the dictionary, like you would expect in a scripting language; by doing myDict.remove(&#8220;key&#8221;). You will have to do delete myDict.key. Not mentioning how to know if you have any keys in the dictionary, because who said you have the length property? Well, if you think you have it, then you&#8217;re wrong, that&#8217;s because you used an array as a dictionary instead of creating an object using\u00a0{ }.<\/p>\n<p>Another thing I encountered was that if you have a dictionary with the last defined element ends with a comma, then the browser (IE) will shout at you while other browsers eat it well. It reminds me the macro&#8217;s in C\/C++ that you don&#8217;t know where&#8217;s the originating code which caused the problem, since it gets compiled <em>after<\/em> it&#8217;s substituted&#8230; So {a:1,} will kick.<\/p>\n<p>Another ugly thing is this fake OOP, now who are you kidding? Adding a special use for the &#8220;this&#8221; keyword, but otherwise everything else is just nested function, err sorry, methods. This is another ugly hack, and some people even use inheritance. Do me a favor. The errorprone &#8220;class&#8221; that you declare will probably have memory leaks, because the methods were really defined as nested rather than using something like MyClassName.prototype.myMethodName, which will certainly work better and not get allocated per instance. Did you say private member? Oh yeah, right. That&#8217;s what you think and this time you&#8217;re right. Because they are local variables to the &#8220;class&#8221; which is really a function that gets run when you create an instance. However, you don&#8217;t have control over public\/readonly, etc, which is pretty much useful. So constructor is free of charge because it&#8217;s the code in the &#8220;class&#8221; function, where you also define the private variables. And I won&#8217;t call them private members. Now you say, &#8220;of course, there&#8217;s no need for a destructor, a scripting language has a GC&#8221;. Well, that&#8217;s right, but when an element points to code, using onClick for example, and that handler has a variable that points to that same element, then you&#8217;re in a circular trouble ;) So this time you might want to have a destructor right? Or having some function that will be called on unload so you can null() a few variables to break the circular references&#8230;But yes, this problem might happen in many environments, but Java for the sake of conversation solve this one unlike Python, AFAIK.<\/p>\n<p>Now why the heck browsers need to compile (yes, in a way) code??? We just all grew up into believing that&#8217;s something normal, but stop and give it a thought. I guess those guys didn&#8217;t hear about standards.<\/p>\n<p>You can even open a new nested block using curly braces, but all the variables you declare there are become globals. So you end up deleting some objects you have to manually. Now don&#8217;t start with why you wanna delete a variable, there are good reasons for that sometime and that&#8217;s another story.<\/p>\n<p>Did you know about javascript compiler time machine? Ahh of course not, let me show you:<\/p>\n<p>var a = &#8220;DEFINED&#8221;;<\/p>\n<p>function f() {<br \/>\n\u00a0alert(a);<br \/>\n\u00a0var a = 5;<br \/>\n}<\/p>\n<p>Will this code snippet open an alert with a text of &#8220;DEFINED&#8221;? No, now keep on reading.<\/p>\n<p>If you run that code snippet above you will get an exception with &#8220;a is undefined&#8221;, now the compiler or whatever freak under there sees the a, which is really defined in the global scope, right? Yes, it is, seriously. But then it sees later on that the &#8216;a&#8217; variable is being defined in the scope of the function &#8216;f&#8217; and decided to make the first one undefined. Make an experiment and remove the &#8216;var&#8217; from the definition of the &#8216;var a = 5;&#8217; and see for yourself the results.<\/p>\n<p>And there are more and more quirks in this language that I will leave for another time. So what do you think, is Silverlight the best next thing?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I really know many languages pretty well, but this language is really ugly or stupid or what not. So many features are only &#8220;hacks&#8221;, browsers do whatever they want with the code differently from each other and there&#8217;s chaos about JS everywhere you go. For example, what we call a &#8216;dictionary&#8217;, which is an associate [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","jetpack_publicize_message":""},"categories":[1],"tags":[],"jetpack_featured_media_url":"","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pbWKd-11","_links":{"self":[{"href":"https:\/\/www.ragestorm.net\/blogs\/index.php?rest_route=\/wp\/v2\/posts\/63"}],"collection":[{"href":"https:\/\/www.ragestorm.net\/blogs\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ragestorm.net\/blogs\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ragestorm.net\/blogs\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ragestorm.net\/blogs\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=63"}],"version-history":[{"count":2,"href":"https:\/\/www.ragestorm.net\/blogs\/index.php?rest_route=\/wp\/v2\/posts\/63\/revisions"}],"predecessor-version":[{"id":384,"href":"https:\/\/www.ragestorm.net\/blogs\/index.php?rest_route=\/wp\/v2\/posts\/63\/revisions\/384"}],"wp:attachment":[{"href":"https:\/\/www.ragestorm.net\/blogs\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=63"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ragestorm.net\/blogs\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=63"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ragestorm.net\/blogs\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=63"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}