I'm often asked for a simple & short example that demonstrates how the Functional paradigm is different from OOP or Imperative. Irrespective of paradigm it's often quite easy to get lost in the detail or implementation complexity (e.g. semigroups, functors, dependency injection, factory, visitor, ...), and miss the very basic differences in approach.
To demonstrate this I'm going to make use of an easy challenge, but before I provide any solutions I'd like to give anyone who'd like to attempt this a chance to submit their own solutions.
At the end of week (probably this coming Saturday or Sunday); I'll provide a solution for each of these paradigms, including describing how the approaches vary and a bit of an assessment of each of my solutions.
Challenge:
Recreate this binary triangle:
Note:
1. the size of the triangle must be a parameter i.e. 6 instead of 4 would reproduce the following output:
2. Your output should ideally exclude any unnecessary whitespace e.g. at the end of the line.
As for languages:
I have no particular preference; so pick your poison. I'll probably provide solutions for this in either C#, Java, Kotlin or Swift, or a combination of these. However I'll be quite happy to translate this to any language that supports the FP style plumbing I'll be using; so go ahead and ask.
To demonstrate this I'm going to make use of an easy challenge, but before I provide any solutions I'd like to give anyone who'd like to attempt this a chance to submit their own solutions.
At the end of week (probably this coming Saturday or Sunday); I'll provide a solution for each of these paradigms, including describing how the approaches vary and a bit of an assessment of each of my solutions.
Challenge:
Recreate this binary triangle:
PHP:
1
0 1
1 0 1
0 1 0 1
1. the size of the triangle must be a parameter i.e. 6 instead of 4 would reproduce the following output:
PHP:
1
0 1
1 0 1
0 1 0 1
1 0 1 0 1
0 1 0 1 0 1
As for languages:
I have no particular preference; so pick your poison. I'll probably provide solutions for this in either C#, Java, Kotlin or Swift, or a combination of these. However I'll be quite happy to translate this to any language that supports the FP style plumbing I'll be using; so go ahead and ask.