SlideShare a Scribd company logo
The
Better
Parts
Antoine de Saint-ExupéryAntoine de Saint-Exupéry
JS Fest 2018. Douglas Crockford. The Better Parts
Il semble que la perfection soit atteinte
non quand il n’y a plus rien à ajouter,
mais quand il n’y a plus rien à retrancher.
Antoine de Saint-Exupéry
Terre des Hommes, 1939
It seems that perfection is attained
not when there is nothing more to add,
but when there is nothing more to take away.
Good Parts
It seems that perfection is attained
not when there is nothing more to add,
but when there is nothing more to take away.
If a feature is sometimes
useful and sometimes
dangerous
and if there is a better option then
always use the better option.
We are not paid to use every
feature of the language.
We are paid to write
programs that work
well and are free of
error.
We are not paid to use every
feature of the language.
We are paid to write
programs that work
well and are free of
error.
A good programming
language should teach you.
I made every mistake with
JavaScript you could make.
JS Fest 2018. Douglas Crockford. The Better Parts
JS Fest 2018. Douglas Crockford. The Better Parts
Arguments against good parts
• Just a matter of opinion.
• Every feature is an essential tool.
• It is sometimes useful.
• I have a right to use every feature.
• I need the freedom to express myself.
• I need to reduce my keystrokes.
• It is an insult to suggest that I would ever make a
mistake with a dangerous feature.
• There is a good reason those features were added
to the language.
Foot Guns
Brendan Eich
The purpose of a
programming language is to
aid programmers in
producing error-free
programs.
It is not possible to write good
programs in JavaScript.
It is not only possible to
write good programs in
JavaScript,
it is necessary.
It is not possible to write good
programs in JavaScript.
Java <> JavaScript
Java <> JavaScript
Star Trek Star Wars
Java <> JavaScript
Star Trek
• Phasers
• Photon Torpedoes
• Uniforms
• Regulations
Star Wars
Java <> JavaScript
Star Trek
• Phasers
• Photon Torpedoes
• Uniforms
• Regulations
Star Wars
• Light Sabres & Blasters
• Proton Torpedoes
• Sand
• Chaos
JS Fest 2018. Douglas Crockford. The Better Parts
JS Fest 2018. Douglas Crockford. The Better Parts
Meesa
web
ninja!
The fantasy of infallibility.
The futility of faultlessness.
Danger Driven Development
Scheduling
A.The time it takes to write the code.
B. The time it takes to make the code
work right.
Always take the time to code well.
New Good Parts in ES6
• Proper tail calls:
return func();
New Good Parts in ES6
• Proper tail calls
• Ellipsis...aka ...rest, aka ...spread
function curry(func, ...first) {
return function (...second) {
return func(...first, ...second);
};
}
function curry(func) {
var slice = Array.prototype.slice, args = slice.call(arguments, 1);
return function () {
return func.apply(null, args.concat(slice.call(arguments, 0)));
};
}
New Good Parts in ES6
• Proper tail calls
• Ellipsis
• Module
New Good Parts in ES6
• Proper tail calls
• Ellipsis
• Module
• let and const
const fax = {};
fax = faz; // bad
fax.fay = faz; // ok
New Good Parts in ES6
• Proper tail calls
• Ellipsis
• Module
• Let
• Destructuring
let {that, other} = some_object;
let that = some_object.that, other = some_object.other;
New Good Parts in ES6
• Proper tail calls
• Ellipsis
• Module
• let and const
• Destructuring
• WeakMap
New Good Parts in ES6
• Proper tail calls
• Ellipsis
• Module
• let and const
• Destructuring
• WeakMap
• Megastring literals
var rx_number = /^(0(?:b[01]+|o[0-7]+|x[0-9a-fA-
F]+|.[0-9]+(?:e[+-]?[0-9]+)?)?|[1-9][0-
9]*(?:.[0-9]+)?(?:e[+-]?[0-9]+)?)$/;
function mega_regexp(str, fl) {
return new RegExp(str.replace(/s/, ""), fl);
}
const rx_number = mega_regexp(`^(
0 (?:
b [01]+
| o [0-7]+
| x [0-9 a-f A-F]+
| . [0-9]+ (?: e [+ -]? [0-9]+ )?
)?
| [1-9] [0-9]*
(?: . [0-9]+ )? (?: e [+ -]? [0-9]+ )?
)$`);
var rx_number = /^(0(?:b[01]+|o[0-7]+|x[0-9a-fA-
F]+|.[0-9]+(?:e[+-]?[0-9]+)?)?|[1-9][0-
9]*(?:.[0-9]+)?(?:e[+-]?[0-9]+)?)$/;
function mega_regexp(str, fl) {
return new RegExp(str.replace(/s/, ""), fl);
}
const rx_number = mega_regexp(`^(
0 (?:
b [01]+
| o [0-7]+
| x [0-9 a-f A-F]+
| . [0-9]+ (?: e [+ -]? [0-9]+ )?
)?
| [1-9] [0-9]*
(?: . [0-9]+ )? (?: e [+ -]? [0-9]+ )?
)$`);
http://jex.im/regulex
New Bad Parts in ES6
• Proxies
• Generators
• Iterators
• Symbols
• Reflect
• Fat Arrow Functions
(name) => {id: name}
Worst Bad Part in ES6
class
Good Parts Reconsidered
• I stopped using new years ago.
Use Object.create instead.
Good Parts Reconsidered
• I stopped using new years ago.
• I have stopped using Object.create.
Good Parts Reconsidered
• I stopped using new years ago.
• I have stopped using Object.create.
• I have stopped using this.
[ADsafe.org]
Good Parts Reconsidered
• I stopped using new years ago.
• I have stopped using Object.create.
• I have stopped using this.
• I have stopped using null.
Good Parts Reconsidered
• I stopped using new years ago.
• I have stopped using Object.create.
• I have stopped using this.
• I have stopped using null.
• I have stopped using falsiness.
Loops Reconsidered
• I don’t use for.
I now use array.forEach and its many
sisters.
• I don’t use for in. I now use
Object.keys(object).forEach.
• ES6 will have proper tail calls.
At that point I will stop using while.
function repeat(func) {
while (func() !== undefined) {
}
}
function repeat(func) {
if (func() !== undefined) {
return repeat(func);
}
}
The Next Language
Programmers are as
emotional and irrational
as normal people.
It took a generation to agree that
high level languages were a good
idea.
It took a generation to agree that
goto was a bad idea.
It took a generation to agree that
objects were a good idea.
It took two generations to agree that
lambdas were a good idea.
Systems languages
Application languages
Classical Inheritance
Prototypal Inheritance
Classification
Taxonomy
Prototypal Inheritance
• Memory conservation.
• May have made sense in 1995.
• Confusion: Own vs inherited.
• Retroactive heredity.
• Performance inhibiting.
Prototypal Inheritance
Class Free
Block Scope
{
let a;
{
let b;
… a …
… b …
}
… a …
}
Function Scope
function green() {
let a;
function yellow() {
let b;
… a …
… b …
}
… a …
}
Function Scope
function green() {
let a;
function yellow() {
let b;
… a …
… b …
}
… a …
}
a
Closure
function green() {
let a;
function yellow() {
let b;
… a …
… b …
}
… a …
}
a b
Inner survives the outer
function green() {
let a;
return function yellow() {
let b;
… a …
… b …
};
… a …
}
function constructor(spec) {
let {member} = spec;
let {other} = other_constructor(spec);
let method = function () {
// member, other, method, spec
};
return Object.freeze({
method,
other
});
}
function constructor(spec) {
let {member} = spec;
const {other} = other_constructor(spec);
let method = function () {
// member, other, method, spec
};
return Object.freeze({
method,
other
});
}
function constructor(spec) {
let {member} = spec;
const {other} = other_constructor(spec);
const method = function () {
// member, other, method, spec
};
return Object.freeze({
method,
other
});
}
function constructor(spec) {
let {member} = spec;
const {other} = other_constructor(spec);
const method = function () {
// member, other, method, spec
};
return Object.freeze({
method,
other
});
}
A Bug Story
private int index;
int
• Overflow errors
• Complement: saving gates in
subtraction
• Memory used to be really
expensive and scarce
Number types
Java: byte char short int long float double
Wastes the programmer’s time by having to select the
right type.
Errors result from choosing the wrong type.
No real benefit from chosing the right type.
JavaScript: number (same as double)
Having only one type is a huge improvement.
Unfortunately, it is the wrong type.
Number types
Java: byte char short int long float double
Wastes the programmer’s time by having to select the
right type.
Errors result from choosing the wrong type.
No real benefit.
JavaScript: number (same as double)
Having only one type is a huge improvement.
Unfortunately, it is the wrong type.
0.1 + 0.2 == 0.3
false
Binary Floating Point
Made a lot of sense in the 1950s.
Scientific | Business
DEC64
Number = Coefficient * 10Exponent
CoefficientCoefficient
Exponent
dec64.com
https://github.com/douglascrockford/DEC64/
CoefficientCoefficient
Exponent
The JSON Data Interchange
Format
JSON, XML
JSON, XML
Advice to data format
standard designers
• Don’t break JSON.
• Make it significantly better.
• Get a better name.
JSON
Java-
Script
Object
Notation
Responsibility
1. The People
2. The Team
3. Management
And finally,
one piece of advice:
Don’t make bugs.

