Khan Academy Computer Science

jeresig
Khan Academy
Computer Science
     John Resig (ejohn.org)
   http://khanacademy.org/cs
Inspiration


• Bret Victor
 • http://vimeo.com/36579366
Learning to Program

• Learn through hands-on experimentation
• Learn by looking at other people’s code
• Learn by building on other people’s code
CS Projects
                    “Forked”     New



• “Forked”: 62930
• New: 22225
                    26%



• 1.86m Views                  74%
Github in Disguise

• Forking (Hitting “Save as...”)
• Versioning (Not yet user exposed)
• Runtime Versioning
 • All runtime changes are versioned to
    protect against API changes
Implementation

• Graphics: Processing.js
• Real-time Execution
 • Dynamic Injection
 • Error handling
Graphics

• Use Processing.js’ API
• Works in all browsers with <canvas>
• Import it wholesale, ignore the “Processing
  language” bits
Real-Time Execution

• Code is constantly checked for changes
• If a change is detected, code is re-evaluated
• Code is not run using a simple “eval”, code
  is dynamically injected into the current
  runtime.
How Code is Injected
•   JSHint (run in worker thread)
    •   Optionally run BabyHint
    •   If Error, stop execution
•   Cache Images
•   Run Code in Worker Thread, Looking for long-running code
    •   If error, stop execution
•   Execute Code
    •   If first time running code, just eval
    •   If later:
        •   Eval code and extract current state
        •   Inject extracted values into runtime
        •   Maintain closures with functions!
Error Messages


• All code is run through JSHint
• And through an extra layer of error
  handling (called “BabyHint”)
JSHint
• Validation!
• Also: Gives us a list of all global variables
  used in the program
• Compare against a master list of properties
  in Processing.js
• Everything else is user-defined!
BabyHint
•   Handles common mistakes:
    •   Spelling and case: “strokeWeight” vs.
        “strokeweight”
    •   Gives sane errors about missing semicolons
    •   Provide hints about correct function arguments
        strokeWeight(); (gives an error asking for more
        args)
    •   Check for function declaration mistakes and
        possible spacing mistakes (“vartest”)
Worker Threads

• Run JavaScript code asynchronously in the
  background of a page
• Available in Chrome, Firefox, Safari, and IE
  10 (Need to make sure it works in IE 9!)
• Works by doing a string-only postMessage
  to the worker and waiting for a response
With Statements
• var obj = { name: “John”, city: “Boston” };
  with (obj) {
    name += “ Resig”;
    city = “Brooklyn”;
  }
• obj.name === “John Resig”
  obj.city === “Brooklyn”
With Statements
• var obj = { name: “John”, city: “Boston” };
  with (obj) {
    var city = “Brooklyn”;
    var job = “Khan Academy”;
  }
• obj.city === “Brooklyn”
  obj.job === undefined
With Statements
• var obj = { name: “John”, city: “Boston” };
  obj.job = undefined;
  with (obj) {
    var city = “Brooklyn”;
    var job = “Khan Academy”;
  }
• obj.city === “Brooklyn”
  obj.job === “Khan Academy”
Example
•   var x = 5, y = 1;
    var draw = function() {
       x += y;
    };
•   JSHint: PASS
•   Long Run Detection: PASS
•   First Run: True
    •   Code is evaluated
    •   lastGrab = {
           x: “5”,
           y: “1”,
           draw: “function() { x += y; }”
        }
Example (cont.)
•   var x = 50, y = 1;
    var draw = function() {
       x += y;
    };

•   JSHint: PASS
•   Long Run Detection: PASS

•   First Run: False
    •   Code is evaluated

    •   grabAll = {
           x: “50”,
           y: “1”,
           draw: “function() { x += y; }”
        }
    •   Compare with lastGrab: grabAll.x !== lastGrab.x

    •   Eval: “var x = 50;”
Example (cont.)
•   var x = 50, y = 1;
    var draw = function() {
       x += y * 2;
    };

