SlideShare a Scribd company logo
How to learn how to design
your functions
KaunasJS, Žygimantas Benetis <2018>
Outline
- Semantic design
- Monoids
- How to learn how to design your functions
- Programming languages and learning
- Summary
CV
Žygimantas Benetis
Software Engineer @ iGeolise <Scala, Frontend>
Coding since 2008
Studying data engineering/science
Code “design”
- What does it mean for code to be “good”?
- What does it mean for abstractions to not leak?
Code “design”
- What does it mean for code to be “good”?
- What does it mean for abstractions to not leak?
- To be composable?
Code “design”
- What does it mean for code to be “good”?
- What does it mean for abstractions to not leak?
- To be composable?
- Good code will let you build complex objects from simpler ones
Exercise: Define image (from Luke Palmer blog)
1. A rectangular array of colors (for a suitable definition of color);
2. A function taking a pair of real numbers and returning a possibly transparent
color;
3. A list of colored geometric primitives (polygons, lines, circles), where objects
later in the list are shown on top of objects earlier;
4. Any object with a draw method (our formalization of this very
software-oriented concept was a function from screens to screens)
Exercise: compose image
A straightforward composition operation on images is to put one on top of another.
Imagine what that would look like for each of the semantic domains:
1. The resulting image at coordinate (x,y) is an appropriate blend of the bottom
image at (x,y) and the top image at (x,y).
2. Same as above, except x and y are real numbers.
3. The resulting image is the bottom image concatenated with the top image.
4. The resulting image’s draw() method is { bottom.draw(); top.draw(); }.
Exercise: translate image
1. The pixel at (x,y) in the resulting image is a blend of the pixels around
(x-tx,y-ty) (if we can translate by non-integral amounts) if it is in the array’s
range. If not, it’s transparent. (Eliminate)
2. The resulting image at coordinate (x,y) is the original at coordinate (x+tx,
y+ty).
3. Translate each of the primitives in the list by (tx,ty).
4. Unclear how to define translation in this domain!
- It is not considered a bad start to start with const image = { draw: function() { } }
- Possible to extend with translate: function() {}
- Eliminate for not being as simple as possible
Exercise: image scaling
- For number 3 we need to consider what kind of primitive we have to scale
- For number 2 - its just (x, y) -> (x/s, y/s)
Summary for image exercise
- Function taking real numbers could doesn’t know about pixels
- Lots of “power” to library user
- Not always the best solution - sometimes restriction/less exposure is needed
Monoids
- Algebra which has identity element for specific associative operator
- Boolean: &&, true
- Addition: +, 0 {1 + 0 = 1, 10 + 0 = 10}
- Multiplication: *, 1 {7 * 1 = 7, 1337 * 1 = 1337}
- Associativity: {1 + 4 = 4 + 1, true && false = false && true}
- They are everywhere! (money summation, access rights to files, 2D shapes)
Monoids #2 from deque.blog
- Why them? They let you build complex behavior out of simple elements
without introducing new things
- Monoids can be chained indefinitely without introducing new types: 1+1+1+1..
- Associativity abstracts away the details of construction (1+1+3 != 1+3+1)
- Associativity lets you compute construction separately (parallel)
- If somebody else sees them - they will know how they behave
In JS: https://github.com/fantasyland/fantasy-land#monoid
How to learn to do better code design
- Using libraries without documentation [Less popular]
- Meaning of every word [Bentley]
- Relationships vs code [Linus and TinyLab]
- "Bad programmers worry about the code. Good programmers worry about data structures and
their relationships." - Linus Torvalds
Programming languages and learning
- Initial D
- Discovered vs Invented [Philip Wadler]
- Scala, Haskell, Elm, Clojure,...
- Javascript
Summary
- Thinking and considering semantic model before jumping into code
- Discovered is better than invented (abstract algebra and types)
- Choose tools which will teach you to be better
[AD] Looking for colleague to do frontend
● Decent HTML, CSS and Javascript experience
● Experience with functional programming or Scala
● Understanding of basic UI/UX design principles
● React knowledge is a huge plus
● Experience of working in Scrum/Agile environment is a plus
● Salary up to 42k per year
Q & A
References
- https://deque.blog/2017/09/13/monoids-what-they-are-why-they-are-useful-an
d-what-they-teach-us-about-software/
- https://lukepalmer.wordpress.com/2008/07/18/semantic-design/
- Book I told you about -
https://www.manning.com/books/functional-and-reactive-domain-modeling