More Related Content

PPTX
JS Fest 2018. Виталий Ратушный. ES X
JSFestUA
 
PDF
JS Fest 2018. Никита Галкин. Микросервисная архитектура с переиспользуемыми к...
JSFestUA
 
PPTX
C++ vs C#
sudipv
 
PDF
Design Patterns in Modern C++
Dmitri Nesteruk
 
PPTX
Pure virtual function and abstract class
Amit Trivedi
 
ODP
ooc - A hybrid language experiment
Amos Wenger
 
PPTX
C# for C++ Programmers
russellgmorley
 
PPTX
C# for C++ programmers
Mark Whitaker
 
JS Fest 2018. Виталий Ратушный. ES X
JSFestUA
 
JS Fest 2018. Никита Галкин. Микросервисная архитектура с переиспользуемыми к...
JSFestUA
 
C++ vs C#
sudipv
 
Design Patterns in Modern C++
Dmitri Nesteruk
 
Pure virtual function and abstract class
Amit Trivedi
 
ooc - A hybrid language experiment
Amos Wenger
 
C# for C++ Programmers
russellgmorley
 
C# for C++ programmers
Mark Whitaker
 

What's hot (20)

PPTX
Introduction to Programming Bots
Dmitri Nesteruk
 
PDF
Monte Carlo C++
Dmitri Nesteruk
 
