Tuesday, December 19, 2017

Object Functional Programming

Object functional programming can be considered as a mix of object oriented programming and functional programming. While standard OOPS approach will focus on objects, and standard functional programming function will focus on functions, object functional programming will focus on object transformations - resulting in higher productivity and quality.



References

http://www.artima.com/weblogs/viewpost.jsp?thread=275983
https://academy.realm.io/posts/altconf-saul-mora-object-orientated-functional-programming/

Sunday, December 3, 2017

Transducing in JS

Say there is a list

var list = [3,4,7,8,11,14,15]

And we want to apply following function to each element

function add1 (n) { return n+1;}

And then filter out only the odd numbers

function isOdd (n) { return n%%2=1;}

And then get sum of those numbers

function sum (total, n) { return total +n };


This can be done :

list
.map(add1)
.filter(isOdd)
.reduce(sum);

This can be reduced to a one line code by using transducer which takes up a sum function as combiner.

Transducer will compose mapReducer and filterReducer together.



Further Reading

frontendmasters.com
Full code - https://gist.github.com/getify/7ba2b8f5a50116f3efa2849e4c6d1f79
http://jlongster.com/Transducers.js--A-JavaScript-Library-for-Transformation-of-Data




Proper Tail Calls, CPS, Trampolines

Proper Tail Calls allows us to run a program with recursive calls without blowing up stack memory.  Tail calls are functions which can be executed without growing stack.

In addition to having proper tail calls, we can implement TCO - Tail Call Optimizations to improve performance of tail recursive functions.

Continuation Passing Style can be used for advanced recursion.

Using Trampolines, we will be calling functions one by one and can get around limitations of having no PTC support. A Trampoline expects a continuation function and executes the same whenever it gets one.

Further Reading
http://lucasfcosta.com/2017/05/08/All-About-Recursion-PTC-TCO-and-STC-in-JavaScript.html
frontendmasters.com
http://www.datchley.name/recursion-tail-calls-and-trampolines/

Saturday, December 2, 2017

Closures, Partial functions and Currying

Closure is when a function "remembers" the variables around it even when the function is executed elsewhere.

Any language that implements lexically scoped name binding with first class functions will have closures. It can be considered as a record storing function and its environment.

Partial functions and Currying are two different techniques for specializing a generalized functions. Partial functions will take some arguments at one time and rest at other time. Currying on the other hand provides arguments one by one for specialization. Currying is kind of calling partial function automatically at each level with one argument




Further Reading

frontendmasters.com

Porter's Five Forces Framework

Analysis of forces close to a company that affect its ability to serve its customers and make a profit.

Based on structure, conduct, performance paradigm in IO economics

Five Forces are

- Bargaining Power of Suppliers
- Threat of New Entrants
- Threat of Substitutes
- Bargaining Power of Buyers
- Industrial Rivalry

Friday, December 1, 2017

The Circles Method

C - Comprehend situation : What , Who, Why, How?

I -  Identify Personas / customers

R - Report customer needs - as ___, I want ___ that ____

C - Cut, through prioritization > ROI Estimate?

L - List Solutions

E - Evaluate trade offs: thoughtful, analytical, objective

S - Summarize recommendation - what, why vs others, recap.




References & Further Reading

https://www.impactinterview.com/2016/08/circles-method-product-design-framework/

Jupyter Notebooks - 1

Jupyter Notebook is essentially a web app that allows us to combine explanatory text, code, equations, visualizations etc in a document that can be shared.

Notebooks are a form of literate programming.

Notebook server which is the core of all interactions via Notebook support a number of kernels.

Read more about how IPython (kernel for python) & Jupyter Notebook works at

https://jupyter.readthedocs.io/en/latest/architecture/how_jupyter_ipython_work.html

Here's a reference diagram from that documentation:





Further Reading:
Setting up remote kernel - http://jupyter-notebook.readthedocs.io/en/latest/public_server.html