SlideShare a Scribd company logo
Metaprogramming
with JavaScript
Timur Shemsedinov
Research Institute of System Technologies
What is Metaprogramming?
• Templates and macroses to generate source
code in compile-time
• Self-changing programs
• Programs that generate other programs
• other meanings ?
What is Metaprogramming?
1. This is not artificial intelligence.
2. Metaprogramming is not something new,
you've always used it.
3. In programming languages ​​of Von Neumann architecture
nothing happens without metadata (architecture in which
data and instructions are stored in shared memory and
computer needs to recognize numbers, strings, addresses,
executable instruction, etc.)
What is Metaprogramming?
Programming paradigm that implies program
structure and functionality modification
programmatically
How Metaprogramming works?
Programming paradigm that implies program
structure and functionality modification
programmatically
1. When changes occur?
2. What is changing?
3. Whereby changes occur?
How Metaprogramming works?
When changes occurs?
• Design-time
• Compile-time
• Run-time
• Just-in-Time (immediate when executing/processing)
• Lazy (between executing/processing)
• On Timer
• On Pull requests
• On Push notifications
How Metaprogramming works?
What is changing?
• data types and data structures
• identifiers (class names, type names, variable names)
• calls (method/function names, dynamic binding)
• algorithm parameters
• formula syntax, regular expression syntax, etc.
• dynamic code interpretation (eval)
• data serialization/deserialization
How Metaprogramming works?
Whereby changes occurs?
• Parsing and translation of syntactic structures
• Access to objects and functions by identification name
• Full introspection
• First-class objects individuation:
• functions, using closures
• classes, using inheritance (prototypes in js)
• objects, using mixins
The problem definition
Why do we need Metaprogramming?
• To raise functionality, universality and
abstraction level of software solutions
• Dynamic domains when changing functionality
and structure is a normal mode
• Intersystem/inter-module integration,
using introspection and dynamic binding
Example 1: data definition
var names = [
"Marcus Aurelius Antoninus Augustus",
"Darth Vader",
"Victor Michailovich Glushkov",
"Gottfried Wilhelm von Leibniz",
"Mao Zedong",
"Vladimir Sergeevich Soloviov",
"Ibn Arabi",
"Lev Nikolayevich Tolstoy",
"Muammar Muhammad Abu Minyar al-Gaddafi",
"Rene Descartes",
"Fyodor Mikhailovich Dostoyevsky",
"Benedito de Espinosa"
];
Example 1: solution (without metaprogramming)
function filter(names) {
var result = [], name;
for (var i=0; i<names.length; i++) {
name = names[i];
if ( name.length >= 10 && name.length <= 200 &&
name.indexOf("Mich") > -1 &&
name.indexOf("V") === 0 &&
name.slice(-2) == "ov" &&
!( name.length >= 50 && name.length <= 65 &&
name.indexOf("Abu") > -1 &&
name.indexOf("Lev") === 0 &&
name.slice(-3) == "iov")
) result.push(name);
}
return result;
}
Example 1: extracted metadata
var conditions = {
length: [10, 200],
contains: "Mich",
starts: "V",
ends: "ov",
not: {
length: [50, 65],
contains: "Abu",
starts: "Lev",
ends: "iov"
}
};
Example 1: metamodel
function filter(names, conditions) {
var operations = {
length: function(s,v) { return s.length>=v[0] && s.length<=v[1] },
contains: function(s,v) { return s.indexOf(v) > -1 },
starts: function(s,v) { return s.indexOf(v) === 0 },
ends: function(s,v) { return s.slice(-v.length) == v },
not: function(s,v) { return !check(s,v) }
};
function check(s, conditions) {
var valid = true;
for (var key in conditions)
valid &= operations[key](s, conditions[key]);
return valid;
}
return names.filter(function(s) { return check(s, conditions); });
}
Unified model for IS module
Example 2: task definition
var tasks = [
{ interval:5000, get:"http://127.0.0.1/api/method1.json",
expect:"OK", save:"file1.json" },
{ interval:"8s", get:"http://127.0.0.1/api/method2.json",
put:"http://127.0.0.1/api/method4.json", save:"file2.json" },
{ interval:"7s", get:"http://127.0.0.1/api/method3.json",
expect:"Done", post:"http://127.0.0.1/api/method5.json" },
{ interval:"4s", load:"file1.json",
expect:"OK", put:"http://127.0.0.1/api/method6.json" },
{ interval:"9s", load:"file2.json", save:"file1.json",
post:"http://127.0.0.1/api/method7.json" },
{ interval:"3s", load:"file1.json", save:"file3.json" },
];
Example 2: metamodel
function iterate(tasks) {
function closureTask(task) { return function () {
console.dir(task);
var source;
if (task.get) source = request.get(task.get);
if (task.load) source = fs.createReadStream(task.load);
if (task.save) source.pipe(fs.createWriteStream(task.save));
if (task.post) source.pipe(request.post(task.post));
if (task.put) source.pipe(request.put(task.put));
} };
for (var i=0; i<tasks.length; i++)
setInterval(closureTask(tasks[i]), duration(tasks[i].interval));
}
Example 2: metamodel (with internal configuration)
function iterate(tasks) {
var sources = { get: request.get,
load: fs.createReadStream };
var destinations = { save: fs.createWriteStream,
post: request.post,
put: request.put };
function closureTask(task) { return function () {
console.dir(task);
var verb, source, destination;
for (key in sources)
if (task[key]) source = sources[key](task[key]);
for (key in destinations)
if (task[key]) source.pipe(destinations[key](task[key]));
} };
for (var i=0; i<tasks.length; i++)
setInterval(closureTask(tasks[i]), duration(tasks[i].interval));
}
Example 3: interpretation
// Parse duration to seconds, example: duration("1d 10h 7m 13s")
function duration(s) {
var result = 0;
if (typeof(s) == 'string') {
var days = s.match(/(d+)s*d/),
hours = s.match(/(d+)s*h/),
minutes = s.match(/(d+)s*m/),
seconds = s.match(/(d+)s*s/);
if (days) result += parseInt(days[1])*86400;
if (hours) result += parseInt(hours[1])*3600;
if (minutes) result += parseInt(minutes[1])*60;
if (seconds) result += parseInt(seconds[1]);
result = result*1000;
} if (typeof(s) == 'number') result = s;
return result;
}
Example 3: interpretation (configurable)
function duration(s) {
if (typeof(s) == 'number') return s;
var units = {
days: { rx:/(d+)s*d/, mul:86400 },
hours: { rx:/(d+)s*h/, mul:3600 },
minutes: { rx:/(d+)s*m/, mul:60 },
seconds: { rx:/(d+)s*s/, mul:1 }
};
var result = 0, unit, match;
if (typeof(s) == 'string') for (var key in units) {
unit = units[key];
match = s.match(unit.rx);
if (match) result += parseInt(match[1])*unit.mul;
}
return result*1000;
}
Example 4: introspection in metaprogramming
Example 4: introspection
var ds = wcl.AjaxDataSource({
read: { get: "examples/person/read.json" },
insert: { post: "examples/person/insert.json" },
update: { post: "examples/person/update.json" },
delete: { post: "examples/person/delete.json" },
find: { post: "examples/person/find.json" },
metadata: { post: "examples/person/metadata.json" }
});
ds.read({ id:5 }, function(err, data) {
data.phone ="+0123456789";
ds.update(data, function(err) {
console.log('Data saved');
});
});
Example 4: introspection in metaprogramming
var ds = wcl.AjaxDataSource({
introspect: { post: "examples/person/introspect.json" }
});
ds.read({ id:3 }, function(err, data) {
data.phone ="+0123456789";
ds.update(data, function(err) {
console.log('Data saved');
});
});
Example 4: introspection in metaprogramming
var ds = wcl.MemoryDataSource({ data: [
{ id:1, name:"Person 1", phone:"+380501002011",
emails:[ "person1@domain.com" ], age: 25 },
{ id:2, name:"Person 2", phone:"+380501002022",
emails:[ "person2@domain.com", "person2@domain2.com" ],
address: { city: "Kiev", street:"Khreschatit", building: "26" } },
{ id:3, name:"Person 3", phone:"+380501002033",
emails:[ "person3@domain.com" ],
tags: [ {tag:"tag1", color:"red"}, {tag:"tag2", color:"green"} ] },
]});
ds.read({ id:3 }, function(err, data) {
data.phone ="+0123456789";
ds.update(data, function(err) {
console.log('Data saved');
});
});
Metaprogramming techniques
• Task definition style: declarative, using metadata,
imperative and functional elements
• Hashes (associative arrays)
beforehand unknown key: var a = {}; a[key] = value;
• String interpretation, inventing domain-specific syntactic
structures or using universal ones (json, js, regexp ...)
• Mixins: beforehand unknown targer object/class
function mixin(a) { a.fn=function(){ ... } }
• Closures: function individuations
fn = (function(a) { return function() { return a*2 } })(value)
The findings
• Code size: generally decrease a lot but may increases code size
in rare cases (compensated by code readability)
• Speed: slightly decreases but good implementation
may remain approximately the same speed
• Flexibility: solution becomes more abstract/universal
software application scope expands
• Integration: usually much simplified integration
and requires less code changes
• Working pleasure: metaprogramming is interesting
so we have more pleasure and motivation
• Working speed: increasing development time but modification and
support tasks take less time, so total time is less
Metaprogramming
with JavaScript
Github: https://github.com/tshemsedinov/metaprogramming
Article: http://habrahabr.ru/post/227753/
Metaprogramming
with JavaScript
Thank you!
Questions please
Timur Shemsedinov
Research Institute of System Technologies