PPTX
All You Need to Know About Type Script
Folio3 Software
 
PDF
JavaScript for Web Analysts
Lukáš Čech
 
PDF
[COSCUP 2020] How to use llvm frontend library-libtooling
Douglas Chen
 
PPTX
Connecting C++ and JavaScript on the Web with Embind
Chad Austin
 
PDF
Introduction to Dart
RameshNair6
 
PDF
Swimat - Swift formatter
Jintin Lin
 
PPTX
Iron Languages - NYC CodeCamp 2/19/2011
Jimmy Schementi
 
PDF
Dove sono i tuoi vertici e di cosa stanno parlando?
Codemotion
 
PDF
A quick and fast intro to Kotlin
XPeppers
 
PDF
Hourglass Interfaces for C++ APIs - CppCon 2014
Stefanus Du Toit
 
PDF
Missing objects: ?. and ?? in JavaScript (BrazilJS 2018)
Igalia
 
PDF
Kotlin cheat sheet by ekito
Arnaud Giuliani
 
PPTX
Typescript tips & tricks
Ori Calvo
 
PDF
Kotlin, smarter development for the jvm
Arnaud Giuliani
 
PDF
C++ Tail Recursion Using 64-bit variables
PVS-Studio
 
ODP
Groovy AST Transformations
hendersk
 
PDF
Large Scale JavaScript with TypeScript
Oliver Zeigermann
 
PDF
Metaprogramming
Mehmet Emin İNAÇ
 
Introduction to Programming Bots
Dmitri Nesteruk
 
Monte Carlo C++
Dmitri Nesteruk
 
All You Need to Know About Type Script
Folio3 Software
 
JavaScript for Web Analysts
Lukáš Čech
 
[COSCUP 2020] How to use llvm frontend library-libtooling
Douglas Chen
 
Connecting C++ and JavaScript on the Web with Embind
Chad Austin
 
Introduction to Dart
RameshNair6
 
