SlideShare a Scribd company logo
The new wave of
JavaScript techniques
Practical pairing of generative programming
with functional programming
Eugene Lazutkin, ClubAjax, 6/4/2013
Wednesday, June 5, 13
Generative programming
Wednesday, June 5, 13
What is GP?
Generative programming (GP):
Creates source code automatically to improve
programmer productivity.
Can be considered as a form of code reuse.
Sometimes called “automatic programming”.
Wednesday, June 5, 13
Examples of GP
Macro processors:
C preprocessor.
C++ templates and inline functions.
IDE “wizards” in Eclipse, MS Visual Studio.
Meta-languages and their compilers.
Domain-specific languages (DSL).
Wednesday, June 5, 13
Why do we need GP?
Higher-level programming.
Meta-programming.
Modeling.
DSL.
Wednesday, June 5, 13
Why do we need GP?
Performance improvements.
Program transformations.
Data transformations.
Code optimization and generation.
Applies to both compilers and interpreters.
Wednesday, June 5, 13
Why do I need GP?
Common narrative goes like that:
“Compilers and interpreters are now very
sophisticated – no need to optimize my code.”
“Modern CPUs with their fancy pipelining,
parallel execution, and branch prediction
eliminate code inefficiencies.”
Wednesday, June 5, 13
Don’t write inefficient code
Always estimate the algorithmic complexity of
your code (Big O notation).
Remember simple things:
Linear code usually works faster than code
with branches or loops.
Calling a function is not free. If its body is
small, it may make sense to inline it.
Wednesday, June 5, 13
Don’t write inefficient code
Remember simple things:
Simplify!
Simple shorter code is usually faster.
Eliminate unnecessary variables.
Profile!!!
BTW, this was an advice by Jared Jurkiewicz.
Wednesday, June 5, 13
Performance summary
Do not expect that an inefficient code will be
magically efficient. Always profile!
In a battle of a code clarity with a code
efficiency support the clarity, if possible.
Avoid premature optimization by taking complex
steps, yet do not write obviously slow code.
Wednesday, June 5, 13
JavaScript and GP
People coming from static languages frequently
overlook or discount GP facilities in JS.
JS has four ways to generate code dynamically:
eval(), new Function(), setTimeout(),
setInterval().
Browser allows to inline code.
Wednesday, June 5, 13
JavaScript and GP
Amazing code-generation facilities are a big
differentiator for Javascript.
Yet they are frequently shunned for numerous
reasons, including security, which is not applied
in all scenarios.
Wednesday, June 5, 13
JavaScript and GP
Recently GP crept in JavaScript libraries.
Examples:
Many templating languages are actually
compiled in JavaScript or can be compiled:
Mustache, Handlebars, jQuery templates...
Wednesday, June 5, 13
JavaScript and GP
Examples:
All JavaScript-based templates:
EJS, JST (e.g., Underscore, Lo-Dash)...
All transpilers:
CoffeeScript, GWT, Emscripten...
Numerous code-level tools (minifiers...).
Wednesday, June 5, 13
JavaScript and GP
Examples:
Some libraries generate code for similar
functions from the same template in order to
reduce their downloadable size, and optimize
performance.
Lo-Dash...
Wednesday, June 5, 13
Functional programming
Wednesday, June 5, 13
What is FP?
Functional programming (FP):
Treats computations as the evaluation of
mathematical functions.
Avoids state, mutations, side-effects.
Emphasizes “scenario” over “a list of actors”.
Concerns more with “how” rather than
“who” and “what”.
Wednesday, June 5, 13
JavaScript and FP
“JavaScript is Lisp in C’s clothing.” – said
Douglas Crockford back in 2001.
Functions are first-class objects.
Lambdas are supported (functions can be
inlined, and passed around).
Closures are supported (functions can access
their environment).
Wednesday, June 5, 13
Practical applications of FP
Abstracting control flow details with array extras:
var total = data
.filter(function(value){ return value % 2; })
.map(function(value){ return value * value; })
.reduce(function(acc, value){
return acc + value;
}, 0);
Wednesday, June 5, 13
Practical applications of FP
We can even use “building blocks” now:
var total = data
.filter(isOdd)
.map(square)
.reduce(sum, 0);
Wednesday, June 5, 13
Why I like this code
It is easy to understand.
It is easy to decompose or refactor.
There is no trivial technical noise like names of
index and value variables, and exit conditions.
Wednesday, June 5, 13
Building blocks
In general we are assumed to create our
programs from right-sized building blocks.
Bigger blocks are built from smaller blocks with a
mortar/language.
It applies to any programming paradigms.
Wednesday, June 5, 13
...and reality
How come in real projects we see methods and
functions in 100s and even 1000s lines of code?
Sometimes there are “good” reasons for that.
It can take more time to figure out our
building blocks than to code everything from
scratch.
Wednesday, June 5, 13
...and more reality
Sometimes there are “good” reasons for that.
Calling myriad of small functions can be
detrimental to performance.
Is it really the case? It can be verified with a
profiler, which takes time too.
It is possible to create a different system of
“building blocks”.
Wednesday, June 5, 13
Case for pipes
Pipes are individual components of a pipeline.
Each pipe has an input and an output
(sometimes more than one of those).
Pipeline combines individual pipes by
connecting their inputs and outputs producing a
program.
A pipeline can be used as a pipe.
Wednesday, June 5, 13
Case for pipes
Unix shells are a classic examples of pipes.
Closely related concept: dataflow.
Complex applications frequently can be
expressed in terms of event flow.
Hot topics in JS: event streams, data streams.
Wednesday, June 5, 13
Pipes and chaining
While chaining is a frequent implementation
technique for pipes, it doesn’t mean that all
chaining equates to pipes.
Pipes encapsulate streams of data and
orchestrate processing of individual bits.
Frequently chaining operates in terms of
transferred objects (streams), not data bits.
Wednesday, June 5, 13
Chaining
Examples in JS of chaining without piping:
jQuery
Underscore
JavaScript array extras
All examples above create a container object
before passing it down.
Wednesday, June 5, 13
Theory and practice
Wednesday, June 5, 13
Can we do better?
Let’s use our simple example as a start point and
optimize it by inlining functions:
var total = data
.filter(function(value){ return value % 2; })
.map(function(value){ return value * value; })
.reduce(function(acc, value){
return acc + value;
}, 0);
Wednesday, June 5, 13
Can we do better?
var a1 = [];
for(var i = 0; i < data.length; ++i){
if(data[i] % 2) a1.push(data[i]);
}
var a2 = new Array(a1.length);
for(var i = 0; i < a1.length; ++i){
a2[i] = a1[i] * a1[i];
}
var acc = 0;
for(var i = 0; i < a2.length; ++i){
acc += a2[i];
}
var total = acc;
Wednesday, June 5, 13
Can we do better?
Let’s merge loops and eliminate intermediate
arrays:
var acc = 0;
for(var i = 0; i < data.length; ++i){
var value = data[i];
if(value % 2) acc += value * value;
}
var total = acc;
Wednesday, June 5, 13
Performance results
0 750 1500 2250 3000
ms
Manual (38ms) Extra (2885ms)
Wednesday, June 5, 13
We did better!
And the results are in:
It is faster.
We loop over values manually.
We cannot easily move this snippet around
because our technical variable names may
clash.
Ultimately it was a trade-off.
Wednesday, June 5, 13
Can we have our cake and eat it too?
Yes!
Wednesday, June 5, 13
Can we have our cake and eat it too?
We need a way to describe a result.
Not how exactly get it, but its logical inference.
Then we can apply GP to generate an optimal
code.
Wednesday, June 5, 13
FP and pipes
FP gives us some answers:
Iterations can be described by higher-order
operations:
map, filter, fold/reduce, zipping, unzipping,
partitioning.
Secondary: forEach, every, some, indexOf.
Wednesday, June 5, 13
Heya Pipe
Wednesday, June 5, 13
Heya: ctr and pipe
Heya is a library that provides a modern
foundation for building web applications (both
server and client).
Heya Pipe is a functional toolkit to build efficient
data and event processing pipes using GP.
Heya Ctr provides a constructor to build
generated components.
Wednesday, June 5, 13
The Heya way
Let’s use our simple example and optimize it with
Heya Pipe:
var total = data
.filter(function(value){ return value % 2; })
.map(function(value){ return value * value; })
.reduce(function(acc, value){
return acc + value;
}, 0);
Wednesday, June 5, 13
The Heya way
Here it is:
var f = array(new Pipe()
.filter(“value % 2”)
.map(“value *= value;”)
.fold(“accumulator += value;”, 0)
).compile();
var total = f(data);
Wednesday, June 5, 13
Performance results
0 750 1500 2250 3000
ms
Manual (38ms) Pipe (53ms) Extra (2885ms)
Wednesday, June 5, 13
What do we see?
We are as expressive as array extras.
We are as performant as manual code.
The performance gap can be reduced.
In any case pipes are >40x faster than array
extras.
Wednesday, June 5, 13
Heya Pipe conventions
Heya Pipe is modeled after array extras.
It can accept the same parameters.
If a string is specified instead of a function it is
assumed to be a code snippet.
Code snippets work by conventions.
Wednesday, June 5, 13
Heya Pipe conventions
Snippets can have several lines of code.
“Boolean” snippets assume that the last line
returns a boolean value.
Snippet’s input is a “value” variable. A snippet
can modify it to return a different value.
Snippets for fold-able operations can access and
update an “accumulator” variable.
Wednesday, June 5, 13
Debugging
People make mistakes ⇒ code should be
debugged.
How to debug a generated code?
What is Heya Pipe story here?
Wednesday, June 5, 13
Debugging
The screenshot shows node.js debugging with
node-inspector.
The generated code appears in the file panel.
The code is fully readable.
Wednesday, June 5, 13
Heya Pipe
Provides a rich foundation for pipes:
forEach, transform, map, filter, indexOf, every,
some, fold, scan, skip, take, skipWhile,
takeWhile, voidResult.
Can work with potentially infinite streams.
Wednesday, June 5, 13
Heya Pipe
Can iterate over numerous containers:
Array (sparse and dense, including in reverse),
array slices (including in reverse), Object (keys,
values, own and inherited), iterators,
enumerators, generators, and perform unfold.
Includes a compiler, and an interpreter.
Can use pipes as sub-pipes.
Wednesday, June 5, 13
Heya Ctr
Implements GP helpers.
Includes a simple formatting-aware
templating.
Allows managing closures.
Serves as a foundation for Heya Pipes.
Wednesday, June 5, 13
Closures with Heya Ctr
Allows to inject variables in a closure, which will
be directly accessible from snippets by name.
Does not use “with” statement because it is
incompatible with strict mode.
Fully strict mode compatible.
Allows to access and modify closure-bound
variables.
Wednesday, June 5, 13
!at’s all
Folks!
Wednesday, June 5, 13
Ad

