The Wun Show: Douglas Crockford has been sniffing JavaScript

Stob In the first chapter of his last book How JavaScript works (pub. Virgule-Solidus, 2018, c. £ 24.19, pp 279), Douglas Crockford presents a selection of Idiosyncrasy English linguistics that will inflict on your readers.

The most surprising of these is his spelling of "one," yes, yes, that eye of Kelly, that inefficient multiplier, that name that Prince Charles calls himself, that he, Crockford, insists on rendering " wun ". And again. With all the adorable variations released for free: somewun anywun no wun I wunce wrote a builder, wunth and, get ready for it, two .

This is quite annoying and distracting, but no more than an economy-class transatlantic flight in a narrow seat in the middle aisle in front of a poorly disciplined ADD child whose kicks in the seat back are distributed by Poisson with Lambda around 4.7 per minute

I am sure I have seen that spelling "wun" before, in the writings of Daisy Ashford, Alan Alexander Milne, or some other child author. We have greeted "goodbye" to the wild world web. We have landed at Wun Hundred Acre Wood.

Good parts

Given this promising start, non-JavaScript-oriented readers Reg might reasonably ask why we are here at all.

The reason is historical. At the turn of the millennium, the High Programming Command treated JavaScript as a toy language, suitable only to manipulate the event of passing the mouse through horrible web pages and to sponsor responses: "No, no, you are confusing it with Java .It has nothing to do with Java ! You fell in love with marketing ! Har, har, har. "

But Douglas Crockford did what you promised me never to do: tee eff em arrived. The sequel was surprising. He discovered, buried under the curly jaws of JavaScript, shameless comparison operators and disconcerting scope rules, a particularly powerful language, which was quite different from the many type C script languages ​​that pollute the programming ecosystem.

Crockford devoted himself to trying-doing. He showed and published on his website that it was possible to make JavaScript objects with private and hidden fields, a feat that the textbooks of the time implied was impossible. He separated his larger programs into suitably independent modules (idem).

