-
Notifications
You must be signed in to change notification settings - Fork 6
Coming from JavaScript
ES6 EcmaScript6 added a lot of nice things to JavaScript, but didn't address JavaScript's three biggest shortcomings:
- It dramatically reduces the number of tokens required to code.
- It ensures everything returns a value, so you can program in a functional way.
- It avoids JavaScript's pitfalls:
- JavaScript's == and != are dangerous, so CaffeineScript compiles == and != into ===, and !==.
JavaScript should be considered a machine-language. It is more machine-friendly than human-friendly. And that's great! Like the JVM, it's a runtime that is available on all platforms. Even better than JVM byte-codes, Javascript is vaguely human-readable. As such, it's easy to inspect the generated code and see what's going on under the CaffeineScript hood.
I strongly believe 'less is more.' Given that, it's no surprise I think JavaScript's syntax is horrible. We can do so much better:
# CaffeineScript - 19 tokens including only 2 must-match-tokens: #{ and }
import &MyFramework
class HelloMessage extends Component
render: ->
Div "" Hello #{@props.name}.
render HelloMessage name: :Bob
// ES6 - 55 tokens including 22 must-match-tokens: 5 ()'s, 3 {}'s, and one each of ${}, `` and ''
var {createFactory, render, Div} = require('MyFramework');
var HelloMessage = (class HelloMessage extends Component {
render: () => Div(`Hello ${this.props.name}.`);
}).createWithPostCreate();
render(HelloMessage({
name: 'Bob'
}));
It's hard to overestimate the negative impact on a language built on first-class-functions (i.e. functions are also values and can be used anywhere any other value can), that contains so much non-functional syntax, i.e. syntax that doesn't return a value:
- JavaScript functions don't return a value, unless you manually add 'return'
- Some of the many JavaScript constructs that don't return values:
- if statements
- try statements
- switch statements
- 'while' and 'for' loops
Read more about how CaffeineScript addresses JavaScript's dangerous Semantics.
- Home
- Get Started
- Benefits
- Highlights
- Productivity by Design
- CaffeineScript Design
- What is CaffeineScript Good For?
- Get the most out of JavaScript
- Language Comparison
- CHANGELOG
- Blocks Instead of Brackets
- Binary Line-Starts
- Everything Returns a Value
- Streamlined Modules
- Scopes and Variables
- Optional Commas
- Semantics
- Ambiguities