More Related Content

What's hot (20)

Skiron - Experiments in CPU Design in D
Skiron - Experiments in CPU Design in DSkiron - Experiments in CPU Design in D
Skiron - Experiments in CPU Design in D
Mithun Hunsur
 
clWrap: Nonsense free control of your GPU
clWrap: Nonsense free control of your GPUclWrap: Nonsense free control of your GPU
clWrap: Nonsense free control of your GPU
John Colvin
 
C++ Coroutines
C++ CoroutinesC++ Coroutines
C++ Coroutines
Sumant Tambe
 
Best Practices in Qt Quick/QML - Part 3
Best Practices in Qt Quick/QML - Part 3Best Practices in Qt Quick/QML - Part 3
Best Practices in Qt Quick/QML - Part 3
ICS
 
Know yourengines velocity2011
Know yourengines velocity2011Know yourengines velocity2011
Know yourengines velocity2011
Demis Bellot
 
Optimizing Communicating Event-Loop Languages with Truffle
Optimizing Communicating Event-Loop Languages with TruffleOptimizing Communicating Event-Loop Languages with Truffle
Optimizing Communicating Event-Loop Languages with Truffle
Stefan Marr
 
Best Practices in Qt Quick/QML - Part 2
Best Practices in Qt Quick/QML - Part 2Best Practices in Qt Quick/QML - Part 2
Best Practices in Qt Quick/QML - Part 2
Janel Heilbrunn
 
