{"id":1969,"date":"2015-11-12T15:36:35","date_gmt":"2015-11-12T23:36:35","guid":{"rendered":"http:\/\/blackcap.name\/blog\/new\/?p=1969"},"modified":"2015-11-12T15:52:26","modified_gmt":"2015-11-12T23:52:26","slug":"time-for-another-javascript-sucks-post","status":"publish","type":"post","link":"https:\/\/blackcap.name\/blog\/new\/?p=1969","title":{"rendered":"Time for Another &#8220;Javascript Sucks&#8221; Post"},"content":{"rendered":"<p>For no other reason than it&#8217;s been a while since my last one. Oh, I&#8217;ve just been bitten by some sucky Javascript today, but that&#8217;s hardly new: it happens most days.<\/p>\n<p>That&#8217;s because there&#8217;s an <em>awful lot<\/em> of sucky Javascript code out there. Which is the case because Javascript is a difficult language to program well in. Which in turn is the case because both the core language <em>and<\/em> its object model basically suck.<\/p>\n<p>I mean, how much more sucky a design decision can there be than making <em>all variables by default global<\/em> unless explicitly made local? This is precisely the opposite of what any sane design would do. Thanks to this misfeature, all the Javascript coder need to is absentmindedly leave off a <kbd>var<\/kbd> or two and presto, there&#8217;s a bug waiting to strike. And Javascript&#8217;s parallelized and callback-based nature means the bug probably won&#8217;t be immediately obvious, so it will make it through testing and into production where it can bite users.<\/p>\n<p>And then there&#8217;s the Javascript object model. It&#8217;s not necessarily deficient, it&#8217;s just bizarre. Well, bizarre to anyone used to the classical inheritance model (which means virtually any other object-oriented language out there); Javascript uses prototypal inheritance. It&#8217;s a bit of gratuitous difference that just makes Javascript needlessly strange and thus more difficult to learn and understand for the vast majority of programmers. Why? Just why?<\/p>\n<p>That Javascript makes failure easy and success difficult can be illustrated by how it&#8217;s not that hard to run into bad (i.e. flaky and unreliable) Javascript on Google pages. I mean, if one of the largest and wealthiest corporations on the planet, one famous for hiring the best and brightest, one that writes browsers as well as web pages, can&#8217;t successfully implement a <a href=\"http:\/\/www.gwtproject.org\/\">toolkit<\/a> to tame Javascript&#8217;s bias towards failure outcomes, that&#8217;s about as damning an indictment as one can make against Javascript.<\/p>\n<p>Finally, it&#8217;s instructive that those who designed the Google Web Toolkit chose to (alas, ineffectively) fight Javascript&#8217;s brokenness by writing a tool to enable developers to <em>avoid<\/em> programming in Javascript entirely.<\/p>\n<p>Javascript code would be bad enough if most of it only had all of the above factors working against it, but wait, there&#8217;s more.<\/p>\n<p>First, client-side Javascript has to be cross-browser portable, and there&#8217;s lots of gratuitous little differences between the execution environments on different browsers (or even differing versions of the same browser).<\/p>\n<p>Second, many kinds of client-side code, in particular AJAX code, are difficult to write well. Such code must cope well with all sorts of network conditions without adversely impacting human-machine interactivity.<\/p>\n<p>The latter would be difficult to do even with a sanely-designed programming language and execution environment. In Javascript, it&#8217;s often close to impossible.<\/p>\n<p>It&#8217;s one reason why the answer to the question of how best to do something in client-side Javascript is a simple <strong>don&#8217;t.<\/strong><\/p>\n<p>Don&#8217;t do it. Not if you can do it in static HTML somehow. It might in some theoretical sense be better to have more interactivity, but in practice a less theoretically-elegant solution that works and works reliability in a wide variety of situations will come out ahead.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>For no other reason than it&#8217;s been a while since my last one. Oh, I&#8217;ve just been bitten by some sucky Javascript today, but that&#8217;s hardly new: it happens most days. That&#8217;s because there&#8217;s an awful lot of sucky Javascript code out there. Which is the case because Javascript is a difficult language to program [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-1969","post","type-post","status-publish","format-standard","hentry","category-computers"],"_links":{"self":[{"href":"https:\/\/blackcap.name\/blog\/new\/index.php?rest_route=\/wp\/v2\/posts\/1969","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blackcap.name\/blog\/new\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blackcap.name\/blog\/new\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blackcap.name\/blog\/new\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blackcap.name\/blog\/new\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1969"}],"version-history":[{"count":0,"href":"https:\/\/blackcap.name\/blog\/new\/index.php?rest_route=\/wp\/v2\/posts\/1969\/revisions"}],"wp:attachment":[{"href":"https:\/\/blackcap.name\/blog\/new\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1969"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blackcap.name\/blog\/new\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1969"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blackcap.name\/blog\/new\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1969"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}