Swimat - Swift formatter
Jintin Lin
 
Iron Languages - NYC CodeCamp 2/19/2011
Jimmy Schementi
 
Dove sono i tuoi vertici e di cosa stanno parlando?
Codemotion
 
A quick and fast intro to Kotlin
XPeppers
 
Hourglass Interfaces for C++ APIs - CppCon 2014
Stefanus Du Toit
 
Missing objects: ?. and ?? in JavaScript (BrazilJS 2018)
Igalia
 
Kotlin cheat sheet by ekito
Arnaud Giuliani
 
Typescript tips & tricks
Ori Calvo
 
Kotlin, smarter development for the jvm
Arnaud Giuliani
 
C++ Tail Recursion Using 64-bit variables
PVS-Studio
 
Groovy AST Transformations
hendersk
 
Large Scale JavaScript with TypeScript
Oliver Zeigermann
 
Metaprogramming
Mehmet Emin İNAÇ
 
Ad

Similar to JS Fest 2018. Douglas Crockford. The Better Parts (20)

KEY
LISP: How I Learned To Stop Worrying And Love Parantheses
Dominic Graefen
 
PPT
Goodparts
damonjablons
 
PDF
Javascript The Good Parts
Federico Galassi
 
PDF
Fluent14
Brendan Eich
 
ODP
Learn JavaScript by modeling Rubik Cube
Manoj Kumar
 
PPT
Javascript
Sunil Thakur
 
PDF
The Rust Programming Language 2nd Edition Second Converted Steve Klabnik Caro...
cizekchingbj
 
KEY
Exciting JavaScript - Part I
Eugene Lazutkin
 
PDF
Js in-ten-minutes
Phong Vân
 
PDF
Technology: A Means to an End with Thibault Imbert
FITC
 
PDF
FITC '14 Toronto - Technology, a means to an end
Thibault Imbert
 
PDF
The Rust Programming Language Second Edition 2 Converted Steve Klabnik
nuovochady2s
 
PDF
javascript teach
guest3732fa
 
PDF
JSBootcamp_White
guest3732fa
 
PDF
The Rust Programming Language 2nd Edition Steve Klabnik
urbuuawara
 
KEY
Object Oriented Programming in js
threepointone
 
PPT
Douglas Crockford Presentation Goodparts
Ajax Experience 2009
 
PDF
JS Responsibilities
Brendan Eich
 
PDF
A Re-Introduction to JavaScript
Simon Willison
 
PPTX
ES6: Features + Rails
Santosh Wadghule
 
LISP: How I Learned To Stop Worrying And Love Parantheses
Dominic Graefen
 
Goodparts
damonjablons
 
Javascript The Good Parts
Federico Galassi
 
Fluent14
Brendan Eich
 
Learn JavaScript by modeling Rubik Cube
Manoj Kumar
 
Javascript
Sunil Thakur
 
The Rust Programming Language 2nd Edition Second Converted Steve Klabnik Caro...
cizekchingbj
 
Exciting JavaScript - Part I
Eugene Lazutkin
 
Js in-ten-minutes
Phong Vân
 
Technology: A Means to an End with Thibault Imbert
FITC
 
FITC '14 Toronto - Technology, a means to an end
Thibault Imbert
 
The Rust Programming Language Second Edition 2 Converted Steve Klabnik
nuovochady2s
 
javascript teach
guest3732fa
 
JSBootcamp_White
guest3732fa
 
The Rust Programming Language 2nd Edition Steve Klabnik
urbuuawara
 
Object Oriented Programming in js
threepointone
 
Douglas Crockford Presentation Goodparts
Ajax Experience 2009
 
JS Responsibilities
Brendan Eich
 
A Re-Introduction to JavaScript
Simon Willison
 
ES6: Features + Rails
Santosh Wadghule
 
Ad

More from JSFestUA (20)

PDF
JS Fest 2019/Autumn. Роман Савіцький. Webcomponents & lit-element in production
JSFestUA
 
PDF
JS Fest 2019/Autumn. Erick Wendel. 10 secrets to improve Javascript Performance
JSFestUA
 
PDF
JS Fest 2019/Autumn. Alexandre Gomes. Embrace the "react fatigue"
JSFestUA
 