Big-data-analysis-training-in-mumbai
Big-data-analysis-training-in-mumbaiBig-data-analysis-training-in-mumbai
Big-data-analysis-training-in-mumbai
Unmesh Baile
 
Qtp realtime scripts
Qtp realtime scriptsQtp realtime scripts
Qtp realtime scripts
Ramu Palanki
 
A Domain-Specific Embedded Language for Programming Parallel Architectures.
A Domain-Specific Embedded Language for Programming Parallel Architectures.A Domain-Specific Embedded Language for Programming Parallel Architectures.
A Domain-Specific Embedded Language for Programming Parallel Architectures.
Jason Hearne-McGuiness
 
Building High-Performance Language Implementations With Low Effort
Building High-Performance Language Implementations With Low EffortBuilding High-Performance Language Implementations With Low Effort
Building High-Performance Language Implementations With Low Effort
Stefan Marr
 
Zero-Overhead Metaprogramming: Reflection and Metaobject Protocols Fast and w...
Zero-Overhead Metaprogramming: Reflection and Metaobject Protocols Fast and w...Zero-Overhead Metaprogramming: Reflection and Metaobject Protocols Fast and w...
Zero-Overhead Metaprogramming: Reflection and Metaobject Protocols Fast and w...
Stefan Marr
 
Best Practices in Qt Quick/QML - Part III
Best Practices in Qt Quick/QML - Part IIIBest Practices in Qt Quick/QML - Part III
Best Practices in Qt Quick/QML - Part III
ICS
 
Reactive Programming for a demanding world: building event-driven and respons...
Reactive Programming for a demanding world: building event-driven and respons...Reactive Programming for a demanding world: building event-driven and respons...
Reactive Programming for a demanding world: building event-driven and respons...
Mario Fusco
 
Go Faster With Native Compilation
Go Faster With Native CompilationGo Faster With Native Compilation
Go Faster With Native Compilation
Rajeev Rastogi (KRR)
 
Дмитрий Копляров , Потокобезопасные сигналы в C++
Дмитрий Копляров , Потокобезопасные сигналы в C++Дмитрий Копляров , Потокобезопасные сигналы в C++
Дмитрий Копляров , Потокобезопасные сигналы в C++
Sergey Platonov
 
Pune-Cocoa: Blocks and GCD
Pune-Cocoa: Blocks and GCDPune-Cocoa: Blocks and GCD
Pune-Cocoa: Blocks and GCD
Prashant Rane
 
Comparing different concurrency models on the JVM
Comparing different concurrency models on the JVMComparing different concurrency models on the JVM
Comparing different concurrency models on the JVM
Mario Fusco
 
System verilog assertions
System verilog assertionsSystem verilog assertions
System verilog assertions
HARINATH REDDY
 
How and why I turned my old Java projects into a first-class serverless compo...
How and why I turned my old Java projects into a first-class serverless compo...How and why I turned my old Java projects into a first-class serverless compo...
How and why I turned my old Java projects into a first-class serverless compo...
Mario Fusco
 
Skiron - Experiments in CPU Design in D
Skiron - Experiments in CPU Design in DSkiron - Experiments in CPU Design in D
Skiron - Experiments in CPU Design in D
Mithun Hunsur
 
clWrap: Nonsense free control of your GPU
clWrap: Nonsense free control of your GPUclWrap: Nonsense free control of your GPU
clWrap: Nonsense free control of your GPU
John Colvin
 
Best Practices in Qt Quick/QML - Part 3
Best Practices in Qt Quick/QML - Part 3Best Practices in Qt Quick/QML - Part 3
Best Practices in Qt Quick/QML - Part 3
ICS
 
Know yourengines velocity2011
Know yourengines velocity2011Know yourengines velocity2011
Know yourengines velocity2011
Demis Bellot
 
Optimizing Communicating Event-Loop Languages with Truffle
Optimizing Communicating Event-Loop Languages with TruffleOptimizing Communicating Event-Loop Languages with Truffle
Optimizing Communicating Event-Loop Languages with Truffle
Stefan Marr
 
Best Practices in Qt Quick/QML - Part 2
Best Practices in Qt Quick/QML - Part 2Best Practices in Qt Quick/QML - Part 2
Best Practices in Qt Quick/QML - Part 2
Janel Heilbrunn
 
Big-data-analysis-training-in-mumbai
Big-data-analysis-training-in-mumbaiBig-data-analysis-training-in-mumbai
Big-data-analysis-training-in-mumbai
Unmesh Baile
 
Qtp realtime scripts
Qtp realtime scriptsQtp realtime scripts
Qtp realtime scripts
Ramu Palanki
 
A Domain-Specific Embedded Language for Programming Parallel Architectures.
A Domain-Specific Embedded Language for Programming Parallel Architectures.A Domain-Specific Embedded Language for Programming Parallel Architectures.
A Domain-Specific Embedded Language for Programming Parallel Architectures.
Jason Hearne-McGuiness
 
Building High-Performance Language Implementations With Low Effort
Building High-Performance Language Implementations With Low EffortBuilding High-Performance Language Implementations With Low Effort
Building High-Performance Language Implementations With Low Effort
Stefan Marr
 
Zero-Overhead Metaprogramming: Reflection and Metaobject Protocols Fast and w...
Zero-Overhead Metaprogramming: Reflection and Metaobject Protocols Fast and w...Zero-Overhead Metaprogramming: Reflection and Metaobject Protocols Fast and w...
Zero-Overhead Metaprogramming: Reflection and Metaobject Protocols Fast and w...
Stefan Marr
 