•   JSHint: PASS
•   Long Run Detection: PASS

•   First Run: False
    •   Code is evaluated

    •   grabAll = {
           x: “50”,
           y: “1”,
           draw: “function() { x += y * 2; }”
        }
    •   Compare with lastGrab: grabAll.draw !== lastGrab.draw

    •   Eval: “var draw = function() { x += y * 2; };”
1 of 19

Recommended

JavaScript Language Update 2016 (LLoT) by
JavaScript Language Update 2016 (LLoT)JavaScript Language Update 2016 (LLoT)
JavaScript Language Update 2016 (LLoT)Teppei Sato
10.2K views33 slides
使用.NET构建轻量级分布式框架 by
使用.NET构建轻量级分布式框架使用.NET构建轻量级分布式框架
使用.NET构建轻量级分布式框架jeffz
2.2K views19 slides
Dmytro Kochergin Angular 2 and New Java Script Technologies by
Dmytro Kochergin Angular 2 and New Java Script TechnologiesDmytro Kochergin Angular 2 and New Java Script Technologies
Dmytro Kochergin Angular 2 and New Java Script TechnologiesLogeekNightUkraine
111 views47 slides
LINQ Inside by
LINQ InsideLINQ Inside
LINQ Insidejeffz
2K views32 slides
How to-node-core by
How to-node-coreHow to-node-core
How to-node-coreIsaacSchlueter
9.8K views60 slides
JavaScript For CSharp Developer by
JavaScript For CSharp DeveloperJavaScript For CSharp Developer
JavaScript For CSharp DeveloperSarvesh Kushwaha
3.1K views18 slides

More Related Content

What's hot

Using JS to teach JS at Khan Academy by
Using JS to teach JS at Khan AcademyUsing JS to teach JS at Khan Academy
Using JS to teach JS at Khan Academyjeresig
1K views25 slides
Fighting Ruby code smell by
Fighting Ruby code smellFighting Ruby code smell
Fighting Ruby code smellolegshpynov
1.5K views17 slides
java8-patterns by
java8-patternsjava8-patterns
java8-patternsJustin Lin
15.3K views44 slides
«Управление логикой переходов между экранами приложения с помощью координатор... by
«Управление логикой переходов между экранами приложения с помощью координатор...«Управление логикой переходов между экранами приложения с помощью координатор...
«Управление логикой переходов между экранами приложения с помощью координатор...Mail.ru Group
3.4K views37 slides
I18nize Scala programs à la gettext by
I18nize Scala programs à la gettextI18nize Scala programs à la gettext
I18nize Scala programs à la gettextNgoc Dao
2K views35 slides
RubyMotion #jbday by
RubyMotion #jbdayRubyMotion #jbday
RubyMotion #jbdayDennis Ushakov
623 views19 slides

What's hot(17)

