What is functional programming?

Reading-notes.md


What is functional programming?

Functional programming is a programming paradigm where programs are constructed by applying and composing functions. It is a declarative programming paradigm in which function definitions are trees of expressions that map values to other values, rather than a sequence of imperative statements which update the running state of the program.

What is a pure function and how do we know if something is a pure function?

A pure function is a function that has the following properties:

1-The function return values are identical for identical arguments (no variation with local static variables, non-local variables, mutable reference arguments or input streams).

2-The function application has no side effects (no mutation of local static variables, non-local variables, mutable reference arguments or input/output streams).

The Benefits of Pure Functions:

1-They’re easier to reason about

2-They’re easier to combine

3-They’re easier to test

4-They’re easier to debug

5-They’re easier to parallelize

Immutable object:

Immutable object (unchangeable object) is an object whose state cannot be modified after it is created. This is in contrast to a mutable object (changeable object), which can be modified after it is created. In some cases, an object is considered immutable even if some internally used attributes change, but the object’s state appears unchanging from an external point of view.

When data is immutable, its state cannot change after it’s created. If you want to change an immutable object, you can’t. Instead, you create a new object with the new value.In Javascript we commonly use the for loop. This next for statement has some mutable variables.

image

What is Referential transparency?

Referential transparency and referential opacity are properties of parts of computer programs. An expression is called referentially transparent if it can be replaced with its corresponding value (and vice-versa) without changing the program’s behavior.[1] This requires that the expression be pure, that is to say the expression value must be the same for the same inputs and its evaluation must have no side effects. An expression that is not referentially transparent is called referentially opaque.

What is a module?

A module is a separate unit of software or hardware. Typical characteristics of modular components include portability, which allows them to be used in a variety of systems, and interoperability, which allows them to function with the components of other systems. The term was first used in architecture.

How do I import a module?

-Save this code in a file named mymodule.

-Import the module named mymodule, and call the greeting function

-Save this code in the file mymodule.

-Import the module named mymodule, and access the person1 dictionary

-Create an alias for mymodule called mx

-Import and use the platform module