Best Practices in Qt Quick/QML - Part III
Best Practices in Qt Quick/QML - Part IIIBest Practices in Qt Quick/QML - Part III
Best Practices in Qt Quick/QML - Part III
ICS
 
Reactive Programming for a demanding world: building event-driven and respons...
Reactive Programming for a demanding world: building event-driven and respons...Reactive Programming for a demanding world: building event-driven and respons...
Reactive Programming for a demanding world: building event-driven and respons...
Mario Fusco
 
Дмитрий Копляров , Потокобезопасные сигналы в C++
Дмитрий Копляров , Потокобезопасные сигналы в C++Дмитрий Копляров , Потокобезопасные сигналы в C++
Дмитрий Копляров , Потокобезопасные сигналы в C++
Sergey Platonov
 
Pune-Cocoa: Blocks and GCD
Pune-Cocoa: Blocks and GCDPune-Cocoa: Blocks and GCD
Pune-Cocoa: Blocks and GCD
Prashant Rane
 
Comparing different concurrency models on the JVM
Comparing different concurrency models on the JVMComparing different concurrency models on the JVM
Comparing different concurrency models on the JVM
Mario Fusco
 
System verilog assertions
System verilog assertionsSystem verilog assertions
System verilog assertions
HARINATH REDDY
 
How and why I turned my old Java projects into a first-class serverless compo...
How and why I turned my old Java projects into a first-class serverless compo...How and why I turned my old Java projects into a first-class serverless compo...
How and why I turned my old Java projects into a first-class serverless compo...
Mario Fusco
 

Viewers also liked (16)

Dojo GFX: SVG in the real world
Dojo GFX: SVG in the real worldDojo GFX: SVG in the real world
Dojo GFX: SVG in the real world
Eugene Lazutkin
 
Exciting JavaScript - Part II
Exciting JavaScript - Part IIExciting JavaScript - Part II
Exciting JavaScript - Part II
Eugene Lazutkin
 
Exciting JavaScript - Part I
Exciting JavaScript - Part IExciting JavaScript - Part I
Exciting JavaScript - Part I
Eugene Lazutkin
 
Seeking Enligtenment - A journey of purpose rather tan instruction
Seeking Enligtenment - A journey of purpose rather tan instructionSeeking Enligtenment - A journey of purpose rather tan instruction
Seeking Enligtenment - A journey of purpose rather tan instruction
Schalk Cronjé
 
Generative programming (mostly parser generation)
Generative programming (mostly parser generation)Generative programming (mostly parser generation)
Generative programming (mostly parser generation)
Ralf Laemmel
 
Practical Meta Programming
Practical Meta ProgrammingPractical Meta Programming
Practical Meta Programming
Reggie Meisler
 
Generative Software Development. Overview and Examples
Generative Software Development. Overview and ExamplesGenerative Software Development. Overview and Examples
Generative Software Development. Overview and Examples
Eelco Visser
 
A Generative Programming Approach to Developing Pervasive Computing Systems
A Generative Programming Approach to Developing Pervasive Computing SystemsA Generative Programming Approach to Developing Pervasive Computing Systems
A Generative Programming Approach to Developing Pervasive Computing Systems
Damien Cassou
 
Generative and Meta-Programming - Modern C++ Design for Parallel Computing
Generative and Meta-Programming - Modern C++ Design for Parallel ComputingGenerative and Meta-Programming - Modern C++ Design for Parallel Computing
Generative and Meta-Programming - Modern C++ Design for Parallel Computing
Joel Falcou
 
Japanese Open and Generative Design
Japanese Open and Generative DesignJapanese Open and Generative Design
Japanese Open and Generative Design
Yuichi Yazaki
 
Seri Belajar Mandiri - Pemrograman C# Untuk Pemula
Seri Belajar Mandiri - Pemrograman C# Untuk PemulaSeri Belajar Mandiri - Pemrograman C# Untuk Pemula
Seri Belajar Mandiri - Pemrograman C# Untuk Pemula
Agus Kurniawan
 
Probabilistic programming
Probabilistic programmingProbabilistic programming
Probabilistic programming
Eli Gottlieb
 
Summary - Transformational-Generative Theory
Summary - Transformational-Generative TheorySummary - Transformational-Generative Theory
Summary - Transformational-Generative Theory
Marielis VI
 
Transformational-Generative Grammar
Transformational-Generative GrammarTransformational-Generative Grammar
Transformational-Generative Grammar
Ruth Ann Llego
 
Deep structure and surface structure
Deep structure and surface structureDeep structure and surface structure
Deep structure and surface structure
Asif Ali Raza
 
Ubiquitous Computing
Ubiquitous ComputingUbiquitous Computing
Ubiquitous Computing
u065932
 
Dojo GFX: SVG in the real world
Dojo GFX: SVG in the real worldDojo GFX: SVG in the real world
Dojo GFX: SVG in the real world
Eugene Lazutkin
 
Exciting JavaScript - Part II
Exciting JavaScript - Part IIExciting JavaScript - Part II
Exciting JavaScript - Part II
Eugene Lazutkin
 
Exciting JavaScript - Part I
Exciting JavaScript - Part IExciting JavaScript - Part I
Exciting JavaScript - Part I
Eugene Lazutkin
 
Seeking Enligtenment - A journey of purpose rather tan instruction
Seeking Enligtenment - A journey of purpose rather tan instructionSeeking Enligtenment - A journey of purpose rather tan instruction
Seeking Enligtenment - A journey of purpose rather tan instruction
Schalk Cronjé
 
Generative programming (mostly parser generation)
Generative programming (mostly parser generation)Generative programming (mostly parser generation)
Generative programming (mostly parser generation)
Ralf Laemmel
 
Practical Meta Programming
Practical Meta ProgrammingPractical Meta Programming
Practical Meta Programming
Reggie Meisler
 
Generative Software Development. Overview and Examples
Generative Software Development. Overview and ExamplesGenerative Software Development. Overview and Examples
Generative Software Development. Overview and Examples
Eelco Visser
 
