
JavaScript Grievances common complaints about JavaScript Seinfeld Festivus Airing of Grievances http://www.youtube.com/watch?v=xoirV6BbjOg Copyright © 2012-2013 by Object Computing, Inc. (OCI). All rights reserved. Assessment Key E - Addressed by EcmaScript 6 (ES6) D - Doesn’t really happen in practice L - Caught by Linting tools (JSLint/JSHint) and/or ES5 strict mode P - Personal preference R - Real problem Y - You can easily learn how to deal with this Copyright © 2012-2014 by Object Computing, Inc. (OCI). 2 JS Grievances All rights reserved. 10 - Crockford’s Bad Parts ... Implied globals (E, L) assign to a variable without a var and it becomes global can’t do in strict mode in ES6, use let instead of var Scope (E, Y) variables are scoped to a function body or they are global no block scope in things like if statements and loops (see let in ES6) CoffeeScript and Node.js provide file/module-scoped variables Semicolon insertion (D, L) semicolons are optional when omitted, they are automatically inserted, sometimes not where intended hard to get wrong though Copyright © 2012-2014 by Object Computing, Inc. (OCI). 3 JS Grievances All rights reserved. 10 - ... Crockford’s Bad Parts ... Reserved words (L) many aren’t currently used, but reserved for possible future use don’t have to memorize them; let a lint tool warn you Unicode (E, D) uses UTF-16 characters, not UTF-8, and string methods expect only 2-byte characters, not 4 characters in all modern languages only require 2 bytes typeof (Y) typeof null === 'object' and typeof [1, 2, 3] === 'object' Numbers (E, D) all are represented by a double; no integer type, but can accurately represent up to 53 bits which is large enough for almost all uses Copyright © 2012-2014 by Object Computing, Inc. (OCI). 4 JS Grievances All rights reserved. 10 - ... Crockford’s Bad Parts Arrays (E, D) represents arrays as objects where keys are string versions of indexes a potential performance issue; but not typically ES6 adds typed arrays of numbers Falsy values (Y) false, undefined, null, 0, NaN and "" are all treated as false in boolean contexts everything else is truthy == vs. === and != vs. !== (L) short forms perform type coercion, long forms do not eval(code) (D, L) need to be careful about source of code Copyright © 2012-2014 by Object Computing, Inc. (OCI). 5 JS Grievances All rights reserved. 10 - More Complaints ... Implicit type coercions (D, L) Google “Gary Bernhardt WAT” Verbose function keyword (E, R) can use arrow functions in ES6 Object keys must be strings (E, R) can use Map and Set collections in ES6 No fancy collections (D, E, R) like sets and maps, only Array and Object can use Map and Set collections in ES6 Copyright © 2012-2014 by Object Computing, Inc. (OCI). 6 JS Grievances All rights reserved. 10 - ... More Complaints ... Prototypal inheritance (E, R, Y) many steps to get right call superclass ctor in subclass ctor set subclass .prototype to an instance of superclass set subclass .prototype.constructor to subclass ctor can use class and extends keywords in ES6 Ability to add/override functions and methods (D) far away from other related definitions a.k.a. monkey patching Dynamically typed (P) some prefer static typing can use TypeScript Copyright © 2012-2014 by Object Computing, Inc. (OCI). 7 JS Grievances All rights reserved. 10 - ... More Complaints No require/import/include capability (E, R) each client-side JavaScript file must be referenced from a script tag in HTML or use something like RequireJS Node provides CommonJS-style require ES6 provides modules Need to learn async programming style (Y) callback functions and avoiding deeply nested calls Supports mutable things (P) can use ClojureScript Don’t like braces, parens and semicolons (P) can use CoffeeScript Copyright © 2012-2014 by Object Computing, Inc. (OCI). 8 JS Grievances All rights reserved. 10 - Good Parts ... First-class functions store in variables, pass to other functions, return from other functions a necessary feature for functional programming Closures functions capture data in the scope where they are defined Anonymous functions Functions are objects can attach properties with any kind of value, even other functions Copyright © 2012-2014 by Object Computing, Inc. (OCI). 9 JS Grievances All rights reserved. 10 - ... Good Parts ... Objects are like maps can add arbitrary properties whose values are data and functions JSON serialization JSON.stringify(value) and JSON.parse(string) JavaScript experience carries over to server-side programming using Node.js Can use CoffeeScript, ClojureScript and other languages that compile to JavaScript instead Copyright © 2012-2014 by Object Computing, Inc. (OCI). 10 JS Grievances All rights reserved. 10 - ... Good Parts JavaScript IS THE ONLY PROGRAMMING LANGUAGE SUPPORTED BY ALL POPULAR WEB BROWSERS! Copyright © 2012-2014 by Object Computing, Inc. (OCI). 11 JS Grievances All rights reserved. 10 - Stop the Hate! Typically Twitter comments OH: JavaScript sucks ... ha, ha, ha! TIL: JavaScript is lame. Truth You can implement nearly any application successfully in nearly any programming language. Everyone has personal preferences. There will never be a programming language that is everyone’s favorite. Hate fragments the community and reduces opportunities for learning from each other. Copyright © 2012-2014 by Object Computing, Inc. (OCI). 12 JS Grievances All rights reserved. 10 -.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages12 Page
-
File Size-