He used JavaScript object literals as the basis of his data exchange format called "JSON" – that is the JSON that everyone now uses for everything – fully specified on a single, short web page. (In this period, the Waterstones shelves were moaning with thick and thick volumes, some heavy enough to contain a self-closing fire door, preaching the virtues of JSON's anointed rival, the indescribable / illegible XML.) [19659002] Created JSLint, a program that pushed its users towards the path blessed by Crockford of healthy JavaScript, and with a famous and generous license "IBM, its customers, partners and minions" to use this tool for evil.

Above all, he wrote JavaScript: The Good Parts . This "grumpy booklet" (description © D Crockford) was adopted by a considerable electorate as the closest equivalent of JavaScript to K&R, or Stroustrup, or Klabnik and Nichols. He even had a Hello, World as the first program.

Eeyore & # 39; s Gloomy Place

A decade later, thanks in large part to Crockford's contributions, the importance of language has increased n -doblez. A consequence of this: in recent times, language has undergone serial manipulation, culminating in annual revisions of its standard. Good Parts has become obsolete.

How JavaScript works is not a reworking of Good Parts but is a product of the same basic approach. Crockford traces the characteristic language by characteristic: pointing out traps, rejecting facilities he considers dangerous gewgaws, suggesting solutions, recommending techniques.

It is, in the jargon of JavaScript blogs, a stubborn resource. "If I don't mention your favorite feature, it's very likely because that feature is crap." If he mentions it he can still repent. These are just some of his unfavorable things:

  • Callbacks, promises and async / wait – that is, the three code sequence structures used by the old and modern Node.js programmers. These Crockford styles are "the three errors"
  • ES6 generators ("added during the time when the standards process suffered serious Python envy." The Crockford code snippet that demonstrates an alternative looks much more orderly and elegant, he should have the standards committee slapping his forehead together and shouting "Oh!")
  • They revoked exceptions ("a terrible practice that C ++ made popular")
  • The fat arrow => ("Farts [sic] is an abbreviated way of writing functions." Given reasons for disgust: a problem with ambiguous keys when a thick arrow is used to return an object, and the danger of confusing it with < = and > = . Really?)
  • The keyword class ("The coders who use the class will go to their graves without knowing how miserable were ")

There are some newer JS Functions that they receive a warmer welcome: the method Array.reduce is r Ated as "kind of bright". But such enthusiasm is spent frugally.

By the way, the TypeScript language is not mentioned, the current toast of many of those fashionable children of React, the inventor of the Ryan Dahl node, and in fact myself. Given Mr. Crockford's low opinion about type safety ("Types can induce us to adopt cryptic, complex and doubtful coding practices") and his advice in italics "Transpilators should never be used in production" I think we can safely assume that TypeScript is firmly buried in its "garbage" heap. Boo hoo.

Tigger bounces in

The book is not pessimistic at all; rather it is sadness and remedy.

Consider the first chapters. These deal with the type of JavaScript number, which is based on 64-bit IEEE floating point numbers. Every few minutes, somewhere in the world, a naive JavaScripter falls into this hole

  0.1 + 0.2 === 0.3 // false, obv

so it is reasonable for Crockford to highlight it. (On the other hand, I suspect your report of this wrinkle

  (1/0) === (1 / -0) // also false

is there just to entertain readers. It works for me.)

The next bit is smart: disapproving a standard proposal to complement number with a BigInt takes the lower 24 bits of the doubles and ordinary tortures to be become the basis of a library of arbitrary precision integers. Not satisfied with this, he extends his library of integers to make a "large floating point" library, designed cleverly so that the tenths add up correctly, and then take it further to create a "large rational" library that works with fractions, although vulgar

Everything is very ingenious … but building a model of the SS Titanic with worn Vestas is also ingenious. And one is concerned about performance (of arithmetic, not coincidences). Again, my data sources rarely give me up to 14 bits of accuracy on a sunny day; I dare to say that those who do financial calculations will be duly grateful.

This general approach sets the template: identify a problem in the language, then provide a solution.

… but I am not convinced that the solution is always necessary. "Applicants" are Crockford's alternative to callbacks, promises and asynchronous / pending functions from Node.js. That the first two are problematic is indisputable; But Crockford's objection to async / wait, as I understand it, is that it hides its underlying mechanism from its users, who consequently do not understand its operation.

This seems to me the old argument, presented long ago by the smoking pipes and generation of leather patches on the elbow, so that no one is allowed to use C until he dominates the assembly of Z80. I am not buying it. Also, miserably conservative that I am, I feel reluctant to be a pioneer in a fourth callback mechanism when my base code is already plagued by a confusing mix of the other three.

A much more promising innovation is JSCheck, a powerful variation of the usual unit testing framework. Instead of forcing the programmer to write tests a tedious affirm Equals () at the same time according to the lumpen prescription of the TDD crowd, the JSCheck tests are configured using predicate functions that indicate true when the results are good ones. When activated, the target code is bombarded with automatically generated random values. It seems much more blurry than conventional unit tests, and I'm eager to try it with anger.

The book itself ends with a chapter based on the famous WAT talk by Gary Bernhardt (which in turn was surely influenced by Crockford Appendix "Bad pieces" in Good pieces ). The most perverse corners of JavaScript are exposed. As always, the unfair equality operator of JavaScript and its empty arrays

  [] == [] // false
[] ==! [] // true

provide hours of fun for children.

Tonstant Weader doesn't fly up

I ran into How JavaScript works by accident. The book has come out almost a year. It has not appeared in any podcast of my headphones. There is no Egghead course to celebrate it, and at the time of writing this article there is only a rather bitter criticism on

Given the importance of JavaScript and the provenance of the book, this is surprising. I suspect that it was not published by a "known" imprint is part of the problem, in fact, there are several signs of self-publication; The cover is decorated with a humorous headline: THE BLOCKBUSTER IMPACTANT THAT DARE TO ROTATE THE COVER BEHIND THE SCENES!

Crockford has always been happily iconoclastic, and has always followed the Third Doctor. dictum about being serious on purpose, if not approaching.

These are admirable qualities, but the relentless joke tends to blur the lens. He could do with an editor. My services are available and have an incredibly good value. If it is taken, I will fix the problem of wun in wunce. ®

Verity Stob is the pseudonym of a London-based software developer. Since 1988, he has written his "Verity Stob" column for the .EXE, Dr. Dobb & # 39; s Journal and, since 2002, The Register .

What follows after Netezza?

For More Updates Check out Blog, Windows Softwares Drivers, Antivirus, Ms Office, Graphic Design Don’t Forget to Look Our Facebook Page Get Into Pc like us & follow on Twitter- @getinpc

Please Note: This content is provided and hosted by a 3rd party server. Sometimes these servers may include advertisements. does not host or upload this material and is not responsible for the content.