More Related Content

What's hot (20)

NodeJS
NodeJSNodeJS
NodeJS
LinkMe Srl
 
Shared memory and multithreading in Node.js - Timur Shemsedinov - JSFest'19
Shared memory and multithreading in Node.js - Timur Shemsedinov - JSFest'19Shared memory and multithreading in Node.js - Timur Shemsedinov - JSFest'19
Shared memory and multithreading in Node.js - Timur Shemsedinov - JSFest'19
Timur Shemsedinov
 
A million connections and beyond - Node.js at scale
A million connections and beyond - Node.js at scaleA million connections and beyond - Node.js at scale
A million connections and beyond - Node.js at scale
Tom Croucher
 
Node.js
Node.jsNode.js
Node.js
Jan Dillmann
 
Node.js and How JavaScript is Changing Server Programming
Node.js and How JavaScript is Changing Server Programming  Node.js and How JavaScript is Changing Server Programming
Node.js and How JavaScript is Changing Server Programming
Tom Croucher
 
DEF CON 23 - amit ashbel and maty siman - game of hacks
DEF CON 23 - amit ashbel and maty siman - game of hacks DEF CON 23 - amit ashbel and maty siman - game of hacks
DEF CON 23 - amit ashbel and maty siman - game of hacks
Felipe Prado
 
Node js presentation
Node js presentationNode js presentation
Node js presentation
martincabrera
 
Node.js - Best practices
Node.js  - Best practicesNode.js  - Best practices
Node.js - Best practices
Felix Geisendörfer
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.js
orkaplan
 
Node ppt
Node pptNode ppt
Node ppt
Tamil Selvan R S
 
The Art of JVM Profiling
The Art of JVM ProfilingThe Art of JVM Profiling
The Art of JVM Profiling
Andrei Pangin
 
Индексируем базу: как делать хорошо и не делать плохо Winter saint p 2021 m...
Индексируем базу: как делать хорошо и не делать плохо   Winter saint p 2021 m...Индексируем базу: как делать хорошо и не делать плохо   Winter saint p 2021 m...
Индексируем базу: как делать хорошо и не делать плохо Winter saint p 2021 m...
Андрей Новиков
 
Node.js - A Quick Tour
Node.js - A Quick TourNode.js - A Quick Tour
Node.js - A Quick Tour
Felix Geisendörfer
 
03 standard class library
03 standard class library03 standard class library
03 standard class library
eleksdev
 
Building a real life application in node js
Building a real life application in node jsBuilding a real life application in node js
Building a real life application in node js
fakedarren
 
Multithreading in Node.js and JavaScript
Multithreading in Node.js and JavaScriptMultithreading in Node.js and JavaScript
Multithreading in Node.js and JavaScript
Timur Shemsedinov
 
MongoDB + node.js で作るソーシャルゲーム
MongoDB + node.js で作るソーシャルゲームMongoDB + node.js で作るソーシャルゲーム
MongoDB + node.js で作るソーシャルゲーム
Suguru Namura
 