A Generative Programming Approach to Developing Pervasive Computing Systems
A Generative Programming Approach to Developing Pervasive Computing SystemsA Generative Programming Approach to Developing Pervasive Computing Systems
A Generative Programming Approach to Developing Pervasive Computing Systems
Damien Cassou
 
Generative and Meta-Programming - Modern C++ Design for Parallel Computing
Generative and Meta-Programming - Modern C++ Design for Parallel ComputingGenerative and Meta-Programming - Modern C++ Design for Parallel Computing
Generative and Meta-Programming - Modern C++ Design for Parallel Computing
Joel Falcou
 
Japanese Open and Generative Design
Japanese Open and Generative DesignJapanese Open and Generative Design
Japanese Open and Generative Design
Yuichi Yazaki
 
Seri Belajar Mandiri - Pemrograman C# Untuk Pemula
Seri Belajar Mandiri - Pemrograman C# Untuk PemulaSeri Belajar Mandiri - Pemrograman C# Untuk Pemula
Seri Belajar Mandiri - Pemrograman C# Untuk Pemula
Agus Kurniawan
 
Probabilistic programming
Probabilistic programmingProbabilistic programming
Probabilistic programming
Eli Gottlieb
 
Summary - Transformational-Generative Theory
Summary - Transformational-Generative TheorySummary - Transformational-Generative Theory
Summary - Transformational-Generative Theory
Marielis VI
 
Transformational-Generative Grammar
Transformational-Generative GrammarTransformational-Generative Grammar
Transformational-Generative Grammar
Ruth Ann Llego
 
Deep structure and surface structure
Deep structure and surface structureDeep structure and surface structure
Deep structure and surface structure
Asif Ali Raza
 
Ubiquitous Computing
Ubiquitous ComputingUbiquitous Computing
Ubiquitous Computing
u065932
 
Ad

Similar to Practical pairing of generative programming with functional programming. (20)

Questions On The Code And Core Module
Questions On The Code And Core ModuleQuestions On The Code And Core Module
Questions On The Code And Core Module
Katie Gulley
 
Pattern: PMML for Cascading and Hadoop
Pattern: PMML for Cascading and HadoopPattern: PMML for Cascading and Hadoop
Pattern: PMML for Cascading and Hadoop
Paco Nathan
 
Art & music vs Google App Engine
Art & music vs Google App EngineArt & music vs Google App Engine
Art & music vs Google App Engine
thomas alisi
 
Lambdas puzzler - Peter Lawrey
Lambdas puzzler - Peter LawreyLambdas puzzler - Peter Lawrey
Lambdas puzzler - Peter Lawrey
JAXLondon_Conference
 
r,rstats,r language,r packages
r,rstats,r language,r packagesr,rstats,r language,r packages
r,rstats,r language,r packages
Ajay Ohri
 
Google Interview Questions By Scholarhat
Google Interview Questions By ScholarhatGoogle Interview Questions By Scholarhat
Google Interview Questions By Scholarhat
Scholarhat
 
Pivotal Data Labs - Technology and Tools in our Data Scientist's Arsenal
Pivotal Data Labs - Technology and Tools in our Data Scientist's Arsenal Pivotal Data Labs - Technology and Tools in our Data Scientist's Arsenal
Pivotal Data Labs - Technology and Tools in our Data Scientist's Arsenal
Srivatsan Ramanujam
 
Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008
Guillaume Laforge
 
Performance modeling and simulation for accumulo applications
Performance modeling and simulation for accumulo applicationsPerformance modeling and simulation for accumulo applications
Performance modeling and simulation for accumulo applications
Accumulo Summit
 
Cloudera Data Science Challenge
Cloudera Data Science ChallengeCloudera Data Science Challenge
Cloudera Data Science Challenge
Mark Nichols, P.E.
 
Data Science Challenge presentation given to the CinBITools Meetup Group
Data Science Challenge presentation given to the CinBITools Meetup GroupData Science Challenge presentation given to the CinBITools Meetup Group
Data Science Challenge presentation given to the CinBITools Meetup Group
Doug Needham
 
Lone StarPHP 2013 - Building Web Apps from a New Angle
Lone StarPHP 2013 - Building Web Apps from a New AngleLone StarPHP 2013 - Building Web Apps from a New Angle
Lone StarPHP 2013 - Building Web Apps from a New Angle
Pablo Godel
 
Elasticsearch's aggregations &amp; esctl in action or how i built a cli tool...
Elasticsearch's aggregations &amp; esctl in action  or how i built a cli tool...Elasticsearch's aggregations &amp; esctl in action  or how i built a cli tool...
Elasticsearch's aggregations &amp; esctl in action or how i built a cli tool...
FaithWestdorp
 
Exploring SharePoint with F#
Exploring SharePoint with F#Exploring SharePoint with F#
Exploring SharePoint with F#
Talbott Crowell
 
Easy R
Easy REasy R
Easy R
Ajay Ohri
 
Google App Engine for Java
Google App Engine for JavaGoogle App Engine for Java
Google App Engine for Java
Lars Vogel
 
02 c++g3 d (1)
02 c++g3 d (1)02 c++g3 d (1)
02 c++g3 d (1)
Mohammed Ali
 
ES6 detailed slides for presentation.pptx
ES6 detailed slides for presentation.pptxES6 detailed slides for presentation.pptx
ES6 detailed slides for presentation.pptx
AneesLarik1
 
Scalding for Hadoop
Scalding for HadoopScalding for Hadoop
Scalding for Hadoop
Chicago Hadoop Users Group
 
10 things I’ve learnt In the clouds
10 things I’ve learnt In the clouds10 things I’ve learnt In the clouds
10 things I’ve learnt In the clouds
Stuart Lodge
 
Questions On The Code And Core Module
Questions On The Code And Core ModuleQuestions On The Code And Core Module
Questions On The Code And Core Module
Katie Gulley
 
Pattern: PMML for Cascading and Hadoop
Pattern: PMML for Cascading and HadoopPattern: PMML for Cascading and Hadoop
Pattern: PMML for Cascading and Hadoop
Paco Nathan
 