PDF
JS Fest 2019/Autumn. Anton Cherednikov. Choreographic or orchestral architect...
JSFestUA
 
PDF
JS Fest 2019/Autumn. Adam Leos. So why do you need to know Algorithms and Dat...
JSFestUA
 
PDF
JS Fest 2019/Autumn. Marko Letic. Saving the world with JavaScript: A Data Vi...
JSFestUA
 
PPTX
JS Fest 2019/Autumn. Александр Товмач. JAMstack
JSFestUA
 
PPTX
JS Fest 2019/Autumn. Влад Федосов. Technology agnostic microservices at SPA f...
JSFestUA
 
PPTX
JS Fest 2019/Autumn. Дмитрий Жарков. Blockchainize your SPA or Integrate Java...
JSFestUA
 
PPTX
JS Fest 2019/Autumn. Maciej Treder. Angular Schematics - Develop for developers
JSFestUA
 
PPTX
JS Fest 2019/Autumn. Kyle Boss. A Tinder Love Story: Create a Wordpress Blog ...
JSFestUA
 
PPTX
JS Fest 2019/Autumn. Андрей Старовойт. Зачем нужен тип "true" в TypeScript?
JSFestUA
 
PPTX
JS Fest 2019/Autumn. Eyal Eizenberg. Tipping the Scale
JSFestUA
 
PDF
JS Fest 2019/Autumn. Sota Ohara. Сreate own server less CMS from scratch
JSFestUA
 
PPTX
JS Fest 2019/Autumn. Джордж Евтушенко. Как стать программистом, которого хотят
JSFestUA
 
PDF
JS Fest 2019/Autumn. Алексей Орленко. Node.js N-API for Rust
JSFestUA
 
PDF
JS Fest 2019/Autumn. Daniel Ostrovsky. Falling in love with decorators ES6/Ty...
JSFestUA
 
PPTX
JS Fest 2019/Autumn. Андрей Андрийко. Гексагональна архітектура в Nodejs проекті
JSFestUA
 
PPTX
JS Fest 2019/Autumn. Борис Могила. Svelte. Почему нам не нужно run-time ядро
JSFestUA
 
PPTX
JS Fest 2019/Autumn. Виталий Кухар. Сравнение кластеризации HTTP, TCP и UDP н...
JSFestUA
 
JS Fest 2019/Autumn. Роман Савіцький. Webcomponents & lit-element in production
JSFestUA
 
JS Fest 2019/Autumn. Erick Wendel. 10 secrets to improve Javascript Performance
JSFestUA
 
JS Fest 2019/Autumn. Alexandre Gomes. Embrace the "react fatigue"
JSFestUA
 
JS Fest 2019/Autumn. Anton Cherednikov. Choreographic or orchestral architect...
JSFestUA
 
JS Fest 2019/Autumn. Adam Leos. So why do you need to know Algorithms and Dat...
JSFestUA
 
JS Fest 2019/Autumn. Marko Letic. Saving the world with JavaScript: A Data Vi...
JSFestUA
 
JS Fest 2019/Autumn. Александр Товмач. JAMstack
JSFestUA
 
JS Fest 2019/Autumn. Влад Федосов. Technology agnostic microservices at SPA f...
JSFestUA
 
JS Fest 2019/Autumn. Дмитрий Жарков. Blockchainize your SPA or Integrate Java...
JSFestUA
 
JS Fest 2019/Autumn. Maciej Treder. Angular Schematics - Develop for developers
JSFestUA
 
JS Fest 2019/Autumn. Kyle Boss. A Tinder Love Story: Create a Wordpress Blog ...
JSFestUA
 
JS Fest 2019/Autumn. Андрей Старовойт. Зачем нужен тип "true" в TypeScript?
JSFestUA
 
JS Fest 2019/Autumn. Eyal Eizenberg. Tipping the Scale
JSFestUA
 
JS Fest 2019/Autumn. Sota Ohara. Сreate own server less CMS from scratch
JSFestUA
 
JS Fest 2019/Autumn. Джордж Евтушенко. Как стать программистом, которого хотят
JSFestUA
 
JS Fest 2019/Autumn. Алексей Орленко. Node.js N-API for Rust
JSFestUA
 
JS Fest 2019/Autumn. Daniel Ostrovsky. Falling in love with decorators ES6/Ty...
JSFestUA
 
