Effective Java Programming Language Guide
Quotes from the Book
Computer programs are the most complex things that humans make.
We see a lot of feature-driven product design in which the cost of features is not properly accounted. Features can have a negative value to customers because they make the products more difficult to understand and use. We are finding that people like products that just work. It turns out that designs that just work are much harder to produce that designs that assemble long lists of features.
Generally, the craft of programming is the factoring of a set of requirements into a a set of functions and data structures.
Obsolete comments are worse than no comments.
If you want to learn more about the bad parts and how to use them badly, consult any other JavaScript book.
If we offend, it is with our good will That you should think, we come not to offend, But with good will. To show our simple skill, That is the true beginning of our end.
Quality was not a motivating concern in the design, implementation, or standardization of JavaScript. That puts a greater burden on the users of the language to resist the language's weaknesses.
Fortunately, JavaScript has some extraordinarily good parts. In JavaScript, there is a beautiful, elegant, highly expressive language that is buried under a steaming pile of good intentions and blunders.
JavaScript, being a loosely typed language, never casts. The lineage of an object is irrelevant. What matters about an object is what it can do, not what it is descended from.
Some languages offer the tail recursion optimization. This means that if a function returns the result of invoking itself recursively, then the invocation is replaced with a loop, which can significantly speed things up. Unfortunately, JavaScript does not currently provide tail recursion optimization. Functions that recurse very deeply can fail by exhausting the return stack:
There are four patterns of invocation in JavaScript: the method invocation pattern, the function invocation pattern, the constructor invocation pattern, and the apply invocation pattern.
Objects are passed around by reference. They are never copied:
Attempting to retrieve values from undefined will throw a TypeError exception. This can be guarded against with the && operator: flight.equipment // undefined flight.equipment.model // throw "TypeError" flight.equipment && flight.equipment.model // undefined
The || operator can be used to fill in default values: var middle = stooge["middle-name"] || "(none)"; var status = flight.status || "unknown";
A property value can be any JavaScript value except for undefined.
If a return expression is not specified, then the return value will be undefined.
a return expression is not specified, then the return value will be undefined.
The try statement executes a block and catches any exceptions that were thrown by the block. The catch clause defines a new variable that will receive the exception object. The throw statement raises an exception. If the throw statement is in a try block, then control goes to the catch clause. Otherwise, the function invocation is abandoned, and control goes to the catch clause of the try in the calling function. The expression is usually an object literal containing a name property and a message property. The catcher of the exception can use that information to determine what to do.
The other form (called for in) enumerates the property names (or keys) of an object. On each iteration, another property name string from the object is assigned to the variable.
Here are the falsy values: false null undefined The empty string '' The number 0 The number NaN All other values are truthy, including true, the string 'false', and all objects.
The switch, while, for, and do statements are allowed to have an optional label prefix that interacts with the break statement.
When used inside of a function, the var statement defines the function’s private variables.
Numbers JavaScript has a single number type. Internally, it is represented as 64-bit floating point, the same as Java’s double. Unlike most other programming languages, there is no separate integer type, so 1 and 1.0 are the same value. This is a significant convenience because problems of overflow in short integers are completely avoided, and all you need to know about a number is that it is a number. A large class of numeric type errors is avoided.
Names A name is a letter optionally followed by one or more letters, digits, or underbars. A name cannot be one of these reserved words: abstract boolean break byte case catch char class const continue debugger default delete do double else enum export extends false final finally float for function goto if implements import in instanceof int interface long native new null package private protected public return short static super switch synchronized this throw throws transient true try typeof var volatile void while with Most of the reserved words in this list are not used in the language. The list does not include some words that should have been reserved but were not, such as undefined, NaN, and Infinity. It is not permitted to name a variable or parameter with a reserved word. Worse, it is not permitted to use a reserved word as the name of an object property in an object literal or following a dot in a refinement. Names are used for statements, variables, parameters, property names, operators, and labels.
The best thing about JavaScript is its implementation of functions. It got almost everything right. But, as you should expect with JavaScript, it didn’t get everything right.
suppress empty strings in the output array when the separator is a regular expression: var f = '|a|b|c|'.split(/\|/); // f is ['a', 'b', 'c'] on some systems, and // f is ['', 'a', 'b', 'c', ''] on others string.substring(start, end ) The substring method is the same as the slice method except that it doesn’t handle the adjustment for negative parameters. There is no reason to use the substring method. Use slice instead. string.toLocaleLowerCase( ) The toLocaleLowerCase method produces a new string that is made by converting this string to lowercase using the rules for the locale. This is primarily for the benefit of Turkish because in that language `I’ converts to 1
Few classical programmers found prototypal inheritance to be acceptable, and classically inspired syntax obscures the language’s true prototypal nature. It is the worst of both worlds.
JavaScript is a language with more than its share of bad parts.
undefined and NaN are not constants. They are global variables, and you can change their values. That should not be possible, and yet it is. Don’t do it.
Watch on YouTube
About Douglas Crockford
About the book
Most programming languages contain good and bad parts, but JavaScript has more than its share of the bad, having been developed and released in a hurry before it could be refined. This authoritative book scrapes away these bad features to reveal a subset of JavaScript that's more reliable, readable, and maintainable than the language as a whole—a subset you can use to create truly extensible and efficient code. Considered the JavaScript expert by many people in the development community, author Douglas Crockford identifies the abundance of good ideas that make JavaScript an outstanding object-oriented programming language-ideas such as functions, loose typing, dynamic objects, and an expressive object literal notation. Unfortunately, these good ideas are mixed in with bad and downright awful ideas, like a programming model based on global variables. When Java applets failed, JavaScript b
Book details
- First published
- 2008
- Author
- Douglas Crockford
- Genre
- Nonfiction
- Goodreads rating
- 4.23 (9k ratings)
Keep reading
Effective Java Programming Language Guide
Code Complete
The Pragmatic Programmer: From Journeyman to Master
Humble Pi: A Comedy of Maths Errors
Structure and Interpretation of Computer Programs (MIT Electrical Engineering and Computer Science)
Domain-Driven Design: Tackling Complexity in the Heart of Software
Software Engineering at Google: Lessons Learned from Programming Over Time
Gödel, Escher, Bach: An Eternal Golden Braid
Don't Make Me Think, Revisited: A Common Sense Approach to Web Usability
Pragmatic Thinking and Learning: Refactor Your Wetware
Hackers & Painters: Big Ideas from the Computer Age
Getting Real: The Smarter, Faster, Easier Way to Build a Web Application
In the Beginning...Was the Command Line
Dreyer's English: An Utterly Correct Guide to Clarity and Style
Algorithms to Live By: The Computer Science of Human Decisions
The Design of Everyday Things
Continuous delivery
The Elements of Style
Word by Word: The Secret Life of Dictionaries
Because Internet: Understanding the New Rules of Language
The Most Human Human: What Talking with Computers Teaches Us About What It Means to Be Alive
The Unfolding of Language: An Evolutionary Tour of Mankind's Greatest Invention
Dataclysm: Who We Are
Managing Humans: Biting and Humorous Tales of a Software Engineering Manager
How Not to Write a Novel: 200 Classic Mistakes and How to Avoid Them—A Misstep-by-Misstep Guide
Rationality: From AI to Zombies
The Art of Thinking Clearly
The Elements of Eloquence: How to Turn the Perfect English Phrase
Eats, Shoots & Leaves: The Zero Tolerance Approach to Punctuation
Between You & Me: Confessions of a Comma Queen
Rework
Math with Bad Drawings
The Stuff of Thought: Language as a Window into Human Nature
Shape: The Hidden Geometry of Information, Biology, Strategy, Democracy, and EverythingElse
Philosophical Investigations
Babel-17
Antifragile: Things That Gain from Disorder
Microserfs
My Ishmael
Founders at Work: Stories of Startups' Early Days
Thinking In Systems: A Primer
In the Land of Invented Languages: Esperanto Rock Stars, Klingon Poets, Loglan Lovers, and the Mad Dreamers Who Tried to Build a Perfect Language
The Goal: A Process of Ongoing Improvement
Little Brother
Asterios Polyp
The Salmon of Doubt
Sin and Syntax: How to Craft Wickedly Effective Prose
Just for Fun: The Story of an Accidental Revolutionary
The 4-Hour Chef: The Simple Path to Cooking Like a Pro, Learning Anything, and Living the Good Life
The Mother Tongue: English and How It Got That Way
Permutation City
How To: Absurd Scientific Advice for Common Real-World Problems
The Feynman Lectures on Physics
The Blind Watchmaker: Why the Evidence of Evolution Reveals a Universe Without Design
A Night Without Stars
Lean Analytics: Use Data to Build a Better Startup Faster
The Language Instinct: How the Mind Creates Language
Mostly Harmless
Six Thinking Hats