Art & music vs Google App Engine
Art & music vs Google App EngineArt & music vs Google App Engine
Art & music vs Google App Engine
thomas alisi
 
r,rstats,r language,r packages
r,rstats,r language,r packagesr,rstats,r language,r packages
r,rstats,r language,r packages
Ajay Ohri
 
Google Interview Questions By Scholarhat
Google Interview Questions By ScholarhatGoogle Interview Questions By Scholarhat
Google Interview Questions By Scholarhat
Scholarhat
 
Pivotal Data Labs - Technology and Tools in our Data Scientist's Arsenal
Pivotal Data Labs - Technology and Tools in our Data Scientist's Arsenal Pivotal Data Labs - Technology and Tools in our Data Scientist's Arsenal
Pivotal Data Labs - Technology and Tools in our Data Scientist's Arsenal
Srivatsan Ramanujam
 
Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008
Guillaume Laforge
 
Performance modeling and simulation for accumulo applications
Performance modeling and simulation for accumulo applicationsPerformance modeling and simulation for accumulo applications
Performance modeling and simulation for accumulo applications
Accumulo Summit
 
Cloudera Data Science Challenge
Cloudera Data Science ChallengeCloudera Data Science Challenge
Cloudera Data Science Challenge
Mark Nichols, P.E.
 
Data Science Challenge presentation given to the CinBITools Meetup Group
Data Science Challenge presentation given to the CinBITools Meetup GroupData Science Challenge presentation given to the CinBITools Meetup Group
Data Science Challenge presentation given to the CinBITools Meetup Group
Doug Needham
 
Lone StarPHP 2013 - Building Web Apps from a New Angle
Lone StarPHP 2013 - Building Web Apps from a New AngleLone StarPHP 2013 - Building Web Apps from a New Angle
Lone StarPHP 2013 - Building Web Apps from a New Angle
Pablo Godel
 
Elasticsearch's aggregations &amp; esctl in action or how i built a cli tool...
Elasticsearch's aggregations &amp; esctl in action  or how i built a cli tool...Elasticsearch's aggregations &amp; esctl in action  or how i built a cli tool...
Elasticsearch's aggregations &amp; esctl in action or how i built a cli tool...
FaithWestdorp
 
Exploring SharePoint with F#
Exploring SharePoint with F#Exploring SharePoint with F#
Exploring SharePoint with F#
Talbott Crowell
 
Google App Engine for Java
Google App Engine for JavaGoogle App Engine for Java
Google App Engine for Java
Lars Vogel
 
ES6 detailed slides for presentation.pptx
ES6 detailed slides for presentation.pptxES6 detailed slides for presentation.pptx
ES6 detailed slides for presentation.pptx
AneesLarik1
 
10 things I’ve learnt In the clouds
10 things I’ve learnt In the clouds10 things I’ve learnt In the clouds
10 things I’ve learnt In the clouds
Stuart Lodge
 
Ad

More from Eugene Lazutkin (16)

Service workers
Service workersService workers
Service workers
Eugene Lazutkin
 
Advanced I/O in browser
Advanced I/O in browserAdvanced I/O in browser
Advanced I/O in browser
Eugene Lazutkin
 
Functional practices in JavaScript
Functional practices in JavaScriptFunctional practices in JavaScript
Functional practices in JavaScript
Eugene Lazutkin
 
Express: the web server for node.js
Express: the web server for node.jsExpress: the web server for node.js
Express: the web server for node.js
Eugene Lazutkin
 
TXJS 2013 in 10 minutes
TXJS 2013 in 10 minutesTXJS 2013 in 10 minutes
TXJS 2013 in 10 minutes
Eugene Lazutkin
 
Optimization of modern web applications
Optimization of modern web applicationsOptimization of modern web applications
Optimization of modern web applications
Eugene Lazutkin
 
OOP in JS
OOP in JSOOP in JS
OOP in JS
Eugene Lazutkin
 
Pulsar
PulsarPulsar
Pulsar
Eugene Lazutkin
 
SSJS, NoSQL, GAE and AppengineJS
SSJS, NoSQL, GAE and AppengineJSSSJS, NoSQL, GAE and AppengineJS
SSJS, NoSQL, GAE and AppengineJS
Eugene Lazutkin
 
Dojo for programmers (TXJS 2010)
Dojo for programmers (TXJS 2010)Dojo for programmers (TXJS 2010)
Dojo for programmers (TXJS 2010)
Eugene Lazutkin
 
RAD CRUD
RAD CRUDRAD CRUD
RAD CRUD
Eugene Lazutkin
 
CRUD with Dojo
CRUD with DojoCRUD with Dojo
CRUD with Dojo
Eugene Lazutkin
 
Dojo GFX workshop slides
Dojo GFX workshop slidesDojo GFX workshop slides
Dojo GFX workshop slides
Eugene Lazutkin
 
Dojo (QCon 2007 Slides)
Dojo (QCon 2007 Slides)Dojo (QCon 2007 Slides)
Dojo (QCon 2007 Slides)
Eugene Lazutkin
 
DojoX GFX Session Eugene Lazutkin SVG Open 2007
DojoX GFX Session Eugene Lazutkin SVG Open 2007DojoX GFX Session Eugene Lazutkin SVG Open 2007
DojoX GFX Session Eugene Lazutkin SVG Open 2007
Eugene Lazutkin
 
DojoX GFX Keynote Eugene Lazutkin SVG Open 2007
DojoX GFX Keynote Eugene Lazutkin SVG Open 2007DojoX GFX Keynote Eugene Lazutkin SVG Open 2007
DojoX GFX Keynote Eugene Lazutkin SVG Open 2007
Eugene Lazutkin
 
Functional practices in JavaScript
Functional practices in JavaScriptFunctional practices in JavaScript
Functional practices in JavaScript
Eugene Lazutkin
 
Express: the web server for node.js
Express: the web server for node.jsExpress: the web server for node.js
Express: the web server for node.js
Eugene Lazutkin
 