JS Fest 2019/Autumn. Андрей Андрийко. Гексагональна архітектура в Nodejs проекті
JSFestUA
 
JS Fest 2019/Autumn. Борис Могила. Svelte. Почему нам не нужно run-time ядро
JSFestUA
 
JS Fest 2019/Autumn. Виталий Кухар. Сравнение кластеризации HTTP, TCP и UDP н...
JSFestUA
 

Recently uploaded (20)

PPTX
Autodock-for-Beginners by Rahul D Jawarkar.pptx
Rahul Jawarkar
 
PPTX
Odoo 18 Sales_ Managing Quotation Validity
Celine George
 
PDF
RA 12028_ARAL_Orientation_Day-2-Sessions_v2.pdf
Seven De Los Reyes
 
PDF
Sunset Boulevard Student Revision Booklet
jpinnuck
 
PDF
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
PPTX
CDH. pptx
AneetaSharma15
 
PPTX
CONCEPT OF CHILD CARE. pptx
AneetaSharma15
 
PDF
BÀI TẬP TEST BỔ TRỢ THEO TỪNG CHỦ ĐỀ CỦA TỪNG UNIT KÈM BÀI TẬP NGHE - TIẾNG A...
Nguyen Thanh Tu Collection
 
PPTX
FSSAI (Food Safety and Standards Authority of India) & FDA (Food and Drug Adm...
Dr. Paindla Jyothirmai
 
PDF
PG-BPSDMP 2 TAHUN 2025PG-BPSDMP 2 TAHUN 2025.pdf
AshifaRamadhani
 
PDF
Antianginal agents, Definition, Classification, MOA.pdf
Prerana Jadhav
 
PDF
2.Reshaping-Indias-Political-Map.ppt/pdf/8th class social science Exploring S...
Sandeep Swamy
 
PPTX
Introduction to pediatric nursing in 5th Sem..pptx
AneetaSharma15
 
PPTX
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
PPTX
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
PPTX
TEF & EA Bsc Nursing 5th sem.....BBBpptx
AneetaSharma15
 
PPTX
An introduction to Dialogue writing.pptx
drsiddhantnagine
 
PPTX
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
PoojaSen20
 
PPTX
Care of patients with elImination deviation.pptx
AneetaSharma15
 
PDF
Phylum Arthropoda: Characteristics and Classification, Entomology Lecture
Miraj Khan
 
Autodock-for-Beginners by Rahul D Jawarkar.pptx
Rahul Jawarkar
 
Odoo 18 Sales_ Managing Quotation Validity
Celine George
 
RA 12028_ARAL_Orientation_Day-2-Sessions_v2.pdf
Seven De Los Reyes
 
Sunset Boulevard Student Revision Booklet
jpinnuck
 
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
CDH. pptx
AneetaSharma15
 
CONCEPT OF CHILD CARE. pptx
AneetaSharma15
 
BÀI TẬP TEST BỔ TRỢ THEO TỪNG CHỦ ĐỀ CỦA TỪNG UNIT KÈM BÀI TẬP NGHE - TIẾNG A...
Nguyen Thanh Tu Collection
 
FSSAI (Food Safety and Standards Authority of India) & FDA (Food and Drug Adm...
Dr. Paindla Jyothirmai
 
PG-BPSDMP 2 TAHUN 2025PG-BPSDMP 2 TAHUN 2025.pdf
AshifaRamadhani
 
Antianginal agents, Definition, Classification, MOA.pdf
Prerana Jadhav
 
2.Reshaping-Indias-Political-Map.ppt/pdf/8th class social science Exploring S...
Sandeep Swamy
 
Introduction to pediatric nursing in 5th Sem..pptx
AneetaSharma15
 
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
TEF & EA Bsc Nursing 5th sem.....BBBpptx
AneetaSharma15
 
An introduction to Dialogue writing.pptx
drsiddhantnagine
 
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
PoojaSen20
 
Care of patients with elImination deviation.pptx
AneetaSharma15
 
Phylum Arthropoda: Characteristics and Classification, Entomology Lecture
Miraj Khan
 

JS Fest 2018. Douglas Crockford. The Better Parts

  • 4. Il semble que la perfection soit atteinte non quand il n’y a plus rien à ajouter, mais quand il n’y a plus rien à retrancher. Antoine de Saint-Exupéry Terre des Hommes, 1939 It seems that perfection is attained not when there is nothing more to add, but when there is nothing more to take away.
  • 5. Good Parts It seems that perfection is attained not when there is nothing more to add, but when there is nothing more to take away.
  • 6. If a feature is sometimes useful and sometimes dangerous and if there is a better option then always use the better option.
  • 7. We are not paid to use every feature of the language. We are paid to write programs that work well and are free of error.
  • 8. We are not paid to use every feature of the language. We are paid to write programs that work well and are free of error.
  • 9. A good programming language should teach you.
  • 10. I made every mistake with JavaScript you could make.
  • 13. Arguments against good parts • Just a matter of opinion. • Every feature is an essential tool. • It is sometimes useful. • I have a right to use every feature. • I need the freedom to express myself. • I need to reduce my keystrokes. • It is an insult to suggest that I would ever make a mistake with a dangerous feature. • There is a good reason those features were added to the language.
  • 15. The purpose of a programming language is to aid programmers in producing error-free programs.
  • 16. It is not possible to write good programs in JavaScript.
  • 17. It is not only possible to write good programs in JavaScript, it is necessary. It is not possible to write good programs in JavaScript.
  • 19. Java <> JavaScript Star Trek Star Wars
  • 20. Java <> JavaScript Star Trek • Phasers • Photon Torpedoes • Uniforms • Regulations Star Wars
  • 21. Java <> JavaScript Star Trek • Phasers • Photon Torpedoes • Uniforms • Regulations Star Wars • Light Sabres & Blasters • Proton Torpedoes • Sand • Chaos
  • 25. The fantasy of infallibility. The futility of faultlessness.
  • 27. Scheduling A.The time it takes to write the code. B. The time it takes to make the code work right. Always take the time to code well.
  • 28. New Good Parts in ES6 • Proper tail calls: return func();
  • 29. New Good Parts in ES6 • Proper tail calls • Ellipsis...aka ...rest, aka ...spread function curry(func, ...first) { return function (...second) { return func(...first, ...second); }; } function curry(func) { var slice = Array.prototype.slice, args = slice.call(arguments, 1); return function () { return func.apply(null, args.concat(slice.call(arguments, 0))); }; }
  • 30. New Good Parts in ES6 • Proper tail calls • Ellipsis • Module
  • 31. New Good Parts in ES6 • Proper tail calls • Ellipsis • Module • let and const const fax = {}; fax = faz; // bad fax.fay = faz; // ok
  • 32. New Good Parts in ES6 • Proper tail calls • Ellipsis • Module • Let • Destructuring let {that, other} = some_object; let that = some_object.that, other = some_object.other;
  • 33. New Good Parts in ES6 • Proper tail calls • Ellipsis • Module • let and const • Destructuring • WeakMap
  • 34. New Good Parts in ES6 • Proper tail calls • Ellipsis • Module • let and const • Destructuring • WeakMap • Megastring literals
  • 35. var rx_number = /^(0(?:b[01]+|o[0-7]+|x[0-9a-fA- F]+|.[0-9]+(?:e[+-]?[0-9]+)?)?|[1-9][0- 9]*(?:.[0-9]+)?(?:e[+-]?[0-9]+)?)$/; function mega_regexp(str, fl) { return new RegExp(str.replace(/s/, ""), fl); } const rx_number = mega_regexp(`^( 0 (?: b [01]+ | o [0-7]+ | x [0-9 a-f A-F]+ | . [0-9]+ (?: e [+ -]? [0-9]+ )? )? | [1-9] [0-9]* (?: . [0-9]+ )? (?: e [+ -]? [0-9]+ )? )$`);
  • 36. var rx_number = /^(0(?:b[01]+|o[0-7]+|x[0-9a-fA- F]+|.[0-9]+(?:e[+-]?[0-9]+)?)?|[1-9][0- 9]*(?:.[0-9]+)?(?:e[+-]?[0-9]+)?)$/; function mega_regexp(str, fl) { return new RegExp(str.replace(/s/, ""), fl); } const rx_number = mega_regexp(`^( 0 (?: b [01]+ | o [0-7]+ | x [0-9 a-f A-F]+ | . [0-9]+ (?: e [+ -]? [0-9]+ )? )? | [1-9] [0-9]* (?: . [0-9]+ )? (?: e [+ -]? [0-9]+ )? )$`); http://jex.im/regulex
  • 37. New Bad Parts in ES6 • Proxies • Generators • Iterators • Symbols • Reflect • Fat Arrow Functions
  • 38. (name) => {id: name}
  • 39. Worst Bad Part in ES6 class
  • 40. Good Parts Reconsidered • I stopped using new years ago. Use Object.create instead.
  • 41. Good Parts Reconsidered • I stopped using new years ago. • I have stopped using Object.create.
  • 42. Good Parts Reconsidered • I stopped using new years ago. • I have stopped using Object.create. • I have stopped using this. [ADsafe.org]
  • 43. Good Parts Reconsidered • I stopped using new years ago. • I have stopped using Object.create. • I have stopped using this. • I have stopped using null.
  • 44. Good Parts Reconsidered • I stopped using new years ago. • I have stopped using Object.create. • I have stopped using this. • I have stopped using null. • I have stopped using falsiness.
  • 45. Loops Reconsidered • I don’t use for. I now use array.forEach and its many sisters. • I don’t use for in. I now use Object.keys(object).forEach. • ES6 will have proper tail calls. At that point I will stop using while.
  • 46. function repeat(func) { while (func() !== undefined) { } } function repeat(func) { if (func() !== undefined) { return repeat(func); } }
  • 48. Programmers are as emotional and irrational as normal people.
  • 49. It took a generation to agree that high level languages were a good idea. It took a generation to agree that goto was a bad idea. It took a generation to agree that objects were a good idea. It took two generations to agree that lambdas were a good idea.
  • 53. Prototypal Inheritance • Memory conservation. • May have made sense in 1995. • Confusion: Own vs inherited. • Retroactive heredity. • Performance inhibiting.
  • 55. Block Scope { let a; { let b; … a … … b … } … a … }
  • 56. Function Scope function green() { let a; function yellow() { let b; … a … … b … } … a … }
  • 57. Function Scope function green() { let a; function yellow() { let b; … a … … b … } … a … } a
  • 58. Closure function green() { let a; function yellow() { let b; … a … … b … } … a … } a b
  • 59. Inner survives the outer function green() { let a; return function yellow() { let b; … a … … b … }; … a … }
  • 60. function constructor(spec) { let {member} = spec; let {other} = other_constructor(spec); let method = function () { // member, other, method, spec }; return Object.freeze({ method, other }); }
  • 61. function constructor(spec) { let {member} = spec; const {other} = other_constructor(spec); let method = function () { // member, other, method, spec }; return Object.freeze({ method, other }); }
  • 62. function constructor(spec) { let {member} = spec; const {other} = other_constructor(spec); const method = function () { // member, other, method, spec }; return Object.freeze({ method, other }); }
  • 63. function constructor(spec) { let {member} = spec; const {other} = other_constructor(spec); const method = function () { // member, other, method, spec }; return Object.freeze({ method, other }); }
  • 64. A Bug Story private int index;
  • 65. int • Overflow errors • Complement: saving gates in subtraction • Memory used to be really expensive and scarce
  • 66. Number types Java: byte char short int long float double Wastes the programmer’s time by having to select the right type. Errors result from choosing the wrong type. No real benefit from chosing the right type. JavaScript: number (same as double) Having only one type is a huge improvement. Unfortunately, it is the wrong type.
  • 67. Number types Java: byte char short int long float double Wastes the programmer’s time by having to select the right type. Errors result from choosing the wrong type. No real benefit. JavaScript: number (same as double) Having only one type is a huge improvement. Unfortunately, it is the wrong type.
  • 68. 0.1 + 0.2 == 0.3 false
  • 69. Binary Floating Point Made a lot of sense in the 1950s. Scientific | Business
  • 70. DEC64 Number = Coefficient * 10Exponent CoefficientCoefficient Exponent
  • 72. The JSON Data Interchange Format
  • 75. Advice to data format standard designers • Don’t break JSON. • Make it significantly better. • Get a better name.
  • 77. Responsibility 1. The People 2. The Team 3. Management
  • 78. And finally, one piece of advice: Don’t make bugs.