Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Livecoding in Javascript
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Jason Frame
May 09, 2013
Programming
1.4k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Livecoding in Javascript
Jason Frame
May 09, 2013
More Decks by Jason Frame
See All by Jason Frame
How to fake it for 18 months and (almost) launch a hardware product
jaz303
0
380
Entity Systems
jaz303
2
200
Ruby by the River
jaz303
1
1.2k
Other Decks in Programming
See All in Programming
Haskell/Servantを通してWebミドルウェアを捉え直す
pizzacat83
1
630
メールのエイリアス機能を履き違えない
isshinfunada
0
160
【やさしく解説 設計編・中級 #6】良いアーキテクチャとは ~ 一本の登り道の、行き先 ~
panda728
PRO
0
200
2年かけて Deno に DOMMatrix を実装した話 / How I implemented DOMMatrix in Deno over two years
petamoriken
0
190
自動化したのに回らないテスト運用の壁ーAI時代の品質責任と生産性
mfunaki
0
110
属人化した知識を、 AIが辿れる地図にする
pkshadeck
PRO
1
120
Google Apps Script で Ruby を動かす
kawahara
0
120
改善しないと、タスクが回らない。 “てんこ盛りポジション” を引き継いだ情シスの、入社3ヶ月の業務改善録
krm963
0
230
【SRE NEXT 2026 Lunch Session】一人目専任SREの立ち上げを加速する ― AIと進めたオンボーディングで2分を0.04秒にした話
pkshadeck
PRO
0
3.3k
JAWS-UG横浜 #102 AWSサ終供養LT会 成仏できない AWS サービスたち 〜本日、三体供養します〜
maroon1st
0
280
Welcome to the "Parametricity" 🏙️ − Generic だけど Specific な世界 −
guvalif
PRO
1
190
Build-to-own AI: Agentic Development for Humans
inesmontani
PRO
0
130
Featured
See All Featured
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
670
The Cost Of JavaScript in 2023
addyosmani
55
10k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
2.9k
Art, The Web, and Tiny UX
lynnandtonic
304
22k
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
440
Ten Tips & Tricks for a 🌱 transition
stuffmc
0
160
The Language of Interfaces
destraynor
162
27k
Designing Experiences People Love
moore
143
24k
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
440
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
330
A Tale of Four Properties
chriscoyier
163
24k
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
1.1k
Transcript
Livecoding in Javascript Jason Frame / @jaz303 Friday, 31 May
13
What is livecoding? By akirto. http://www.flickr.com/photos/30132612@N00/3840200923/in/photostream Friday, 31 May 13
Performance-Oriented Friday, 31 May 13
Node-based Friday, 31 May 13
Microworlds Paper - “Twenty Reasons Why You Should Use Boxer
(Instead of Logo)” Andrea A. diSessa Friday, 31 May 13
Smalltalk, Self Paper - “The Early History of Smalltalk” Alan
C. Kay Friday, 31 May 13
Why livecode? Friday, 31 May 13
Why Javascript? Friday, 31 May 13
Why Javascript? • Flexible language • Ecosystem - browser +
node.js = node- webkit • Single threaded • Event loop Friday, 31 May 13
Why Javascript? Describing Live programming using program transformations and a
callstack explicit interpreter Olov Johansson Friday, 31 May 13
Domain-Specific Livecoding • Generalised tools can be complex • May
also make unacceptable performance/ timing trade-offs • Evolve tools with your application Friday, 31 May 13
Demo Time Friday, 31 May 13
Friday, 31 May 13
Implementation Strategies Friday, 31 May 13
Implementation Strategies eval() is evil Friday, 31 May 13
Implementation Strategies eval() is evil Friday, 31 May 13
Implementation Strategies • Private State • Variable Injection • “Globals”
Preservation • Internal eval() • Blueprints • Snapshot • Clocksources Friday, 31 May 13
Private State Prevent pollution of global namespace Friday, 31 May
13
Private State function setup() { position = {x: 10, y:
20}; velocity = {x: 1, y: 1}; } function loop() { position.x += velocity.x; position.y += velocity.y; } Friday, 31 May 13
Private State (function() { “use strict”; var position; var velocity;
function setup() { position = {x: 10, y: 20}; velocity = {x: 1, y: 1}; } function loop() { position.x += velocity.x; position.y += velocity.y; } })(); Friday, 31 May 13
Private State (function() { “use strict”; var position; var velocity;
function setup() { position = {x: 10, y: 20}; velocity = {x: 1, y: 1}; } function loop() { position.x += velocity.x; position.y += velocity.y; } return { setup: setup, loop: loop }; })(); Friday, 31 May 13
Variable Injection Provide objects to user-code Friday, 31 May 13
Variable Injection function loop() { car.drawAt(0,0,50,50) } // ... //
... // ... Friday, 31 May 13
Variable Injection // Generate method signature from defined // objects
(function(car, trafficLights, background) { // Paste user code here function loop() { car.drawAt(0,0,50,50) } // ... // ... // ... }).apply(null, exposedObjects); Friday, 31 May 13
“Globals” Preservation Persist global values between code reloads Friday, 31
May 13
“Globals” Preservation var carX = 0; var carY = 0;
var speed = 5; function loop() { carY += speed; draw(); } Friday, 31 May 13
“Globals” Preservation var carX = 0; var carY = 0;
var speed = 5; function loop() { carY += speed; draw(); } Friday, 31 May 13
“Globals” Preservation (function() { "use strict"; var carX = 0;
var carY = 0; var speed = 5; function loop() { carY += speed; draw(); } return { loop: loop, getVars: function() { return {carX: carX, carY: carY, speed: speed}; }, setVars: function(vars) { carX = vars.carX; carY = vars.carY; speed = vars.speed; } }; })(); Friday, 31 May 13
Internal eval() Provide external (e.g. console) access to private state
Friday, 31 May 13
Internal eval() var car = {x: 20, y: 20} var
lightState = “red-amber” function setup() { // ... } function loop() { // ... } Friday, 31 May 13
Internal eval() (function() { "use strict"; var car = {x:
20, y: 20} var lightState = “red-amber” function setup() { // ... } function loop() { // ... } })(); Friday, 31 May 13
Internal eval() (function() { "use strict"; var car = {x:
20, y: 20} var lightState = “red-amber” function setup() { // ... } function loop() { // ... } function evaluate(code) { return eval(code); } return { __eval__: evaluate } })(); Friday, 31 May 13
Blueprints Augment a supplied object with user-code Friday, 31 May
13
Blueprints // Inside engine var blueprint = new SystemBlueprint(); blueprint.id
= oldSystem.id; blueprint.enabled = oldSystem.enabled; blueprint.update = function() { /* default impl */ } USERCODE = ‘(function(system) { // augment blueprint system.title = “foo”; system.update = function() { ... } })’; // Compile code systemBuilder = eval(USERCODE); systemBuilder(blueprint); // inspect user’s refinements to blueprint and // setup accordingly Friday, 31 May 13
Snapshots Save and restore entire application state Friday, 31 May
13
Snapshots system.snapshot = function() { return { entities: Object.keys(this.entities), lastShotTime:
this.lastShotTime } } system.restore = function(snapshot) { var self = this; this.entities = {}; snapshot.entities.forEach(function(eid) { self.entities[eid] = self.world.getEntityById(eid); } this.lastShotTime = snapshot.lastShotTime; } Friday, 31 May 13
Snapshots function updateSystem(registry, systemId, newSystem) { var existingSystem = registry.getSystemById(systemId);
var snapshot = existingSystem.snapshot(); try { newSystem.restore(snapshot); registry.setSystem(systemId, newSystem); } catch (e) { // Incompatible snapshot - restart app? } } Friday, 31 May 13
Clocksources Provide a consistent view of time when loading snapshots
Friday, 31 May 13
Clocksources Date.now() Friday, 31 May 13
Clocksources Date.now() function Clock() { this.time = 0; this.lastDelta =
null; } Clock.prototype.tick = function(delta) { this.time += delta; this.lastDelta = delta; } function tick() { var wallclockDelta = Date.now() - lastTick; clock.tick(wallclockDelta); } Friday, 31 May 13
Escaping the Walled Garden Friday, 31 May 13
Escaping the Walled Garden Friday, 31 May 13
Escaping the Walled Garden Friday, 31 May 13
Demo Time Friday, 31 May 13