MongoDB Performance Debugging
MongoDB Performance DebuggingMongoDB Performance Debugging
MongoDB Performance Debugging
MongoDB
 
Everything you wanted to know about Stack Traces and Heap Dumps
Everything you wanted to know about Stack Traces and Heap DumpsEverything you wanted to know about Stack Traces and Heap Dumps
Everything you wanted to know about Stack Traces and Heap Dumps
Andrei Pangin
 
Asynchronous I/O in NodeJS - new standard or challenges?
Asynchronous I/O in NodeJS - new standard or challenges?Asynchronous I/O in NodeJS - new standard or challenges?
Asynchronous I/O in NodeJS - new standard or challenges?
Dinh Pham
 
Shared memory and multithreading in Node.js - Timur Shemsedinov - JSFest'19
Shared memory and multithreading in Node.js - Timur Shemsedinov - JSFest'19Shared memory and multithreading in Node.js - Timur Shemsedinov - JSFest'19
Shared memory and multithreading in Node.js - Timur Shemsedinov - JSFest'19
Timur Shemsedinov
 
A million connections and beyond - Node.js at scale
A million connections and beyond - Node.js at scaleA million connections and beyond - Node.js at scale
A million connections and beyond - Node.js at scale
Tom Croucher
 
Node.js and How JavaScript is Changing Server Programming
Node.js and How JavaScript is Changing Server Programming  Node.js and How JavaScript is Changing Server Programming
Node.js and How JavaScript is Changing Server Programming
Tom Croucher
 
DEF CON 23 - amit ashbel and maty siman - game of hacks
DEF CON 23 - amit ashbel and maty siman - game of hacks DEF CON 23 - amit ashbel and maty siman - game of hacks
DEF CON 23 - amit ashbel and maty siman - game of hacks
Felipe Prado
 
Node js presentation
Node js presentationNode js presentation
Node js presentation
martincabrera
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.js
orkaplan
 
The Art of JVM Profiling
The Art of JVM ProfilingThe Art of JVM Profiling
The Art of JVM Profiling
Andrei Pangin
 
Индексируем базу: как делать хорошо и не делать плохо Winter saint p 2021 m...
Индексируем базу: как делать хорошо и не делать плохо   Winter saint p 2021 m...Индексируем базу: как делать хорошо и не делать плохо   Winter saint p 2021 m...
Индексируем базу: как делать хорошо и не делать плохо Winter saint p 2021 m...
Андрей Новиков
 
03 standard class library
03 standard class library03 standard class library
03 standard class library
eleksdev
 
Building a real life application in node js
Building a real life application in node jsBuilding a real life application in node js
Building a real life application in node js
fakedarren
 
Multithreading in Node.js and JavaScript
Multithreading in Node.js and JavaScriptMultithreading in Node.js and JavaScript
Multithreading in Node.js and JavaScript
Timur Shemsedinov
 
MongoDB + node.js で作るソーシャルゲーム
MongoDB + node.js で作るソーシャルゲームMongoDB + node.js で作るソーシャルゲーム
MongoDB + node.js で作るソーシャルゲーム
Suguru Namura
 
MongoDB Performance Debugging
MongoDB Performance DebuggingMongoDB Performance Debugging
MongoDB Performance Debugging
MongoDB
 
Everything you wanted to know about Stack Traces and Heap Dumps
Everything you wanted to know about Stack Traces and Heap DumpsEverything you wanted to know about Stack Traces and Heap Dumps
Everything you wanted to know about Stack Traces and Heap Dumps
Andrei Pangin
 
Asynchronous I/O in NodeJS - new standard or challenges?
Asynchronous I/O in NodeJS - new standard or challenges?Asynchronous I/O in NodeJS - new standard or challenges?
Asynchronous I/O in NodeJS - new standard or challenges?
Dinh Pham
 

Similar to Metaprogramming with JavaScript (20)

"Applied Enterprise Metaprogramming in JavaScript", Vladyslav Dukhin
"Applied Enterprise Metaprogramming in JavaScript", Vladyslav Dukhin"Applied Enterprise Metaprogramming in JavaScript", Vladyslav Dukhin
"Applied Enterprise Metaprogramming in JavaScript", Vladyslav Dukhin
Fwdays
 
Metaprogramming, Metaobject Protocols, Gradual Type Checks: Optimizing the "U...
Metaprogramming, Metaobject Protocols, Gradual Type Checks: Optimizing the "U...Metaprogramming, Metaobject Protocols, Gradual Type Checks: Optimizing the "U...
Metaprogramming, Metaobject Protocols, Gradual Type Checks: Optimizing the "U...
Stefan Marr
 
Metaprogramming by brandon
Metaprogramming by brandonMetaprogramming by brandon
Metaprogramming by brandon
MaslowB
 
TripCase Unit Testing with Jasmine
TripCase Unit Testing with JasmineTripCase Unit Testing with Jasmine
TripCase Unit Testing with Jasmine
Stephen Pond
 
Metaprogramming in ES6
Metaprogramming in ES6Metaprogramming in ES6
Metaprogramming in ES6
Héctor Pablos López
 
Metarhia KievJS 22-Feb-2018
Metarhia KievJS 22-Feb-2018Metarhia KievJS 22-Feb-2018
Metarhia KievJS 22-Feb-2018
Timur Shemsedinov
 
Rediscovering JavaScript: The Language Behind The Libraries
Rediscovering JavaScript: The Language Behind The LibrariesRediscovering JavaScript: The Language Behind The Libraries
Rediscovering JavaScript: The Language Behind The Libraries
Simon Willison
 
Exploring metaprogramming using Ruby language
Exploring metaprogramming using Ruby languageExploring metaprogramming using Ruby language
Exploring metaprogramming using Ruby language
Harshal Hayatnagarkar
 
Refactoring
RefactoringRefactoring
Refactoring
Amir Barylko
 
10 Ways To Improve Your Code( Neal Ford)
10  Ways To  Improve  Your  Code( Neal  Ford)10  Ways To  Improve  Your  Code( Neal  Ford)
10 Ways To Improve Your Code( Neal Ford)
guestebde
 
A Systematic Language Engineering Approach for Prototyping Domain Specific Mo...
A Systematic Language Engineering Approach for Prototyping Domain Specific Mo...A Systematic Language Engineering Approach for Prototyping Domain Specific Mo...
A Systematic Language Engineering Approach for Prototyping Domain Specific Mo...
Luis Pedro
 