Optimization of modern web applications
Optimization of modern web applicationsOptimization of modern web applications
Optimization of modern web applications
Eugene Lazutkin
 
SSJS, NoSQL, GAE and AppengineJS
SSJS, NoSQL, GAE and AppengineJSSSJS, NoSQL, GAE and AppengineJS
SSJS, NoSQL, GAE and AppengineJS
Eugene Lazutkin
 
Dojo for programmers (TXJS 2010)
Dojo for programmers (TXJS 2010)Dojo for programmers (TXJS 2010)
Dojo for programmers (TXJS 2010)
Eugene Lazutkin
 
Dojo GFX workshop slides
Dojo GFX workshop slidesDojo GFX workshop slides
Dojo GFX workshop slides
Eugene Lazutkin
 
DojoX GFX Session Eugene Lazutkin SVG Open 2007
DojoX GFX Session Eugene Lazutkin SVG Open 2007DojoX GFX Session Eugene Lazutkin SVG Open 2007
DojoX GFX Session Eugene Lazutkin SVG Open 2007
Eugene Lazutkin
 
DojoX GFX Keynote Eugene Lazutkin SVG Open 2007
DojoX GFX Keynote Eugene Lazutkin SVG Open 2007DojoX GFX Keynote Eugene Lazutkin SVG Open 2007
DojoX GFX Keynote Eugene Lazutkin SVG Open 2007
Eugene Lazutkin
 

Recently uploaded (20)

#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 