More Related Content

PDF
Blockchain Technology - Week 6 - Role of Cryptography in Blockchain
PDF
E018212935
PPTX
2 Years of Real World FP at REA
PPTX
Security Operations, Engineering, and Intelligence Integration through the po...
PPTX
Class[3][5th jun] [three js]
PDF
Criticalthinking
PDF
detailed experience
PDF
Data Science - Part XVII - Deep Learning & Image Processing
Blockchain Technology - Week 6 - Role of Cryptography in Blockchain
E018212935
2 Years of Real World FP at REA
Security Operations, Engineering, and Intelligence Integration through the po...
Class[3][5th jun] [three js]
Criticalthinking
detailed experience
Data Science - Part XVII - Deep Learning & Image Processing

Similar to How to learn how to design your functions - Žygimantas Benetis (20)

PDF
Map your Mind, Your mind on a paper
PPT
lecture1hhhhhhhhhhhhhhhhhhhhhhhhhhhhh.ppt
PPT
lecture33333333333333333333333333331.ppt
PDF
Computer investigatroy project c++ class 12
PDF
R programmingmilano
PPT
Design Patterns By Sisimon Soman
PDF
Illogical engineers
PDF
Illogical engineers
PPTX
Python: Migrating from Procedural to Object-Oriented Programming
PPTX
AI On Your Phone: CoreML and Tensorflow Lite
PPT
Being Professional
PDF
Show and Tell_ A Neural Image Caption Generator.pdf
PPTX
Dip day1&2
PPTX
Android and Deep Learning
PDF
Sessisgytcfgggggggggggggggggggggggggggggggg
PDF
Computer_Science_Sr.Sec_2021-22.pdf
PDF
Effective Object Oriented Design in Cpp
PPT
Introduction to Machine Vision
PPTX
Introduction to Deep Learning and Tensorflow
PDF
ELAVARASAN.pdf
Map your Mind, Your mind on a paper
lecture1hhhhhhhhhhhhhhhhhhhhhhhhhhhhh.ppt
lecture33333333333333333333333333331.ppt
Computer investigatroy project c++ class 12
R programmingmilano
Design Patterns By Sisimon Soman
Illogical engineers
Illogical engineers
Python: Migrating from Procedural to Object-Oriented Programming
AI On Your Phone: CoreML and Tensorflow Lite
Being Professional
Show and Tell_ A Neural Image Caption Generator.pdf
Dip day1&2
Android and Deep Learning
Sessisgytcfgggggggggggggggggggggggggggggggg
Computer_Science_Sr.Sec_2021-22.pdf
Effective Object Oriented Design in Cpp
Introduction to Machine Vision
Introduction to Deep Learning and Tensorflow
ELAVARASAN.pdf
Ad

Recently uploaded (20)

PDF
cuic standard and advanced reporting.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Encapsulation theory and applications.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
Cloud computing and distributed systems.
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Empathic Computing: Creating Shared Understanding
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Electronic commerce courselecture one. Pdf
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
KodekX | Application Modernization Development
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Programs and apps: productivity, graphics, security and other tools
cuic standard and advanced reporting.pdf
20250228 LYD VKU AI Blended-Learning.pptx
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Encapsulation theory and applications.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Cloud computing and distributed systems.
MIND Revenue Release Quarter 2 2025 Press Release
Empathic Computing: Creating Shared Understanding
Digital-Transformation-Roadmap-for-Companies.pptx
MYSQL Presentation for SQL database connectivity
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Electronic commerce courselecture one. Pdf
NewMind AI Weekly Chronicles - August'25 Week I
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
KodekX | Application Modernization Development
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Dropbox Q2 2025 Financial Results & Investor Presentation
Network Security Unit 5.pdf for BCA BBA.
Programs and apps: productivity, graphics, security and other tools
Ad

