{"author_name":"Zelen3d","cat":"LD #24","comments":[{"author_name":"Puzzlem00n","time":"August 6, 2012 8:44 pm","epoch":1344303840,"text":"Haha. &#8220;Inability to summarize.&#8221; I&#8217;m in the same boat as you there. Try to keep things short, never can.","spam":"N"}],"epoch":1344295680,"likes":2,"metadata":{"p_key":"55492","p_author":"Zelen3d","p_authorkey":"13310","p_urlkey":"91210","p_title":"Faith in JavaScript has been restored","p_cat":"LD #24","p_event":"LD24","p_time":"1344295680","p_likes":"2","p_comments":"1","p_status":"UPD5","us_key":"13310","us_name":"Zelen3d","us_username":"zelen3d","event_start":"1345766400","event_key":"12","event_name":"LD24"},"text":"<div>\n <p><a href=\"http:\/\/www.ludumdare.com\/compo\/2012\/08\/06\/faith-in-javascript\/faith-in-humanity\/\" rel=\"attachment wp-att-149509\"><img class=\"wp-image-149509 alignleft\" src=\"http:\/\/www.ludumdare.com\/compo\/wp-content\/uploads\/2012\/08\/faith-in-humanity-240x300.png\" alt=\"\" width=\"240\" height=\"300\" \/><\/a>This post, other than being an <em>I am IN<\/em> post, actually describes my journey around JavaScript: why I left it and how I finally came back to it. If JavaScript concerns you, you would find here a few things that I hope I knew half a year ago. Also please excuse my inability to summarize.<\/p>\n <p>When I first started learning Javascript and Html5, I was trying to find an alternative to flash to make online games. At first, I have been pleased of how simple it was. You didn\u2019t need a complex IDE, you didn\u2019t need any compilers and libraries to get graphics. All you needed was an average text-editor (in my case gedit) and a browser (I chose Chrome for its developer\u2019s tools). In fact, I have made a few <a title=\"My first tile based game!\" href=\"http:\/\/rnd.atspace.tv\/tileGame.html\" target=\"_blank\">unfinished<\/a> but <a title=\"Cloud Hopping!\" href=\"http:\/\/rnd.atspace.tv\/clouds.html\" target=\"_blank\">kind of playable<\/a> \u201cgames\u201d, <a title=\"Click to press Spin Turret\" href=\"http:\/\/rnd.atspace.tv\/spinturret\/game.html\" target=\"_blank\">one of them<\/a> for the 34th miniLD.<\/p>\n <p>As I became better and better at the language (learning how <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/JavaScript\/Guide\/Closures\">closures<\/a> work and stuff), I started seeing more and more of these \u201cissues\u201d in the language, as well as in the &lt;canvas&gt; object, some of them couldn\u2019t be worked around. (There are quite a few of them and I chose to spare them for you as the paragraph was becoming big enough. If you&#8217;re curious ask in the comments.) Then, here is the issue that made me loose faith in JavaScript: the nature of JavaScript arrays. You see, in JavaScript arrays are just objects that have a special <em>length<\/em> property. And when you do <em>myArray[5]<\/em> it is exactly the same as <em>myArray[&#8220;5&#8221;]<\/em> since it is supposed to internally do<em> myArray[(5).toString]<\/em> . So JavaScript arrays aren\u2019t real arrays (C-like arrays), and aren&#8217;t even number-associative arrays , but are string-associative arrays. And to crown it all, these not real arrays can\u2019t even be directly inherited.<\/p>\n <p>At this point I decided that maybe I should leave web scripting for a &#8220;real&#8221; language. For a few months I drifted from C++ to D, to Java and Processing and back to C++. If I would have settled down for a language, I would have probably became good at it, but it is such a difficult choice to make and there is always some feature that a language has and others don\u2019t.<\/p>\n <p>And then, recently, I have <a href=\"http:\/\/stackoverflow.com\/questions\/614126\/why-is-array-push-sometimes-faster-than-arrayn-value\/614255#614255\">found out<\/a> that most JavaScript implementations actually treat arrays as real arrays until there is a need to really treat them differently. I was amused knowing how browser providers silently try to close the performance gaps left out by the standardization in which they have themselves took part. On a side note, I heard Mozilla is adding <a href=\"http:\/\/blog.mozilla.org\/futurereleases\/2011\/11\/10\/type-inference-to-firefox-beta\/\">type inference<\/a> in their next JavaScript implementation to speed it up. Cruel irony.<\/p>\n <p>Things started to get really bright for me when I discovered that JavaScript has a pretty new feature called <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/JavaScript_typed_arrays\">Typed Arrays<\/a>. Typed arrays permit to manipulate raw binary data by creating an array of bits and then accessing them as 8bit, 16bit, 32bit; signed, unsigned; ints or floats. I have then thought that it would be really good to use this kind of array to boost performance in a tile-based game where each tile corresponds to a number. So today&#8217;s JavaScript maybe isn&#8217;t so bad.<\/p>\n <p>And the future of JavaScript is even brighter, and must be, talking about the amount of people that use it. The JavaScript 2.0 draft that would make JavaScript strongly-typed but dynamic if the developer chooses, submitted by Netscape in 2006, sounded very exciting. Sadly, ECMA didn&#8217;t make it into ECMAscript 4, and to not confuse people they directly jumped to making ECMAscript 5, the language that we use today, with just a few small changes. Most of the features of the proposed JavaScript 2.0 were yet incorporated into ActionScript making flash developers pretty glad. But the ECMAscript team continued working on the proposal and they actually came up with an agreement: <a href=\"http:\/\/wiki.ecmascript.org\/doku.php?id=harmony:harmony\">EcmaScript-Harmony<\/a> wich will become the EcmaScript 6 (a quick list of it&#8217;s features that you can google may be found <a title=\"ES6 features\" href=\"http:\/\/espadrine.github.com\/New-In-A-Spec\/es6\/\">here<\/a>). This will add classes, but just to simplify the prototyping based inheritance. Then they say that maybe, just maybe, they would make javascript strongly typed in a further release but not just yet. Anyways, the future looks good, but isn&#8217;t here yet.<\/p>\n <p>So to conclude, I would probably use HTML5 and JavaScript in the 24th Ludum Dare, unless I find some epic language\/game engine at the last minute (if I for example start playing around with Flex). And in the mean time, I would be creating a library to simplify the use of typed arrays for 2d tile based games. I will make a system that automatically transforms a two-dimensional JavaScript array into an object that keeps the data as a typed array internally and gives you methods for easily accessing the tiles.(\u00a0 <em>var map= new binaryArray([[1,1,1],[1,0,23],[1,1,1]]);\u00a0\u00a0 map.setTile(1,2,25);\u00a0<\/em>\u00a0 \/\/set tile at (1,2) to 25\u00a0 ). I hope that this would boost performance. I would keep track of my efforts on this blog and anyone of you would be able to use the library once it&#8217;s done.<\/p>\n <p>And to pursue the tradition:<\/p>\n <ul>\n <li>Platform:HTML5<\/li>\n <li>Language:JavaScript<\/li>\n <li><strong>Graphics<\/strong>:Gimp,Blender 3d, InkScape<\/li>\n <li><strong>Audio and Music<\/strong>: Audacity, LMMS, Bfxr<\/li>\n <\/ul>\n <p>Good luck to all of you and have a good time.<\/p>\n <p>I would also be searching for some screen recording program.<\/p>\n <\/div>","time":"August 6th, 2012 6:28 pm","title":"Faith in JavaScript has been restored"}