Skip to content

Instantly share code, notes, and snippets.

@dfkaye
Last active September 20, 2022 07:30
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dfkaye/660cde02ead1344757d7ab9a37e1068c to your computer and use it in GitHub Desktop.
Save dfkaye/660cde02ead1344757d7ab9a37e1068c to your computer and use it in GitHub Desktop.
Notes from Douglas Crockford's "Post-JavaScript Apocalypse" talk

Notes from Douglas Crockford's "Post-JavaScript Apocalypse" talk

Video: https://www.youtube.com/watch?v=NPB34lDZj3E

Programming languages are full of clutter

Programming languages are full of clutter because programmers are hoarders.

"POST-javascript? Why not PUT- or PATCH-javascript?"

The HTTP verbs do similar things but have possible edge cases.

That's not helpful, that's clutter.

Reduce clutter

money quote from this talk:

When confronted with two or more ways of doing the same thing, keep the one you can't get rid of.

TAB vs. Space

"We can't get rid of Space, so the one that has to go is TAB.

var vs. let or const

let has block scope which makes it less confusing to the Java guys (his joke, not mine), so use let.

const means you can't reassign the variable which is better, so given the choice, use const over let.

single- vs. double-quotes for strings

Keep double quotes. "and use single quotes for something's apostrophe."

null vs. undefined

These are "bottom" values. Every language should have one. And only one.

Keep undefined, ditch null.

The null implementation in JavaScript is broken, should be an object that contains nothing, and any property access on null should return null instead of throwing an error.

pure functions

This portion is funny. Pure functions mean immutability, no side-effects, etc. Things to be removed in order to prohibit mutation include:

  1. Date
  2. Math.random
  3. delete
  4. Array.splice
  5. Array.sort
  6. RegExp.exec
  7. assignment
  8. var
  9. let
  10. the for loop - that also means for in and for of
  11. user interaction
  12. networks...

In other words, the universe is mutating. So keep pure where you can, but you need to account for the changing input (an account balance cannot be a constant for all time, e.g.).

generators*

This feature is a mistake (!) - "weird syntax, unproductive, unnecessary" - just need to understand how a JavaScript function can return another function.

Factory is a well-understood pattern:

function factory(...) {

  // state variables
  
  return function generator() {
  
    // update state, then...
    
    return value
  }
}

element generator example

function element(array) {
  let i = 0;
  return function generator() {
    if (i < array.length) {
      let value = array[i];
      i += 1;
      return value;
    }
  }
}

Callback parameter - first or last?

Due to ES6 rest parameter syntax, ...rest, callbacks should now be in first position.

Promises

Not originally for asynchronicity. We can do better.

mentions RQ project - seems to be deprecated in favor of parseq project

Syntax

Syntax is all about fashion, it's not about functionality

[ here follows a very interesting look at BCPL which got the if statement right ]

if a = 0 { a := b; }

But how about algol-68 if-fi plus python significant whitespace?

if a = 0 
  a : b
fi

No more curly braces, semi-colons, use colons for assignment, etc...

finally

In the JVM, the finally clause is a symptom, that Java did not originally have free-standing functions. To get around this, the Exception system was overloaded to get around the design error in the Type system (catch). Result: overly complicated control flows - AKA goto. In JavaScript, try {} catch(e) {} is enough.

"".indexOf('z') returns -1

Should have returned null or undefined rather than an int.

0.1 + 0.2 === 0.3 returns false

Binary floating point cannot accurately represent decimal expressions. And that breaks associativity.

Proposal: Decimal64 number type: Number = coefficient (56-bit) * 10 (raised to the exponent)

See https://github.com/douglascrockford/DEC64

0 / 0 returns ...?

Undefined? NaN? 0? 1? 2?

For theoretical mathematical purposes, 'not defined' or 'not allowed' or 'Not a Number' makes sense, but for business purposes ('how much profit did we make on the items we didn't sell?'), then 0 is the right answer.

0 * NaN returns ...?

NaN! Which is part of that binary floating point spec, which punishes the wicked, slows things down for moral reasons, not for mathematical reasons.

Just return 0 and let compilation be faster, forget compilation jumps, etc.

reserved words

Too restrictive. Memory constraints on the early compilers no longer apply.

Proposal:

In any function, a word may used as a language keyword (if) or a name (variable) but not both.

camelCase vs. under_bar?

Neither. "Names with spaces" instead.

contracts

Eiffel language in any function allowed for pre-conditions and post-conditions, right in the function.

More effective than Type systems, more effective than unit tests because they're right there in the code. Should get back to that, and leave them on in production.

security

Make this the first requirement of the next language.

distribution

Take advantage of multiple cores, and nodes across the network. The next language should have something like actors (i.e., actor model), a new paradigm, not Fortan but with new syntax.

warning

Be careful out there because the web is cluttered and full of errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment