software-development - done reading

map is actually a functional programming concept that's easy to understand when thinking about list. If you call map on a list, you get back a new list where each element of the new list is the result of applying a function to each element of the original list.

We were naturally led to using RxJava for wrangling UI interactions in a declarative fashion, and we came up with a simplified way of separating the pure logic from the side-effects in our code, very much in the spirit of the Functional Core, Imperative Shell. The result was a highly testable code base most of which could be fully understood, in isolation, with no concern for how it interacted with the rest of the system.

Where is the word functional come from?

The word functional is related to math function, particularly with Lambda calculus. From a more pragmatic perspective, a beginner needs to understand only two concepts in order to use it for everyday applications (no calculus required!).

What is functional programming?

Data processing without the data is just… well, processing. I'm afraid you're going to have to be patient. When you work with functional programming, all you get is functions forming a pipeline. One function feeds data to the next, which feeds it to the next, and so on until the results you need flow out the end.

What are the benefits provided by functional programming?

  1. If you’re a front-end developer working with data, especially if you’re formatting that data for visualization using D3, Raphael or the like, then functional programming will be an essential weapon in your arsenal. However, be warned that if you do a lot of data processing on the client side, the browser may give you the "slow running" script error dialog which can be annoying. Data processing should be done on the server-side to avoid this issue.
  2. Functional programming makes your code a bit more concise. With functional programming, we break the complex task into functions each accomplish a simple task, and then we combine those simple functions to perform more complex tasks.

What are some key points about functional programming?

  1. First, data in functional programs should be immutable, which sounds serious but just means that it should never change. At first, this might seem odd (after all, who needs a program that never changes anything?), but in practice, you would simply create new data structures instead of modifying ones that already exist. For example, if you need to manipulate some data in an array, then you’d make a new array with the updated values, rather than revise the original array. Easy!
  2. Secondly, functional programs should be stateless, which basically means they should perform every task as if for the first time, with no knowledge of what may or may not have happened earlier in the program’s execution (you might say that a stateless program is ignorant of the past). Combined with immutability, this helps us think of each function as if it were operating in a vacuum, blissfully ignorant of anything else in the application besides other functions. In more concrete terms, this means that your functions will operate only on data passed in as arguments and will never rely on outside values to perform their calculations.

What are the best practices?

  1. All of your functions must accept at least one argument.
  2. All of your functions must return data or another function.
  3. No loops!

How can we do programming without loop?

  • Use recursion
  • Need to think more on this. Perhaps there are other techniques as well.

Why should we not use loops?

Nested loops are difficult to read and understand.

What should we do if we find ourselves needing to use loops?

Rethink our design, and try to break it down further into multiple simpler functions, and then combine them. Consider using a functional programming libraries such as Underscore that already provide a bunch of methods such as each, map, reduce, etc for avoiding loops.

What are some functional programming languages?

What is the definition of higher-order functions?

Helper methods that perform actions on arrays in lieu of looping are often called “higher-order functions.”

Higher order functions are functions that accept other functions as an input, or functions that output a function as its output. A helpful example of this is Haskell's built-in map function. map takes in a function that was meant for a single value, and performs this function on an array of objects. Higher order functions allow you to abstract sections of code that multiple functions have in common, and then simply supply a function as a parameter to change the overall effect.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License