Using JS to teach JS at Khan Academy by jeresig
Using JS to teach JS at Khan AcademyUsing JS to teach JS at Khan Academy
Using JS to teach JS at Khan Academy
jeresig1K views
Fighting Ruby code smell by olegshpynov
Fighting Ruby code smellFighting Ruby code smell
Fighting Ruby code smell
olegshpynov1.5K views
java8-patterns by Justin Lin
java8-patternsjava8-patterns
java8-patterns
Justin Lin15.3K views
«Управление логикой переходов между экранами приложения с помощью координатор... by Mail.ru Group
«Управление логикой переходов между экранами приложения с помощью координатор...«Управление логикой переходов между экранами приложения с помощью координатор...
«Управление логикой переходов между экранами приложения с помощью координатор...
Mail.ru Group3.4K views
I18nize Scala programs à la gettext by Ngoc Dao
I18nize Scala programs à la gettextI18nize Scala programs à la gettext
I18nize Scala programs à la gettext
Ngoc Dao2K views
What's new in PHP 7.1 by Simon Jones
What's new in PHP 7.1What's new in PHP 7.1
What's new in PHP 7.1
Simon Jones319 views
Essential ElixirScript - Roman Senin by Elixir Club
Essential ElixirScript - Roman SeninEssential ElixirScript - Roman Senin
Essential ElixirScript - Roman Senin
Elixir Club229 views
Open World Forum 2014 : From ES6 to Javascript 2.0. What use today ? par Jon... by ALTER WAY
Open World Forum 2014  : From ES6 to Javascript 2.0. What use today ? par Jon...Open World Forum 2014  : From ES6 to Javascript 2.0. What use today ? par Jon...
Open World Forum 2014 : From ES6 to Javascript 2.0. What use today ? par Jon...
ALTER WAY1.2K views
Angular 2.0: Brighter future? by Eugene Zharkov
Angular 2.0: Brighter future?Angular 2.0: Brighter future?
Angular 2.0: Brighter future?
Eugene Zharkov726 views
Streams or Loops? Java 8 Stream API by Niki Petkov - Proxiad Bulgaria by HackBulgaria
Streams or Loops? Java 8 Stream API by Niki Petkov - Proxiad BulgariaStreams or Loops? Java 8 Stream API by Niki Petkov - Proxiad Bulgaria
Streams or Loops? Java 8 Stream API by Niki Petkov - Proxiad Bulgaria
HackBulgaria1.7K views
WDB005.1 - JavaScript for Java Developers (Lecture 1) by Igor Khotin
WDB005.1 - JavaScript for Java Developers (Lecture 1)WDB005.1 - JavaScript for Java Developers (Lecture 1)
WDB005.1 - JavaScript for Java Developers (Lecture 1)
Igor Khotin1.1K views

Viewers also liked