ECMAScript 6 new features
ECMAScript 6 new featuresECMAScript 6 new features
ECMAScript 6 new features
GephenSG
 
Refactoring
RefactoringRefactoring
Refactoring
Amir Barylko
 
Testing Model Transformations
Testing Model TransformationsTesting Model Transformations
Testing Model Transformations
miso_uam
 
What’s new in ECMAScript 6.0
What’s new in ECMAScript 6.0What’s new in ECMAScript 6.0
What’s new in ECMAScript 6.0
Eyal Vardi
 
Rapid software evolution
Rapid software evolutionRapid software evolution
Rapid software evolution
borislav
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing Up
David Padbury
 
Monads and Monoids by Oleksiy Dyagilev
Monads and Monoids by Oleksiy DyagilevMonads and Monoids by Oleksiy Dyagilev
Monads and Monoids by Oleksiy Dyagilev
JavaDayUA
 
Semantic code transformations in MetaJS
Semantic code transformations in MetaJSSemantic code transformations in MetaJS
Semantic code transformations in MetaJS
Dmytro Dogadailo
 
Awesomeness of JavaScript…almost
Awesomeness of JavaScript…almostAwesomeness of JavaScript…almost
Awesomeness of JavaScript…almost
Quinton Sheppard
 
"Applied Enterprise Metaprogramming in JavaScript", Vladyslav Dukhin
"Applied Enterprise Metaprogramming in JavaScript", Vladyslav Dukhin"Applied Enterprise Metaprogramming in JavaScript", Vladyslav Dukhin
"Applied Enterprise Metaprogramming in JavaScript", Vladyslav Dukhin
Fwdays
 
Metaprogramming, Metaobject Protocols, Gradual Type Checks: Optimizing the "U...
Metaprogramming, Metaobject Protocols, Gradual Type Checks: Optimizing the "U...Metaprogramming, Metaobject Protocols, Gradual Type Checks: Optimizing the "U...
Metaprogramming, Metaobject Protocols, Gradual Type Checks: Optimizing the "U...
Stefan Marr
 
Metaprogramming by brandon
Metaprogramming by brandonMetaprogramming by brandon
Metaprogramming by brandon
MaslowB
 
TripCase Unit Testing with Jasmine
TripCase Unit Testing with JasmineTripCase Unit Testing with Jasmine
TripCase Unit Testing with Jasmine
Stephen Pond
 
Rediscovering JavaScript: The Language Behind The Libraries
Rediscovering JavaScript: The Language Behind The LibrariesRediscovering JavaScript: The Language Behind The Libraries
Rediscovering JavaScript: The Language Behind The Libraries
Simon Willison
 
Exploring metaprogramming using Ruby language
Exploring metaprogramming using Ruby languageExploring metaprogramming using Ruby language
Exploring metaprogramming using Ruby language
Harshal Hayatnagarkar
 
10 Ways To Improve Your Code( Neal Ford)
10  Ways To  Improve  Your  Code( Neal  Ford)10  Ways To  Improve  Your  Code( Neal  Ford)
10 Ways To Improve Your Code( Neal Ford)
guestebde
 
A Systematic Language Engineering Approach for Prototyping Domain Specific Mo...
A Systematic Language Engineering Approach for Prototyping Domain Specific Mo...A Systematic Language Engineering Approach for Prototyping Domain Specific Mo...
A Systematic Language Engineering Approach for Prototyping Domain Specific Mo...
Luis Pedro
 
ECMAScript 6 new features
ECMAScript 6 new featuresECMAScript 6 new features
ECMAScript 6 new features
GephenSG
 
Testing Model Transformations
Testing Model TransformationsTesting Model Transformations
Testing Model Transformations
miso_uam
 
What’s new in ECMAScript 6.0
What’s new in ECMAScript 6.0What’s new in ECMAScript 6.0
What’s new in ECMAScript 6.0
Eyal Vardi
 
Rapid software evolution
Rapid software evolutionRapid software evolution
Rapid software evolution
borislav
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing Up
David Padbury
 
Monads and Monoids by Oleksiy Dyagilev
Monads and Monoids by Oleksiy DyagilevMonads and Monoids by Oleksiy Dyagilev
Monads and Monoids by Oleksiy Dyagilev
JavaDayUA
 
Semantic code transformations in MetaJS
Semantic code transformations in MetaJSSemantic code transformations in MetaJS
Semantic code transformations in MetaJS
Dmytro Dogadailo
 
Awesomeness of JavaScript…almost
Awesomeness of JavaScript…almostAwesomeness of JavaScript…almost
Awesomeness of JavaScript…almost
Quinton Sheppard
 
Ad

More from Timur Shemsedinov (20)

How to use Chat GPT in JavaScript optimizations for Node.js
How to use Chat GPT in JavaScript optimizations for Node.jsHow to use Chat GPT in JavaScript optimizations for Node.js
How to use Chat GPT in JavaScript optimizations for Node.js
Timur Shemsedinov
 
IT Revolution in 2023-2024: AI, GPT, business transformation, future professi...
IT Revolution in 2023-2024: AI, GPT, business transformation, future professi...IT Revolution in 2023-2024: AI, GPT, business transformation, future professi...
IT Revolution in 2023-2024: AI, GPT, business transformation, future professi...
Timur Shemsedinov
 
Node.js threads for I/O-bound tasks
Node.js threads for I/O-bound tasksNode.js threads for I/O-bound tasks
Node.js threads for I/O-bound tasks
Timur Shemsedinov
 
Node.js Меньше сложности, больше надежности Holy.js 2021
Node.js Меньше сложности, больше надежности Holy.js 2021Node.js Меньше сложности, больше надежности Holy.js 2021
Node.js Меньше сложности, больше надежности Holy.js 2021
Timur Shemsedinov
 
Rethinking low-code
Rethinking low-codeRethinking low-code
Rethinking low-code
Timur Shemsedinov
 
Hat full of developers
Hat full of developersHat full of developers
Hat full of developers
Timur Shemsedinov
 
FwDays 2021: Metarhia Technology Stack for Node.js
FwDays 2021: Metarhia Technology Stack for Node.jsFwDays 2021: Metarhia Technology Stack for Node.js
FwDays 2021: Metarhia Technology Stack for Node.js
Timur Shemsedinov
 