Practical pairing of generative programming with functional programming.

  • 1. The new wave of JavaScript techniques Practical pairing of generative programming with functional programming Eugene Lazutkin, ClubAjax, 6/4/2013 Wednesday, June 5, 13
  • 3. What is GP? Generative programming (GP): Creates source code automatically to improve programmer productivity. Can be considered as a form of code reuse. Sometimes called “automatic programming”. Wednesday, June 5, 13
  • 4. Examples of GP Macro processors: C preprocessor. C++ templates and inline functions. IDE “wizards” in Eclipse, MS Visual Studio. Meta-languages and their compilers. Domain-specific languages (DSL). Wednesday, June 5, 13
  • 5. Why do we need GP? Higher-level programming. Meta-programming. Modeling. DSL. Wednesday, June 5, 13
  • 6. Why do we need GP? Performance improvements. Program transformations. Data transformations. Code optimization and generation. Applies to both compilers and interpreters. Wednesday, June 5, 13
  • 7. Why do I need GP? Common narrative goes like that: “Compilers and interpreters are now very sophisticated – no need to optimize my code.” “Modern CPUs with their fancy pipelining, parallel execution, and branch prediction eliminate code inefficiencies.” Wednesday, June 5, 13
  • 8. Don’t write inefficient code Always estimate the algorithmic complexity of your code (Big O notation). Remember simple things: Linear code usually works faster than code with branches or loops. Calling a function is not free. If its body is small, it may make sense to inline it. Wednesday, June 5, 13
  • 9. Don’t write inefficient code Remember simple things: Simplify! Simple shorter code is usually faster. Eliminate unnecessary variables. Profile!!! BTW, this was an advice by Jared Jurkiewicz. Wednesday, June 5, 13
  • 10. Performance summary Do not expect that an inefficient code will be magically efficient. Always profile! In a battle of a code clarity with a code efficiency support the clarity, if possible. Avoid premature optimization by taking complex steps, yet do not write obviously slow code. Wednesday, June 5, 13
  • 11. JavaScript and GP People coming from static languages frequently overlook or discount GP facilities in JS. JS has four ways to generate code dynamically: eval(), new Function(), setTimeout(), setInterval(). Browser allows to inline code. Wednesday, June 5, 13
  • 12. JavaScript and GP Amazing code-generation facilities are a big differentiator for Javascript. Yet they are frequently shunned for numerous reasons, including security, which is not applied in all scenarios. Wednesday, June 5, 13
  • 13. JavaScript and GP Recently GP crept in JavaScript libraries. Examples: Many templating languages are actually compiled in JavaScript or can be compiled: Mustache, Handlebars, jQuery templates... Wednesday, June 5, 13
  • 14. JavaScript and GP Examples: All JavaScript-based templates: EJS, JST (e.g., Underscore, Lo-Dash)... All transpilers: CoffeeScript, GWT, Emscripten... Numerous code-level tools (minifiers...). Wednesday, June 5, 13
  • 15. JavaScript and GP Examples: Some libraries generate code for similar functions from the same template in order to reduce their downloadable size, and optimize performance. Lo-Dash... Wednesday, June 5, 13
  • 17. What is FP? Functional programming (FP): Treats computations as the evaluation of mathematical functions. Avoids state, mutations, side-effects. Emphasizes “scenario” over “a list of actors”. Concerns more with “how” rather than “who” and “what”. Wednesday, June 5, 13
  • 18. JavaScript and FP “JavaScript is Lisp in C’s clothing.” – said Douglas Crockford back in 2001. Functions are first-class objects. Lambdas are supported (functions can be inlined, and passed around). Closures are supported (functions can access their environment). Wednesday, June 5, 13
  • 19. Practical applications of FP Abstracting control flow details with array extras: var total = data .filter(function(value){ return value % 2; }) .map(function(value){ return value * value; }) .reduce(function(acc, value){ return acc + value; }, 0); Wednesday, June 5, 13
  • 20. Practical applications of FP We can even use “building blocks” now: var total = data .filter(isOdd) .map(square) .reduce(sum, 0); Wednesday, June 5, 13
  • 21. Why I like this code It is easy to understand. It is easy to decompose or refactor. There is no trivial technical noise like names of index and value variables, and exit conditions. Wednesday, June 5, 13
  • 22. Building blocks In general we are assumed to create our programs from right-sized building blocks. Bigger blocks are built from smaller blocks with a mortar/language. It applies to any programming paradigms. Wednesday, June 5, 13
  • 23. ...and reality How come in real projects we see methods and functions in 100s and even 1000s lines of code? Sometimes there are “good” reasons for that. It can take more time to figure out our building blocks than to code everything from scratch. Wednesday, June 5, 13
  • 24. ...and more reality Sometimes there are “good” reasons for that. Calling myriad of small functions can be detrimental to performance. Is it really the case? It can be verified with a profiler, which takes time too. It is possible to create a different system of “building blocks”. Wednesday, June 5, 13
  • 25. Case for pipes Pipes are individual components of a pipeline. Each pipe has an input and an output (sometimes more than one of those). Pipeline combines individual pipes by connecting their inputs and outputs producing a program. A pipeline can be used as a pipe. Wednesday, June 5, 13
  • 26. Case for pipes Unix shells are a classic examples of pipes. Closely related concept: dataflow. Complex applications frequently can be expressed in terms of event flow. Hot topics in JS: event streams, data streams. Wednesday, June 5, 13
  • 27. Pipes and chaining While chaining is a frequent implementation technique for pipes, it doesn’t mean that all chaining equates to pipes. Pipes encapsulate streams of data and orchestrate processing of individual bits. Frequently chaining operates in terms of transferred objects (streams), not data bits. Wednesday, June 5, 13
  • 28. Chaining Examples in JS of chaining without piping: jQuery Underscore JavaScript array extras All examples above create a container object before passing it down. Wednesday, June 5, 13
  • 30. Can we do better? Let’s use our simple example as a start point and optimize it by inlining functions: var total = data .filter(function(value){ return value % 2; }) .map(function(value){ return value * value; }) .reduce(function(acc, value){ return acc + value; }, 0); Wednesday, June 5, 13
  • 31. Can we do better? var a1 = []; for(var i = 0; i < data.length; ++i){ if(data[i] % 2) a1.push(data[i]); } var a2 = new Array(a1.length); for(var i = 0; i < a1.length; ++i){ a2[i] = a1[i] * a1[i]; } var acc = 0; for(var i = 0; i < a2.length; ++i){ acc += a2[i]; } var total = acc; Wednesday, June 5, 13
  • 32. Can we do better? Let’s merge loops and eliminate intermediate arrays: var acc = 0; for(var i = 0; i < data.length; ++i){ var value = data[i]; if(value % 2) acc += value * value; } var total = acc; Wednesday, June 5, 13
  • 33. Performance results 0 750 1500 2250 3000 ms Manual (38ms) Extra (2885ms) Wednesday, June 5, 13
  • 34. We did better! And the results are in: It is faster. We loop over values manually. We cannot easily move this snippet around because our technical variable names may clash. Ultimately it was a trade-off. Wednesday, June 5, 13
  • 35. Can we have our cake and eat it too? Yes! Wednesday, June 5, 13
  • 36. Can we have our cake and eat it too? We need a way to describe a result. Not how exactly get it, but its logical inference. Then we can apply GP to generate an optimal code. Wednesday, June 5, 13
  • 37. FP and pipes FP gives us some answers: Iterations can be described by higher-order operations: map, filter, fold/reduce, zipping, unzipping, partitioning. Secondary: forEach, every, some, indexOf. Wednesday, June 5, 13
  • 39. Heya: ctr and pipe Heya is a library that provides a modern foundation for building web applications (both server and client). Heya Pipe is a functional toolkit to build efficient data and event processing pipes using GP. Heya Ctr provides a constructor to build generated components. Wednesday, June 5, 13
  • 40. The Heya way Let’s use our simple example and optimize it with Heya Pipe: var total = data .filter(function(value){ return value % 2; }) .map(function(value){ return value * value; }) .reduce(function(acc, value){ return acc + value; }, 0); Wednesday, June 5, 13
  • 41. The Heya way Here it is: var f = array(new Pipe() .filter(“value % 2”) .map(“value *= value;”) .fold(“accumulator += value;”, 0) ).compile(); var total = f(data); Wednesday, June 5, 13
  • 42. Performance results 0 750 1500 2250 3000 ms Manual (38ms) Pipe (53ms) Extra (2885ms) Wednesday, June 5, 13
  • 43. What do we see? We are as expressive as array extras. We are as performant as manual code. The performance gap can be reduced. In any case pipes are >40x faster than array extras. Wednesday, June 5, 13
  • 44. Heya Pipe conventions Heya Pipe is modeled after array extras. It can accept the same parameters. If a string is specified instead of a function it is assumed to be a code snippet. Code snippets work by conventions. Wednesday, June 5, 13
  • 45. Heya Pipe conventions Snippets can have several lines of code. “Boolean” snippets assume that the last line returns a boolean value. Snippet’s input is a “value” variable. A snippet can modify it to return a different value. Snippets for fold-able operations can access and update an “accumulator” variable. Wednesday, June 5, 13
  • 46. Debugging People make mistakes ⇒ code should be debugged. How to debug a generated code? What is Heya Pipe story here? Wednesday, June 5, 13
  • 47. Debugging The screenshot shows node.js debugging with node-inspector. The generated code appears in the file panel. The code is fully readable. Wednesday, June 5, 13
  • 48. Heya Pipe Provides a rich foundation for pipes: forEach, transform, map, filter, indexOf, every, some, fold, scan, skip, take, skipWhile, takeWhile, voidResult. Can work with potentially infinite streams. Wednesday, June 5, 13
  • 49. Heya Pipe Can iterate over numerous containers: Array (sparse and dense, including in reverse), array slices (including in reverse), Object (keys, values, own and inherited), iterators, enumerators, generators, and perform unfold. Includes a compiler, and an interpreter. Can use pipes as sub-pipes. Wednesday, June 5, 13
  • 50. Heya Ctr Implements GP helpers. Includes a simple formatting-aware templating. Allows managing closures. Serves as a foundation for Heya Pipes. Wednesday, June 5, 13
  • 51. Closures with Heya Ctr Allows to inject variables in a closure, which will be directly accessible from snippets by name. Does not use “with” statement because it is incompatible with strict mode. Fully strict mode compatible. Allows to access and modify closure-bound variables. Wednesday, June 5, 13