jQuery Internals + Cool Stuff by
jQuery Internals + Cool StuffjQuery Internals + Cool Stuff
jQuery Internals + Cool Stuffjeresig
6.1K views37 slides
JavaScript Libraries (Ajax Exp 2006) by
JavaScript Libraries (Ajax Exp 2006)JavaScript Libraries (Ajax Exp 2006)
JavaScript Libraries (Ajax Exp 2006)jeresig
3.1K views62 slides
JavaScript Libraries (Kings of Code) by
JavaScript Libraries (Kings of Code)JavaScript Libraries (Kings of Code)
JavaScript Libraries (Kings of Code)jeresig
2.2K views83 slides
Processing and Processing.js by
Processing and Processing.jsProcessing and Processing.js
Processing and Processing.jsjeresig
2.7K views15 slides
Secrets of JavaScript Libraries by
Secrets of JavaScript LibrariesSecrets of JavaScript Libraries
Secrets of JavaScript Librariesjeresig
41.5K views78 slides
Testing Mobile JavaScript (Fall 2010 by
Testing Mobile JavaScript (Fall 2010Testing Mobile JavaScript (Fall 2010
Testing Mobile JavaScript (Fall 2010jeresig
1.6K views48 slides

Viewers also liked(10)

jQuery Internals + Cool Stuff by jeresig
jQuery Internals + Cool StuffjQuery Internals + Cool Stuff
jQuery Internals + Cool Stuff
jeresig6.1K views
JavaScript Libraries (Ajax Exp 2006) by jeresig
JavaScript Libraries (Ajax Exp 2006)JavaScript Libraries (Ajax Exp 2006)
JavaScript Libraries (Ajax Exp 2006)
jeresig3.1K views
JavaScript Libraries (Kings of Code) by jeresig
JavaScript Libraries (Kings of Code)JavaScript Libraries (Kings of Code)
JavaScript Libraries (Kings of Code)
jeresig2.2K views
Processing and Processing.js by jeresig
Processing and Processing.jsProcessing and Processing.js
Processing and Processing.js
jeresig2.7K views
Secrets of JavaScript Libraries by jeresig
Secrets of JavaScript LibrariesSecrets of JavaScript Libraries
Secrets of JavaScript Libraries
jeresig41.5K views
Testing Mobile JavaScript (Fall 2010 by jeresig
Testing Mobile JavaScript (Fall 2010Testing Mobile JavaScript (Fall 2010
Testing Mobile JavaScript (Fall 2010
jeresig1.6K views
Building a JavaScript Library by jeresig
Building a JavaScript LibraryBuilding a JavaScript Library
Building a JavaScript Library
jeresig11.7K views
Understanding JavaScript Testing by jeresig
Understanding JavaScript TestingUnderstanding JavaScript Testing
Understanding JavaScript Testing
jeresig38.4K views
Crafting Visual Stories with Data by Amit Kapoor
Crafting Visual Stories with DataCrafting Visual Stories with Data
Crafting Visual Stories with Data
Amit Kapoor26.2K views
Geração Automática de Ontologias Probabilíticas a partir de um modelo UMP-ST by Diego Marques
Geração Automática de Ontologias Probabilíticas a partir de um modelo UMP-STGeração Automática de Ontologias Probabilíticas a partir de um modelo UMP-ST
Geração Automática de Ontologias Probabilíticas a partir de um modelo UMP-ST
Diego Marques371 views

Similar to Khan Academy Computer Science

JavaScript Good Practices by
JavaScript Good PracticesJavaScript Good Practices
JavaScript Good PracticesJussi Pohjolainen
1.3K views37 slides
JavaScript - Object-Oriented Programming & Remote Scripting by
JavaScript - Object-Oriented Programming & Remote ScriptingJavaScript - Object-Oriented Programming & Remote Scripting
JavaScript - Object-Oriented Programming & Remote ScriptingChen Huang
541 views31 slides
Javascript Everywhere by
Javascript EverywhereJavascript Everywhere
Javascript EverywherePascal Rettig
2.2K views54 slides
BITM3730Week6.pptx by
BITM3730Week6.pptxBITM3730Week6.pptx
BITM3730Week6.pptxMattMarino13
8 views33 slides
Unit Testing JavaScript Applications by
Unit Testing JavaScript ApplicationsUnit Testing JavaScript Applications
Unit Testing JavaScript ApplicationsYnon Perek
2.4K views96 slides
Ajax Under The Hood by
Ajax Under The HoodAjax Under The Hood
Ajax Under The HoodWO Community
1.9K views53 slides

Similar to Khan Academy Computer Science(20)

JavaScript - Object-Oriented Programming & Remote Scripting by Chen Huang
JavaScript - Object-Oriented Programming & Remote ScriptingJavaScript - Object-Oriented Programming & Remote Scripting
JavaScript - Object-Oriented Programming & Remote Scripting
Chen Huang541 views
Javascript Everywhere by Pascal Rettig
Javascript EverywhereJavascript Everywhere
Javascript Everywhere
Pascal Rettig2.2K views
Unit Testing JavaScript Applications by Ynon Perek
Unit Testing JavaScript ApplicationsUnit Testing JavaScript Applications
Unit Testing JavaScript Applications
Ynon Perek2.4K views
Ajax Under The Hood by WO Community
Ajax Under The HoodAjax Under The Hood
Ajax Under The Hood
WO Community1.9K views
ES3-2020-P3 TDD Calculator by David Rodenas
ES3-2020-P3 TDD CalculatorES3-2020-P3 TDD Calculator
ES3-2020-P3 TDD Calculator
David Rodenas114 views
Masterin Large Scale Java Script Applications by Fabian Jakobs
Masterin Large Scale Java Script ApplicationsMasterin Large Scale Java Script Applications
Masterin Large Scale Java Script Applications
Fabian Jakobs1.9K views
Profiling JavaScript Performance by FITC
Profiling JavaScript PerformanceProfiling JavaScript Performance
Profiling JavaScript Performance
FITC458 views
Learning JavaScript Programming by Hriday Ahmed
Learning JavaScript ProgrammingLearning JavaScript Programming
Learning JavaScript Programming
Hriday Ahmed2 views
Thinkful - Intro to JavaScript by TJ Stalcup
Thinkful - Intro to JavaScriptThinkful - Intro to JavaScript
Thinkful - Intro to JavaScript
TJ Stalcup161 views
Intro to javascript (6:19) by Thinkful
Intro to javascript (6:19)Intro to javascript (6:19)
Intro to javascript (6:19)
Thinkful142 views
Intro to JavaScript - Thinkful LA, June 2017 by Thinkful
Intro to JavaScript - Thinkful LA, June 2017Intro to JavaScript - Thinkful LA, June 2017
Intro to JavaScript - Thinkful LA, June 2017
Thinkful114 views
Java Script basics and DOM by Sukrit Gupta
Java Script basics and DOMJava Script basics and DOM
Java Script basics and DOM
Sukrit Gupta482 views
Tips and tricks for building high performance android apps using native code by Kenneth Geisshirt
Tips and tricks for building high performance android apps using native codeTips and tricks for building high performance android apps using native code
Tips and tricks for building high performance android apps using native code
Kenneth Geisshirt4.4K views
Selenium Tips & Tricks - StarWest 2015 by Andrew Krug
Selenium Tips & Tricks - StarWest 2015Selenium Tips & Tricks - StarWest 2015
Selenium Tips & Tricks - StarWest 2015
Andrew Krug1.5K views

More from jeresig

Does Coding Every Day Matter? by
Does Coding Every Day Matter?Does Coding Every Day Matter?
Does Coding Every Day Matter?jeresig
3K views19 slides
Accidentally Becoming a Digital Librarian by
Accidentally Becoming a Digital LibrarianAccidentally Becoming a Digital Librarian
Accidentally Becoming a Digital Librarianjeresig
1.3K views72 slides
2014: John's Favorite Thing (Neo4j) by
2014: John's Favorite Thing (Neo4j)2014: John's Favorite Thing (Neo4j)
2014: John's Favorite Thing (Neo4j)jeresig
847 views42 slides
Computer Vision as Art Historical Investigation by
Computer Vision as Art Historical InvestigationComputer Vision as Art Historical Investigation
Computer Vision as Art Historical Investigationjeresig
1K views89 slides
Hacking Art History by
Hacking Art HistoryHacking Art History
Hacking Art Historyjeresig
925 views107 slides
Applying Computer Vision to Art History by
Applying Computer Vision to Art HistoryApplying Computer Vision to Art History
Applying Computer Vision to Art Historyjeresig
826 views35 slides

More from jeresig(20)

Does Coding Every Day Matter? by jeresig
Does Coding Every Day Matter?Does Coding Every Day Matter?
Does Coding Every Day Matter?
jeresig3K views
Accidentally Becoming a Digital Librarian by jeresig
Accidentally Becoming a Digital LibrarianAccidentally Becoming a Digital Librarian
Accidentally Becoming a Digital Librarian
jeresig1.3K views
2014: John's Favorite Thing (Neo4j) by jeresig
2014: John's Favorite Thing (Neo4j)2014: John's Favorite Thing (Neo4j)
2014: John's Favorite Thing (Neo4j)
jeresig847 views
Computer Vision as Art Historical Investigation by jeresig
Computer Vision as Art Historical InvestigationComputer Vision as Art Historical Investigation
Computer Vision as Art Historical Investigation
jeresig1K views
Hacking Art History by jeresig
Hacking Art HistoryHacking Art History
Hacking Art History
jeresig925 views
Applying Computer Vision to Art History by jeresig
Applying Computer Vision to Art HistoryApplying Computer Vision to Art History
Applying Computer Vision to Art History
jeresig826 views
NYARC 2014: Frick/Zeri Results by jeresig
NYARC 2014: Frick/Zeri ResultsNYARC 2014: Frick/Zeri Results
NYARC 2014: Frick/Zeri Results
jeresig2.1K views
EmpireJS: Hacking Art with Node js and Image Analysis by jeresig
EmpireJS: Hacking Art with Node js and Image AnalysisEmpireJS: Hacking Art with Node js and Image Analysis
EmpireJS: Hacking Art with Node js and Image Analysis
jeresig18.5K views
Applying Computer Vision to Art History by jeresig
Applying Computer Vision to Art HistoryApplying Computer Vision to Art History
Applying Computer Vision to Art History
jeresig3.1K views
Introduction to jQuery (Ajax Exp 2006) by jeresig
Introduction to jQuery (Ajax Exp 2006)Introduction to jQuery (Ajax Exp 2006)
Introduction to jQuery (Ajax Exp 2006)
jeresig2.4K views
jQuery Recommendations to the W3C (2011) by jeresig
jQuery Recommendations to the W3C (2011)jQuery Recommendations to the W3C (2011)
jQuery Recommendations to the W3C (2011)
jeresig1.7K views
jQuery Open Source Process (RIT 2011) by jeresig
jQuery Open Source Process (RIT 2011)jQuery Open Source Process (RIT 2011)
jQuery Open Source Process (RIT 2011)
jeresig1.7K views
jQuery Open Source Process (Knight Foundation 2011) by jeresig
jQuery Open Source Process (Knight Foundation 2011)jQuery Open Source Process (Knight Foundation 2011)
jQuery Open Source Process (Knight Foundation 2011)
jeresig2.2K views
jQuery Mobile by jeresig
jQuery MobilejQuery Mobile
jQuery Mobile
jeresig1.5K views
jQuery Open Source (Fronteer 2011) by jeresig
jQuery Open Source (Fronteer 2011)jQuery Open Source (Fronteer 2011)
jQuery Open Source (Fronteer 2011)
jeresig4K views
Holistic JavaScript Performance by jeresig
Holistic JavaScript PerformanceHolistic JavaScript Performance
Holistic JavaScript Performance
jeresig4K views
New Features Coming in Browsers (RIT '09) by jeresig
New Features Coming in Browsers (RIT '09)New Features Coming in Browsers (RIT '09)
New Features Coming in Browsers (RIT '09)
jeresig1.5K views
Introduction to jQuery (Ajax Exp 2007) by jeresig
Introduction to jQuery (Ajax Exp 2007)Introduction to jQuery (Ajax Exp 2007)
Introduction to jQuery (Ajax Exp 2007)
jeresig1.3K views
Advanced jQuery (Ajax Exp 2007) by jeresig
Advanced jQuery (Ajax Exp 2007)Advanced jQuery (Ajax Exp 2007)
Advanced jQuery (Ajax Exp 2007)
jeresig1.3K views
JavaScript Library Overview (Ajax Exp West 2007) by jeresig
JavaScript Library Overview (Ajax Exp West 2007)JavaScript Library Overview (Ajax Exp West 2007)
JavaScript Library Overview (Ajax Exp West 2007)
jeresig1.4K views

Recently uploaded

Empathic Computing: Delivering the Potential of the Metaverse by
Empathic Computing: Delivering  the Potential of the MetaverseEmpathic Computing: Delivering  the Potential of the Metaverse
Empathic Computing: Delivering the Potential of the MetaverseMark Billinghurst
478 views80 slides
PharoJS - Zürich Smalltalk Group Meetup November 2023 by
PharoJS - Zürich Smalltalk Group Meetup November 2023PharoJS - Zürich Smalltalk Group Meetup November 2023
PharoJS - Zürich Smalltalk Group Meetup November 2023Noury Bouraqadi
127 views17 slides
AMAZON PRODUCT RESEARCH.pdf by
AMAZON PRODUCT RESEARCH.pdfAMAZON PRODUCT RESEARCH.pdf
AMAZON PRODUCT RESEARCH.pdfJerikkLaureta
26 views13 slides
SUPPLIER SOURCING.pptx by
SUPPLIER SOURCING.pptxSUPPLIER SOURCING.pptx
SUPPLIER SOURCING.pptxangelicacueva6
15 views1 slide
PRODUCT PRESENTATION.pptx by
PRODUCT PRESENTATION.pptxPRODUCT PRESENTATION.pptx
PRODUCT PRESENTATION.pptxangelicacueva6
14 views1 slide
Voice Logger - Telephony Integration Solution at Aegis by
Voice Logger - Telephony Integration Solution at AegisVoice Logger - Telephony Integration Solution at Aegis
Voice Logger - Telephony Integration Solution at AegisNirmal Sharma
39 views1 slide

Recently uploaded(20)

Empathic Computing: Delivering the Potential of the Metaverse by Mark Billinghurst
Empathic Computing: Delivering  the Potential of the MetaverseEmpathic Computing: Delivering  the Potential of the Metaverse
Empathic Computing: Delivering the Potential of the Metaverse
Mark Billinghurst478 views
PharoJS - Zürich Smalltalk Group Meetup November 2023 by Noury Bouraqadi
PharoJS - Zürich Smalltalk Group Meetup November 2023PharoJS - Zürich Smalltalk Group Meetup November 2023
PharoJS - Zürich Smalltalk Group Meetup November 2023
Noury Bouraqadi127 views
AMAZON PRODUCT RESEARCH.pdf by JerikkLaureta
AMAZON PRODUCT RESEARCH.pdfAMAZON PRODUCT RESEARCH.pdf
AMAZON PRODUCT RESEARCH.pdf
JerikkLaureta26 views
Voice Logger - Telephony Integration Solution at Aegis by Nirmal Sharma
Voice Logger - Telephony Integration Solution at AegisVoice Logger - Telephony Integration Solution at Aegis
Voice Logger - Telephony Integration Solution at Aegis
Nirmal Sharma39 views
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N... by James Anderson
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
James Anderson85 views
handbook for web 3 adoption.pdf by Liveplex
handbook for web 3 adoption.pdfhandbook for web 3 adoption.pdf
handbook for web 3 adoption.pdf
Liveplex22 views
Case Study Copenhagen Energy and Business Central.pdf by Aitana
Case Study Copenhagen Energy and Business Central.pdfCase Study Copenhagen Energy and Business Central.pdf
Case Study Copenhagen Energy and Business Central.pdf
Aitana16 views
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas... by Bernd Ruecker
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
Bernd Ruecker37 views
Five Things You SHOULD Know About Postman by Postman
Five Things You SHOULD Know About PostmanFive Things You SHOULD Know About Postman
Five Things You SHOULD Know About Postman
Postman33 views
Igniting Next Level Productivity with AI-Infused Data Integration Workflows by Safe Software
Igniting Next Level Productivity with AI-Infused Data Integration Workflows Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Safe Software263 views
Business Analyst Series 2023 - Week 3 Session 5 by DianaGray10
Business Analyst Series 2023 -  Week 3 Session 5Business Analyst Series 2023 -  Week 3 Session 5
Business Analyst Series 2023 - Week 3 Session 5
DianaGray10248 views
STKI Israeli Market Study 2023 corrected forecast 2023_24 v3.pdf by Dr. Jimmy Schwarzkopf
STKI Israeli Market Study 2023   corrected forecast 2023_24 v3.pdfSTKI Israeli Market Study 2023   corrected forecast 2023_24 v3.pdf
STKI Israeli Market Study 2023 corrected forecast 2023_24 v3.pdf
Serverless computing with Google Cloud (2023-24) by wesley chun
Serverless computing with Google Cloud (2023-24)Serverless computing with Google Cloud (2023-24)
Serverless computing with Google Cloud (2023-24)
wesley chun11 views
The details of description: Techniques, tips, and tangents on alternative tex... by BookNet Canada
The details of description: Techniques, tips, and tangents on alternative tex...The details of description: Techniques, tips, and tangents on alternative tex...
The details of description: Techniques, tips, and tangents on alternative tex...
BookNet Canada127 views

Khan Academy Computer Science

  • 1. Khan Academy Computer Science John Resig (ejohn.org) http://khanacademy.org/cs
  • 2. Inspiration • Bret Victor • http://vimeo.com/36579366
  • 3. Learning to Program • Learn through hands-on experimentation • Learn by looking at other people’s code • Learn by building on other people’s code
  • 4. CS Projects “Forked” New • “Forked”: 62930 • New: 22225 26% • 1.86m Views 74%
  • 5. Github in Disguise • Forking (Hitting “Save as...”) • Versioning (Not yet user exposed) • Runtime Versioning • All runtime changes are versioned to protect against API changes
  • 6. Implementation • Graphics: Processing.js • Real-time Execution • Dynamic Injection • Error handling
  • 7. Graphics • Use Processing.js’ API • Works in all browsers with <canvas> • Import it wholesale, ignore the “Processing language” bits
  • 8. Real-Time Execution • Code is constantly checked for changes • If a change is detected, code is re-evaluated • Code is not run using a simple “eval”, code is dynamically injected into the current runtime.
  • 9. How Code is Injected • JSHint (run in worker thread) • Optionally run BabyHint • If Error, stop execution • Cache Images • Run Code in Worker Thread, Looking for long-running code • If error, stop execution • Execute Code • If first time running code, just eval • If later: • Eval code and extract current state • Inject extracted values into runtime • Maintain closures with functions!
  • 10. Error Messages • All code is run through JSHint • And through an extra layer of error handling (called “BabyHint”)
  • 11. JSHint • Validation! • Also: Gives us a list of all global variables used in the program • Compare against a master list of properties in Processing.js • Everything else is user-defined!
  • 12. BabyHint • Handles common mistakes: • Spelling and case: “strokeWeight” vs. “strokeweight” • Gives sane errors about missing semicolons • Provide hints about correct function arguments strokeWeight(); (gives an error asking for more args) • Check for function declaration mistakes and possible spacing mistakes (“vartest”)
  • 13. Worker Threads • Run JavaScript code asynchronously in the background of a page • Available in Chrome, Firefox, Safari, and IE 10 (Need to make sure it works in IE 9!) • Works by doing a string-only postMessage to the worker and waiting for a response
  • 14. With Statements • var obj = { name: “John”, city: “Boston” }; with (obj) { name += “ Resig”; city = “Brooklyn”; } • obj.name === “John Resig” obj.city === “Brooklyn”
  • 15. With Statements • var obj = { name: “John”, city: “Boston” }; with (obj) { var city = “Brooklyn”; var job = “Khan Academy”; } • obj.city === “Brooklyn” obj.job === undefined
  • 16. With Statements • var obj = { name: “John”, city: “Boston” }; obj.job = undefined; with (obj) { var city = “Brooklyn”; var job = “Khan Academy”; } • obj.city === “Brooklyn” obj.job === “Khan Academy”
  • 17. Example • var x = 5, y = 1; var draw = function() { x += y; }; • JSHint: PASS • Long Run Detection: PASS • First Run: True • Code is evaluated • lastGrab = { x: “5”, y: “1”, draw: “function() { x += y; }” }
  • 18. Example (cont.) • var x = 50, y = 1; var draw = function() { x += y; }; • JSHint: PASS • Long Run Detection: PASS • First Run: False • Code is evaluated • grabAll = { x: “50”, y: “1”, draw: “function() { x += y; }” } • Compare with lastGrab: grabAll.x !== lastGrab.x • Eval: “var x = 50;”
  • 19. Example (cont.) • var x = 50, y = 1; var draw = function() { x += y * 2; }; • JSHint: PASS • Long Run Detection: PASS • First Run: False • Code is evaluated • grabAll = { x: “50”, y: “1”, draw: “function() { x += y * 2; }” } • Compare with lastGrab: grabAll.draw !== lastGrab.draw • Eval: “var draw = function() { x += y * 2; };”