Tell all the Truth but tell it slant
Success in Circuit lies
Too bright for our infirm Delight
The Truth's superb surprise
function cube(x) x * x * x
use unit acme.widgets "http://acme.com/widgets";
unit acme.widget { // program unit definition goes here ... }
class Dict.<K, V>
with key, value type params
k1.equals(k2), k.hashcode()
k1 === k2, intrinsic::hashcode(k)
Object
to Dict.<K, *> for several key types K
let d : Dict.<string, int> = {a: 1, b: 2, c: 3};
Sensible JSON integration via toJSONString
Name still in flux (Hash
? Dictionary
? HashMap
? Ugh)
ByteArrays, Vectors, Tuples
ByteArray
class, converts from Array
Array.map
etc. work on it, albeit generically
- Parameterized type
Vector.<T>
- Dense, optionally fixed length
Vector.<T>(length : uint = 0, fixed : boolean = false)
ByteArray
could be subsumed by Vector.<byte>
- If we are willing to add a
byte
type
- Structural array
type A = [int, string, boolean]
is a tuple
- Not a named
Tuple
type!
- Fixed length with type constraints
- Type-checked compatibility with
Array
Type System Trade-offs
- We believe untyped objects will abound forever
- But typed APIs, including structural types, will emerge
- Nominal (class) hierarchies (DOM, Flex, etc.) likely too
- But they won't take over the Web
- So we're not turning JS into Java
- Most common case: Untyped code calling Typed API
- Another important case: class matching structural type
Structural Types as Contracts
- Given
function f(a : {p: int, q: string}) ...
- Assume it's a structurally typed API method
- What does
f({p: 42, q: "hi"})
check, and when?
- Use cases want early and deep checking
- An untyped object could mutate after the check
- Checking every read too costly, yet still incomplete
- See MochiKit's
isArrayLike
, isDateLike
- Given a class
C
with the right instance vars,
- passing
f(new C(42, "hi"))
can go fast
Performance Trends
- "Fastest browser on the planet" i-bench bragging
- Pure JS performance not critical (yet, for common cases)
- DOM and rendering dominate critical paths, but:
- DOM bindings hide JS dynamic typing costs
- Developers are pushing hard at the frontiers
- John Resig wrote and collected some benchmarks
- http://ejohn.org/apps/js-speed/results/
New Projects
ActionMonkey
- Mascot wannabe:
- Merge Tamarin and SpiderMonkey
- Targeting Mozilla 2 release, beta next year
- First stage integrates Tamarin's Garbage Collector
- Later stages include trace-based JITing
IronMonkey
- Inspiration:
- Map IronPython and IronRuby to Tamarin
- Avoid forking C# source using Mono C# compiler
- Bytecode translation a la IKVM, JaCIL
- Led by Seo Sanxiyn of FePy and PyPy fame
ScreamingMonkey
- Goal: support Tamarin in other browsers
- Led by Mark Hammond of Windows Python fame
- First target: IE integration as an ActiveScript engine
- Handle these RFC 4329 content
<script> type=
values:
application/ecmascript;version=4
application/javascript;version=2
- Other browser integrations to follow
The Truth About JavaScript
- JavaScript is...
- Occasionally a curse
- Often a blessing, formerly in disguise
- Spreading from the browser (Rhino on Rails)
- Growing muscle and speed
- Upgradeable in browsers (even in IE)
The 'J' in AJAX The 'j' in Ajax?
Vlad's Photos Demo
Finis