Node.js for enterprise 2021 - JavaScript Fwdays 3
Node.js for enterprise 2021 - JavaScript Fwdays 3Node.js for enterprise 2021 - JavaScript Fwdays 3
Node.js for enterprise 2021 - JavaScript Fwdays 3
Timur Shemsedinov
 
Node.js in 2021
Node.js in 2021Node.js in 2021
Node.js in 2021
Timur Shemsedinov
 
Node.js middleware: Never again!
Node.js middleware: Never again!Node.js middleware: Never again!
Node.js middleware: Never again!
Timur Shemsedinov
 
Patterns and antipatterns
Patterns and antipatternsPatterns and antipatterns
Patterns and antipatterns
Timur Shemsedinov
 
Race-conditions-web-locks-and-shared-memory
Race-conditions-web-locks-and-shared-memoryRace-conditions-web-locks-and-shared-memory
Race-conditions-web-locks-and-shared-memory
Timur Shemsedinov
 
Asynchronous programming and mutlithreading
Asynchronous programming and mutlithreadingAsynchronous programming and mutlithreading
Asynchronous programming and mutlithreading
Timur Shemsedinov
 
Node.js in 2020 - part 3
Node.js in 2020 - part 3Node.js in 2020 - part 3
Node.js in 2020 - part 3
Timur Shemsedinov
 
Node.js in 2020 - part 2
Node.js in 2020 - part 2Node.js in 2020 - part 2
Node.js in 2020 - part 2
Timur Shemsedinov
 
Information system structure and architecture
Information system structure and architectureInformation system structure and architecture
Information system structure and architecture
Timur Shemsedinov
 
Node.js in 2020 - part 1
Node.js in 2020 - part 1Node.js in 2020 - part 1
Node.js in 2020 - part 1
Timur Shemsedinov
 
Web Locks API
Web Locks APIWeb Locks API
Web Locks API
Timur Shemsedinov
 
Node.js in 2020
Node.js in 2020Node.js in 2020
Node.js in 2020
Timur Shemsedinov
 
Введение в SQL
Введение в SQLВведение в SQL
Введение в SQL
Timur Shemsedinov
 
How to use Chat GPT in JavaScript optimizations for Node.js
How to use Chat GPT in JavaScript optimizations for Node.jsHow to use Chat GPT in JavaScript optimizations for Node.js
How to use Chat GPT in JavaScript optimizations for Node.js
Timur Shemsedinov
 
IT Revolution in 2023-2024: AI, GPT, business transformation, future professi...
IT Revolution in 2023-2024: AI, GPT, business transformation, future professi...IT Revolution in 2023-2024: AI, GPT, business transformation, future professi...
IT Revolution in 2023-2024: AI, GPT, business transformation, future professi...
Timur Shemsedinov
 
Node.js threads for I/O-bound tasks
Node.js threads for I/O-bound tasksNode.js threads for I/O-bound tasks
Node.js threads for I/O-bound tasks
Timur Shemsedinov
 
Node.js Меньше сложности, больше надежности Holy.js 2021
Node.js Меньше сложности, больше надежности Holy.js 2021Node.js Меньше сложности, больше надежности Holy.js 2021
Node.js Меньше сложности, больше надежности Holy.js 2021
Timur Shemsedinov
 
FwDays 2021: Metarhia Technology Stack for Node.js
FwDays 2021: Metarhia Technology Stack for Node.jsFwDays 2021: Metarhia Technology Stack for Node.js
FwDays 2021: Metarhia Technology Stack for Node.js
Timur Shemsedinov
 
Node.js for enterprise 2021 - JavaScript Fwdays 3
Node.js for enterprise 2021 - JavaScript Fwdays 3Node.js for enterprise 2021 - JavaScript Fwdays 3
Node.js for enterprise 2021 - JavaScript Fwdays 3
Timur Shemsedinov
 
Node.js middleware: Never again!
Node.js middleware: Never again!Node.js middleware: Never again!
Node.js middleware: Never again!
Timur Shemsedinov
 
Race-conditions-web-locks-and-shared-memory
Race-conditions-web-locks-and-shared-memoryRace-conditions-web-locks-and-shared-memory
Race-conditions-web-locks-and-shared-memory
Timur Shemsedinov
 
Asynchronous programming and mutlithreading
Asynchronous programming and mutlithreadingAsynchronous programming and mutlithreading
Asynchronous programming and mutlithreading
Timur Shemsedinov
 
Information system structure and architecture
Information system structure and architectureInformation system structure and architecture
Information system structure and architecture
Timur Shemsedinov
 
Ad

Recently uploaded (20)