How to learn how to design your functions - Žygimantas Benetis

  • 1. How to learn how to design your functions KaunasJS, Žygimantas Benetis <2018>
  • 2. Outline - Semantic design - Monoids - How to learn how to design your functions - Programming languages and learning - Summary
  • 3. CV Žygimantas Benetis Software Engineer @ iGeolise <Scala, Frontend> Coding since 2008 Studying data engineering/science
  • 4. Code “design” - What does it mean for code to be “good”? - What does it mean for abstractions to not leak?
  • 5. Code “design” - What does it mean for code to be “good”? - What does it mean for abstractions to not leak? - To be composable?
  • 6. Code “design” - What does it mean for code to be “good”? - What does it mean for abstractions to not leak? - To be composable? - Good code will let you build complex objects from simpler ones
  • 7. Exercise: Define image (from Luke Palmer blog) 1. A rectangular array of colors (for a suitable definition of color); 2. A function taking a pair of real numbers and returning a possibly transparent color; 3. A list of colored geometric primitives (polygons, lines, circles), where objects later in the list are shown on top of objects earlier; 4. Any object with a draw method (our formalization of this very software-oriented concept was a function from screens to screens)
  • 8. Exercise: compose image A straightforward composition operation on images is to put one on top of another. Imagine what that would look like for each of the semantic domains: 1. The resulting image at coordinate (x,y) is an appropriate blend of the bottom image at (x,y) and the top image at (x,y). 2. Same as above, except x and y are real numbers. 3. The resulting image is the bottom image concatenated with the top image. 4. The resulting image’s draw() method is { bottom.draw(); top.draw(); }.
  • 9. Exercise: translate image 1. The pixel at (x,y) in the resulting image is a blend of the pixels around (x-tx,y-ty) (if we can translate by non-integral amounts) if it is in the array’s range. If not, it’s transparent. (Eliminate) 2. The resulting image at coordinate (x,y) is the original at coordinate (x+tx, y+ty). 3. Translate each of the primitives in the list by (tx,ty). 4. Unclear how to define translation in this domain! - It is not considered a bad start to start with const image = { draw: function() { } } - Possible to extend with translate: function() {} - Eliminate for not being as simple as possible
  • 10. Exercise: image scaling - For number 3 we need to consider what kind of primitive we have to scale - For number 2 - its just (x, y) -> (x/s, y/s)
  • 11. Summary for image exercise - Function taking real numbers could doesn’t know about pixels - Lots of “power” to library user - Not always the best solution - sometimes restriction/less exposure is needed
  • 12. Monoids - Algebra which has identity element for specific associative operator - Boolean: &&, true - Addition: +, 0 {1 + 0 = 1, 10 + 0 = 10} - Multiplication: *, 1 {7 * 1 = 7, 1337 * 1 = 1337} - Associativity: {1 + 4 = 4 + 1, true && false = false && true} - They are everywhere! (money summation, access rights to files, 2D shapes)
  • 13. Monoids #2 from deque.blog - Why them? They let you build complex behavior out of simple elements without introducing new things - Monoids can be chained indefinitely without introducing new types: 1+1+1+1.. - Associativity abstracts away the details of construction (1+1+3 != 1+3+1) - Associativity lets you compute construction separately (parallel) - If somebody else sees them - they will know how they behave In JS: https://github.com/fantasyland/fantasy-land#monoid
  • 14. How to learn to do better code design - Using libraries without documentation [Less popular] - Meaning of every word [Bentley] - Relationships vs code [Linus and TinyLab] - "Bad programmers worry about the code. Good programmers worry about data structures and their relationships." - Linus Torvalds
  • 15. Programming languages and learning - Initial D - Discovered vs Invented [Philip Wadler] - Scala, Haskell, Elm, Clojure,... - Javascript
  • 16. Summary - Thinking and considering semantic model before jumping into code - Discovered is better than invented (abstract algebra and types) - Choose tools which will teach you to be better
  • 17. [AD] Looking for colleague to do frontend ● Decent HTML, CSS and Javascript experience ● Experience with functional programming or Scala ● Understanding of basic UI/UX design principles ● React knowledge is a huge plus ● Experience of working in Scrum/Agile environment is a plus ● Salary up to 42k per year
  • 18. Q & A