Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.
Paren-free                              Brendan Eich                          brendan@mozilla.orgSaturday, June 11, 2011
MotivationSaturday, June 11, 2011
HistorySaturday, June 11, 2011
History                     •    JS derives from Java from C++ from C (via early C and B), from                          B...
History                     •    JS derives from Java from C++ from C (via early C and B), from                          B...
History                     •    JS derives from Java from C++ from C (via early C and B), from                          B...
Examples                if year > 2010 {                    syntax++                }                for let i of iter {  ...
Examples, cont.                     •    Must support:        •   but not mandate:                           if x < y {   ...
Syntax                     •    IfStatement :                            if   Expression SubStatement else SubStatement   ...
Syntax, cont.                     •    KeywordStatement :    •   Statement :                           IfStatement        ...
CompatibilitySaturday, June 11, 2011
Compatibility                     •    if, while, do-while, and switch statements, where the                          head...
Compatibility                     •    if, while, do-while, and switch statements, where the                          head...
Compatibility                     •    if, while, do-while, and switch statements, where the                          head...
Compatibility                     •    if, while, do-while, and switch statements, where the                          head...
Compatibility                     •    if, while, do-while, and switch statements, where the                          head...
Compatibility                     •    if, while, do-while, and switch statements, where the                          head...
for-in & for-ofSaturday, June 11, 2011
for-in & for-of                     •    for k in o iterates over keys not values for all objects o.Saturday, June 11, 2011
for-in & for-of                     •    for k in o iterates over keys not values for all objects o.                     •...
for-in & for-of                     •    for k in o iterates over keys not values for all objects o.                     •...
for-in & for-of                     •    for k in o iterates over keys not values for all objects o.                     •...
for-in & for-of                     •    for k in o iterates over keys not values for all objects o.                     •...
for-in & for-of                     •    for k in o iterates over keys not values for all objects o.                     •...
for-in & for-of                     •    for k in o iterates over keys not values for all objects o.                     •...
Prochain SlideShare
Chargement dans…5
×

Paren free

4 634 vues

Publié le

My bonus #txjs talk, on paren-free (not in ES.next yet but now backward compatible), also the for-in (same old) and for-of (over values including iterators) loops.

Publié dans : Technologie
  • DOWNLOAD FULL. BOOKS INTO AVAILABLE FORMAT ......................................................................................................................... ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Répondre 
    Voulez-vous vraiment ?  Oui  Non
    Votre message apparaîtra ici

Paren free

  1. 1. Paren-free Brendan Eich brendan@mozilla.orgSaturday, June 11, 2011
  2. 2. MotivationSaturday, June 11, 2011
  3. 3. HistorySaturday, June 11, 2011
  4. 4. History • JS derives from Java from C++ from C (via early C and B), from BCPL. BCPL had paren-free if, etc., heads disambiguated via the do reserved word to separate an expression consequent, avoiding ambiguity.Saturday, June 11, 2011
  5. 5. History • JS derives from Java from C++ from C (via early C and B), from BCPL. BCPL had paren-free if, etc., heads disambiguated via the do reserved word to separate an expression consequent, avoiding ambiguity. • Many JS style guides favor mandatory bracing of if consequents and other sub-statement bodies, in order to avoid dangling else bugs.Saturday, June 11, 2011
  6. 6. History • JS derives from Java from C++ from C (via early C and B), from BCPL. BCPL had paren-free if, etc., heads disambiguated via the do reserved word to separate an expression consequent, avoiding ambiguity. • Many JS style guides favor mandatory bracing of if consequents and other sub-statement bodies, in order to avoid dangling else bugs. • By comparison to nearby programming languages, JS syntax is “shifty” to write and noisy to read. Can we do better?Saturday, June 11, 2011
  7. 7. Examples if year > 2010 { syntax++ } for let i of iter { // i is fresh on each iteration frob(i) } while lo <= hi { let mid = (lo + hi) / 2 // binary search body goes here } ... return [i * i for i in range(n)] // array comprehensionSaturday, June 11, 2011
  8. 8. Examples, cont. • Must support: • but not mandate: if x < y { if x < y { } else if x < z { } else { } else if x < w { if x < z { } else { } else { } if x < w { } else { } } }Saturday, June 11, 2011
  9. 9. Syntax • IfStatement : if Expression SubStatement else SubStatement if Expression SubStatement if ( Expression ) OtherStatement else Statement if ( Expression ) OtherStatement • etc. for while, do-while, for, switch, catch • SubStatement : Block KeywordStatementSaturday, June 11, 2011
  10. 10. Syntax, cont. • KeywordStatement : • Statement : IfStatement Block IterationStatement KeywordStatement ContinueStatement OtherStatement BreakStatement ReturnStatement SwitchStatement • OtherStatement : ThrowStatement TryStatement EmptyStatement DebuggerStatement ExpressionStatement LabelledStatement VariableStatementSaturday, June 11, 2011
  11. 11. CompatibilitySaturday, June 11, 2011
  12. 12. Compatibility • if, while, do-while, and switch statements, where the head syntax is Expression, which may be over-parenthesized.Saturday, June 11, 2011
  13. 13. Compatibility • if, while, do-while, and switch statements, where the head syntax is Expression, which may be over-parenthesized. • try, catch, finally must be braced as in ES3 and ES5.Saturday, June 11, 2011
  14. 14. Compatibility • if, while, do-while, and switch statements, where the head syntax is Expression, which may be over-parenthesized. • try, catch, finally must be braced as in ES3 and ES5. • catch heads may be parenthesized or unparenthesized.Saturday, June 11, 2011
  15. 15. Compatibility • if, while, do-while, and switch statements, where the head syntax is Expression, which may be over-parenthesized. • try, catch, finally must be braced as in ES3 and ES5. • catch heads may be parenthesized or unparenthesized. • for heads may be parenthesized or unparenthesized.Saturday, June 11, 2011
  16. 16. Compatibility • if, while, do-while, and switch statements, where the head syntax is Expression, which may be over-parenthesized. • try, catch, finally must be braced as in ES3 and ES5. • catch heads may be parenthesized or unparenthesized. • for heads may be parenthesized or unparenthesized. • for-in/of heads may be parenthesized or unparenthesized.Saturday, June 11, 2011
  17. 17. Compatibility • if, while, do-while, and switch statements, where the head syntax is Expression, which may be over-parenthesized. • try, catch, finally must be braced as in ES3 and ES5. • catch heads may be parenthesized or unparenthesized. • for heads may be parenthesized or unparenthesized. • for-in/of heads may be parenthesized or unparenthesized. • for-of loop, comprehension, and generator expression new semantics (next slide).Saturday, June 11, 2011
  18. 18. for-in & for-ofSaturday, June 11, 2011
  19. 19. for-in & for-of • for k in o iterates over keys not values for all objects o.Saturday, June 11, 2011
  20. 20. for-in & for-of • for k in o iterates over keys not values for all objects o. • for k of {p:1, q:2} iterates over 1, 2.Saturday, June 11, 2011
  21. 21. for-in & for-of • for k in o iterates over keys not values for all objects o. • for k of {p:1, q:2} iterates over 1, 2. • for v of [3, 4, 5] iterates over 3, 4, 5.Saturday, June 11, 2011
  22. 22. for-in & for-of • for k in o iterates over keys not values for all objects o. • for k of {p:1, q:2} iterates over 1, 2. • for v of [3, 4, 5] iterates over 3, 4, 5. • for k of keys(o) iterates over keys in o.Saturday, June 11, 2011
  23. 23. for-in & for-of • for k in o iterates over keys not values for all objects o. • for k of {p:1, q:2} iterates over 1, 2. • for v of [3, 4, 5] iterates over 3, 4, 5. • for k of keys(o) iterates over keys in o. • for v of values(o) iterates over values in o.Saturday, June 11, 2011
  24. 24. for-in & for-of • for k in o iterates over keys not values for all objects o. • for k of {p:1, q:2} iterates over 1, 2. • for v of [3, 4, 5] iterates over 3, 4, 5. • for k of keys(o) iterates over keys in o. • for v of values(o) iterates over values in o. • for [k, v] of items(o) iterates over key/value pairs.Saturday, June 11, 2011
  25. 25. for-in & for-of • for k in o iterates over keys not values for all objects o. • for k of {p:1, q:2} iterates over 1, 2. • for v of [3, 4, 5] iterates over 3, 4, 5. • for k of keys(o) iterates over keys in o. • for v of values(o) iterates over values in o. • for [k, v] of items(o) iterates over key/value pairs. • for x of proxy iterates using the handler iterate trap. (http://wiki.ecmascript.org/doku.php?id=harmony:iterators)Saturday, June 11, 2011

×