Online Queue Management System for Public Service Offices [Focused on Municip...
Online Queue Management System for Public Service Offices [Focused on Municip...Online Queue Management System for Public Service Offices [Focused on Municip...
Online Queue Management System for Public Service Offices [Focused on Municip...
Rishab Acharya
 
UberEats clone app Development TechBuilder
UberEats clone app Development  TechBuilderUberEats clone app Development  TechBuilder
UberEats clone app Development TechBuilder
TechBuilder
 
Internship in South western railways on software
Internship in South western railways on softwareInternship in South western railways on software
Internship in South western railways on software
abhim5889
 
Feeling Lost in the Blue? Exploring a New Path: AI Mental Health Counselling ...
Feeling Lost in the Blue? Exploring a New Path: AI Mental Health Counselling ...Feeling Lost in the Blue? Exploring a New Path: AI Mental Health Counselling ...
Feeling Lost in the Blue? Exploring a New Path: AI Mental Health Counselling ...
officeiqai
 
AI-ASSISTED METAMORPHIC TESTING FOR DOMAIN-SPECIFIC MODELLING AND SIMULATION
AI-ASSISTED METAMORPHIC TESTING FOR DOMAIN-SPECIFIC MODELLING AND SIMULATIONAI-ASSISTED METAMORPHIC TESTING FOR DOMAIN-SPECIFIC MODELLING AND SIMULATION
AI-ASSISTED METAMORPHIC TESTING FOR DOMAIN-SPECIFIC MODELLING AND SIMULATION
miso_uam
 
Micro-Metrics Every Performance Engineer Should Validate Before Sign-Off
Micro-Metrics Every Performance Engineer Should Validate Before Sign-OffMicro-Metrics Every Performance Engineer Should Validate Before Sign-Off
Micro-Metrics Every Performance Engineer Should Validate Before Sign-Off
Tier1 app
 
Build enterprise-ready applications using skills you already have!
Build enterprise-ready applications using skills you already have!Build enterprise-ready applications using skills you already have!
Build enterprise-ready applications using skills you already have!
PhilMeredith3
 
How to Generate Financial Statements in QuickBooks Like a Pro (1).pdf
How to Generate Financial Statements in QuickBooks Like a Pro (1).pdfHow to Generate Financial Statements in QuickBooks Like a Pro (1).pdf
How to Generate Financial Statements in QuickBooks Like a Pro (1).pdf
QuickBooks Training
 
How John started to like TDD (instead of hating it) (ViennaJUG, June'25)
How John started to like TDD (instead of hating it) (ViennaJUG, June'25)How John started to like TDD (instead of hating it) (ViennaJUG, June'25)
How John started to like TDD (instead of hating it) (ViennaJUG, June'25)
Nacho Cougil
 
Boost Student Engagement with Smart Attendance Software for Schools
Boost Student Engagement with Smart Attendance Software for SchoolsBoost Student Engagement with Smart Attendance Software for Schools
Boost Student Engagement with Smart Attendance Software for Schools
Visitu
 
Software Risk and Quality management.pptx
Software Risk and Quality management.pptxSoftware Risk and Quality management.pptx
Software Risk and Quality management.pptx
HassanBangash9
 
Delivering More with Less: AI Driven Resource Management with OnePlan
Delivering More with Less: AI Driven Resource Management with OnePlan Delivering More with Less: AI Driven Resource Management with OnePlan
Delivering More with Less: AI Driven Resource Management with OnePlan
OnePlan Solutions
 
Risk Management in Software Projects: Identifying, Analyzing, and Controlling...
Risk Management in Software Projects: Identifying, Analyzing, and Controlling...Risk Management in Software Projects: Identifying, Analyzing, and Controlling...
Risk Management in Software Projects: Identifying, Analyzing, and Controlling...
gauravvmanchandaa200
 
Custom Software Development: Types, Applications and Benefits.pdf
Custom Software Development: Types, Applications and Benefits.pdfCustom Software Development: Types, Applications and Benefits.pdf
Custom Software Development: Types, Applications and Benefits.pdf
Digital Aptech
 
Optimising Claims Management with Claims Processing Systems
Optimising Claims Management with Claims Processing SystemsOptimising Claims Management with Claims Processing Systems
Optimising Claims Management with Claims Processing Systems
Insurance Tech Services
 
iOS Developer Resume 2025 | Pramod Kumar
iOS Developer Resume 2025 | Pramod KumariOS Developer Resume 2025 | Pramod Kumar
iOS Developer Resume 2025 | Pramod Kumar
Pramod Kumar
 
AI Alternative - Discover the best AI tools and their alternatives
AI Alternative - Discover the best AI tools and their alternativesAI Alternative - Discover the best AI tools and their alternatives
AI Alternative - Discover the best AI tools and their alternatives
AI Alternative
 
Oliveira2024 - Combining GPT and Weak Supervision.pdf
Oliveira2024 - Combining GPT and Weak Supervision.pdfOliveira2024 - Combining GPT and Weak Supervision.pdf
Oliveira2024 - Combining GPT and Weak Supervision.pdf
GiliardGodoi1
 
GirikHire Unlocking the Future of Tech Talent with AI-Powered Hiring Solution...
GirikHire Unlocking the Future of Tech Talent with AI-Powered Hiring Solution...GirikHire Unlocking the Future of Tech Talent with AI-Powered Hiring Solution...
GirikHire Unlocking the Future of Tech Talent with AI-Powered Hiring Solution...
GirikHire
 
aswjkdwelhjdfshlfjkhewljhfljawerhwjarhwjkahrjar
aswjkdwelhjdfshlfjkhewljhfljawerhwjarhwjkahrjaraswjkdwelhjdfshlfjkhewljhfljawerhwjarhwjkahrjar
aswjkdwelhjdfshlfjkhewljhfljawerhwjarhwjkahrjar
muhammadalikhanalikh1
 
Online Queue Management System for Public Service Offices [Focused on Municip...
Online Queue Management System for Public Service Offices [Focused on Municip...Online Queue Management System for Public Service Offices [Focused on Municip...
Online Queue Management System for Public Service Offices [Focused on Municip...
Rishab Acharya
 
UberEats clone app Development TechBuilder
UberEats clone app Development  TechBuilderUberEats clone app Development  TechBuilder
UberEats clone app Development TechBuilder
TechBuilder
 
Internship in South western railways on software
Internship in South western railways on softwareInternship in South western railways on software
Internship in South western railways on software
abhim5889
 
Feeling Lost in the Blue? Exploring a New Path: AI Mental Health Counselling ...
Feeling Lost in the Blue? Exploring a New Path: AI Mental Health Counselling ...Feeling Lost in the Blue? Exploring a New Path: AI Mental Health Counselling ...
Feeling Lost in the Blue? Exploring a New Path: AI Mental Health Counselling ...
officeiqai
 
AI-ASSISTED METAMORPHIC TESTING FOR DOMAIN-SPECIFIC MODELLING AND SIMULATION
AI-ASSISTED METAMORPHIC TESTING FOR DOMAIN-SPECIFIC MODELLING AND SIMULATIONAI-ASSISTED METAMORPHIC TESTING FOR DOMAIN-SPECIFIC MODELLING AND SIMULATION
AI-ASSISTED METAMORPHIC TESTING FOR DOMAIN-SPECIFIC MODELLING AND SIMULATION
miso_uam
 
Micro-Metrics Every Performance Engineer Should Validate Before Sign-Off
Micro-Metrics Every Performance Engineer Should Validate Before Sign-OffMicro-Metrics Every Performance Engineer Should Validate Before Sign-Off
Micro-Metrics Every Performance Engineer Should Validate Before Sign-Off
Tier1 app
 
Build enterprise-ready applications using skills you already have!
Build enterprise-ready applications using skills you already have!Build enterprise-ready applications using skills you already have!
Build enterprise-ready applications using skills you already have!
PhilMeredith3
 
How to Generate Financial Statements in QuickBooks Like a Pro (1).pdf
How to Generate Financial Statements in QuickBooks Like a Pro (1).pdfHow to Generate Financial Statements in QuickBooks Like a Pro (1).pdf
How to Generate Financial Statements in QuickBooks Like a Pro (1).pdf
QuickBooks Training
 
How John started to like TDD (instead of hating it) (ViennaJUG, June'25)
How John started to like TDD (instead of hating it) (ViennaJUG, June'25)How John started to like TDD (instead of hating it) (ViennaJUG, June'25)
How John started to like TDD (instead of hating it) (ViennaJUG, June'25)
Nacho Cougil
 
Boost Student Engagement with Smart Attendance Software for Schools
Boost Student Engagement with Smart Attendance Software for SchoolsBoost Student Engagement with Smart Attendance Software for Schools
Boost Student Engagement with Smart Attendance Software for Schools
Visitu
 
Software Risk and Quality management.pptx
Software Risk and Quality management.pptxSoftware Risk and Quality management.pptx
Software Risk and Quality management.pptx
HassanBangash9
 
Delivering More with Less: AI Driven Resource Management with OnePlan
Delivering More with Less: AI Driven Resource Management with OnePlan Delivering More with Less: AI Driven Resource Management with OnePlan
Delivering More with Less: AI Driven Resource Management with OnePlan
OnePlan Solutions
 
Risk Management in Software Projects: Identifying, Analyzing, and Controlling...
Risk Management in Software Projects: Identifying, Analyzing, and Controlling...Risk Management in Software Projects: Identifying, Analyzing, and Controlling...
Risk Management in Software Projects: Identifying, Analyzing, and Controlling...
gauravvmanchandaa200
 
Custom Software Development: Types, Applications and Benefits.pdf
Custom Software Development: Types, Applications and Benefits.pdfCustom Software Development: Types, Applications and Benefits.pdf
Custom Software Development: Types, Applications and Benefits.pdf
Digital Aptech
 
Optimising Claims Management with Claims Processing Systems
Optimising Claims Management with Claims Processing SystemsOptimising Claims Management with Claims Processing Systems
Optimising Claims Management with Claims Processing Systems
Insurance Tech Services
 
iOS Developer Resume 2025 | Pramod Kumar
iOS Developer Resume 2025 | Pramod KumariOS Developer Resume 2025 | Pramod Kumar
iOS Developer Resume 2025 | Pramod Kumar
Pramod Kumar
 
AI Alternative - Discover the best AI tools and their alternatives
AI Alternative - Discover the best AI tools and their alternativesAI Alternative - Discover the best AI tools and their alternatives
AI Alternative - Discover the best AI tools and their alternatives
AI Alternative
 
Oliveira2024 - Combining GPT and Weak Supervision.pdf
Oliveira2024 - Combining GPT and Weak Supervision.pdfOliveira2024 - Combining GPT and Weak Supervision.pdf
Oliveira2024 - Combining GPT and Weak Supervision.pdf
GiliardGodoi1
 
GirikHire Unlocking the Future of Tech Talent with AI-Powered Hiring Solution...
GirikHire Unlocking the Future of Tech Talent with AI-Powered Hiring Solution...GirikHire Unlocking the Future of Tech Talent with AI-Powered Hiring Solution...
GirikHire Unlocking the Future of Tech Talent with AI-Powered Hiring Solution...
GirikHire
 
aswjkdwelhjdfshlfjkhewljhfljawerhwjarhwjkahrjar
aswjkdwelhjdfshlfjkhewljhfljawerhwjarhwjkahrjaraswjkdwelhjdfshlfjkhewljhfljawerhwjarhwjkahrjar
aswjkdwelhjdfshlfjkhewljhfljawerhwjarhwjkahrjar
muhammadalikhanalikh1
 

Metaprogramming with JavaScript

  • 2. What is Metaprogramming? • Templates and macroses to generate source code in compile-time • Self-changing programs • Programs that generate other programs • other meanings ?
  • 3. What is Metaprogramming? 1. This is not artificial intelligence. 2. Metaprogramming is not something new, you've always used it. 3. In programming languages ​​of Von Neumann architecture nothing happens without metadata (architecture in which data and instructions are stored in shared memory and computer needs to recognize numbers, strings, addresses, executable instruction, etc.)
  • 4. What is Metaprogramming? Programming paradigm that implies program structure and functionality modification programmatically
  • 5. How Metaprogramming works? Programming paradigm that implies program structure and functionality modification programmatically 1. When changes occur? 2. What is changing? 3. Whereby changes occur?
  • 6. How Metaprogramming works? When changes occurs? • Design-time • Compile-time • Run-time • Just-in-Time (immediate when executing/processing) • Lazy (between executing/processing) • On Timer • On Pull requests • On Push notifications
  • 7. How Metaprogramming works? What is changing? • data types and data structures • identifiers (class names, type names, variable names) • calls (method/function names, dynamic binding) • algorithm parameters • formula syntax, regular expression syntax, etc. • dynamic code interpretation (eval) • data serialization/deserialization
  • 8. How Metaprogramming works? Whereby changes occurs? • Parsing and translation of syntactic structures • Access to objects and functions by identification name • Full introspection • First-class objects individuation: • functions, using closures • classes, using inheritance (prototypes in js) • objects, using mixins
  • 9. The problem definition Why do we need Metaprogramming? • To raise functionality, universality and abstraction level of software solutions • Dynamic domains when changing functionality and structure is a normal mode • Intersystem/inter-module integration, using introspection and dynamic binding
  • 10. Example 1: data definition var names = [ "Marcus Aurelius Antoninus Augustus", "Darth Vader", "Victor Michailovich Glushkov", "Gottfried Wilhelm von Leibniz", "Mao Zedong", "Vladimir Sergeevich Soloviov", "Ibn Arabi", "Lev Nikolayevich Tolstoy", "Muammar Muhammad Abu Minyar al-Gaddafi", "Rene Descartes", "Fyodor Mikhailovich Dostoyevsky", "Benedito de Espinosa" ];
  • 11. Example 1: solution (without metaprogramming) function filter(names) { var result = [], name; for (var i=0; i<names.length; i++) { name = names[i]; if ( name.length >= 10 && name.length <= 200 && name.indexOf("Mich") > -1 && name.indexOf("V") === 0 && name.slice(-2) == "ov" && !( name.length >= 50 && name.length <= 65 && name.indexOf("Abu") > -1 && name.indexOf("Lev") === 0 && name.slice(-3) == "iov") ) result.push(name); } return result; }
  • 12. Example 1: extracted metadata var conditions = { length: [10, 200], contains: "Mich", starts: "V", ends: "ov", not: { length: [50, 65], contains: "Abu", starts: "Lev", ends: "iov" } };
  • 13. Example 1: metamodel function filter(names, conditions) { var operations = { length: function(s,v) { return s.length>=v[0] && s.length<=v[1] }, contains: function(s,v) { return s.indexOf(v) > -1 }, starts: function(s,v) { return s.indexOf(v) === 0 }, ends: function(s,v) { return s.slice(-v.length) == v }, not: function(s,v) { return !check(s,v) } }; function check(s, conditions) { var valid = true; for (var key in conditions) valid &= operations[key](s, conditions[key]); return valid; } return names.filter(function(s) { return check(s, conditions); }); }
  • 14. Unified model for IS module
  • 15. Example 2: task definition var tasks = [ { interval:5000, get:"http://127.0.0.1/api/method1.json", expect:"OK", save:"file1.json" }, { interval:"8s", get:"http://127.0.0.1/api/method2.json", put:"http://127.0.0.1/api/method4.json", save:"file2.json" }, { interval:"7s", get:"http://127.0.0.1/api/method3.json", expect:"Done", post:"http://127.0.0.1/api/method5.json" }, { interval:"4s", load:"file1.json", expect:"OK", put:"http://127.0.0.1/api/method6.json" }, { interval:"9s", load:"file2.json", save:"file1.json", post:"http://127.0.0.1/api/method7.json" }, { interval:"3s", load:"file1.json", save:"file3.json" }, ];
  • 16. Example 2: metamodel function iterate(tasks) { function closureTask(task) { return function () { console.dir(task); var source; if (task.get) source = request.get(task.get); if (task.load) source = fs.createReadStream(task.load); if (task.save) source.pipe(fs.createWriteStream(task.save)); if (task.post) source.pipe(request.post(task.post)); if (task.put) source.pipe(request.put(task.put)); } }; for (var i=0; i<tasks.length; i++) setInterval(closureTask(tasks[i]), duration(tasks[i].interval)); }
  • 17. Example 2: metamodel (with internal configuration) function iterate(tasks) { var sources = { get: request.get, load: fs.createReadStream }; var destinations = { save: fs.createWriteStream, post: request.post, put: request.put }; function closureTask(task) { return function () { console.dir(task); var verb, source, destination; for (key in sources) if (task[key]) source = sources[key](task[key]); for (key in destinations) if (task[key]) source.pipe(destinations[key](task[key])); } }; for (var i=0; i<tasks.length; i++) setInterval(closureTask(tasks[i]), duration(tasks[i].interval)); }
  • 18. Example 3: interpretation // Parse duration to seconds, example: duration("1d 10h 7m 13s") function duration(s) { var result = 0; if (typeof(s) == 'string') { var days = s.match(/(d+)s*d/), hours = s.match(/(d+)s*h/), minutes = s.match(/(d+)s*m/), seconds = s.match(/(d+)s*s/); if (days) result += parseInt(days[1])*86400; if (hours) result += parseInt(hours[1])*3600; if (minutes) result += parseInt(minutes[1])*60; if (seconds) result += parseInt(seconds[1]); result = result*1000; } if (typeof(s) == 'number') result = s; return result; }
  • 19. Example 3: interpretation (configurable) function duration(s) { if (typeof(s) == 'number') return s; var units = { days: { rx:/(d+)s*d/, mul:86400 }, hours: { rx:/(d+)s*h/, mul:3600 }, minutes: { rx:/(d+)s*m/, mul:60 }, seconds: { rx:/(d+)s*s/, mul:1 } }; var result = 0, unit, match; if (typeof(s) == 'string') for (var key in units) { unit = units[key]; match = s.match(unit.rx); if (match) result += parseInt(match[1])*unit.mul; } return result*1000; }
  • 20. Example 4: introspection in metaprogramming
  • 21. Example 4: introspection var ds = wcl.AjaxDataSource({ read: { get: "examples/person/read.json" }, insert: { post: "examples/person/insert.json" }, update: { post: "examples/person/update.json" }, delete: { post: "examples/person/delete.json" }, find: { post: "examples/person/find.json" }, metadata: { post: "examples/person/metadata.json" } }); ds.read({ id:5 }, function(err, data) { data.phone ="+0123456789"; ds.update(data, function(err) { console.log('Data saved'); }); });
  • 22. Example 4: introspection in metaprogramming var ds = wcl.AjaxDataSource({ introspect: { post: "examples/person/introspect.json" } }); ds.read({ id:3 }, function(err, data) { data.phone ="+0123456789"; ds.update(data, function(err) { console.log('Data saved'); }); });
  • 23. Example 4: introspection in metaprogramming var ds = wcl.MemoryDataSource({ data: [ { id:1, name:"Person 1", phone:"+380501002011", emails:[ "[email protected]" ], age: 25 }, { id:2, name:"Person 2", phone:"+380501002022", emails:[ "[email protected]", "[email protected]" ], address: { city: "Kiev", street:"Khreschatit", building: "26" } }, { id:3, name:"Person 3", phone:"+380501002033", emails:[ "[email protected]" ], tags: [ {tag:"tag1", color:"red"}, {tag:"tag2", color:"green"} ] }, ]}); ds.read({ id:3 }, function(err, data) { data.phone ="+0123456789"; ds.update(data, function(err) { console.log('Data saved'); }); });
  • 24. Metaprogramming techniques • Task definition style: declarative, using metadata, imperative and functional elements • Hashes (associative arrays) beforehand unknown key: var a = {}; a[key] = value; • String interpretation, inventing domain-specific syntactic structures or using universal ones (json, js, regexp ...) • Mixins: beforehand unknown targer object/class function mixin(a) { a.fn=function(){ ... } } • Closures: function individuations fn = (function(a) { return function() { return a*2 } })(value)
  • 25. The findings • Code size: generally decrease a lot but may increases code size in rare cases (compensated by code readability) • Speed: slightly decreases but good implementation may remain approximately the same speed • Flexibility: solution becomes more abstract/universal software application scope expands • Integration: usually much simplified integration and requires less code changes • Working pleasure: metaprogramming is interesting so we have more pleasure and motivation • Working speed: increasing development time but modification and support tasks take less time, so total time is less
  • 27. Metaprogramming with JavaScript Thank you! Questions please Timur Shemsedinov Research Institute of System Technologies