View on GitHub

reading-notes

Daily Reading 9

Functional Programming

Functional Programming Concepts

What is functional programming?

A programming style that focuses on using only self contained functions to achieve goals, with minimal code existing outside of pure functions.

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

Can the function be run over and over again with the same arguments, and get the same result every time, without causing side effect changes elsewhere? If so, a function is “pure.”

What are the benefits of a pure function?

Extremely easy debugging. If I pass in A and B, do I get C? Yes? If I pass in X and Y, do I get Z? Also yes? There’s no possibility of anything external changing that from being the case, so the code is airtight in a sense.

What is immutability?

Inability to be changed at any point after its creation. the opposite of “mutable.”

What is Referential transparency?

If something will never be modified, and always results in the same thing, why have it be a function at all? A pure function receiving immutable data will always result in the same thing, no mather what circumstances unless directly changed. This makes it Referentially Transparent, and also raises the question of “does this need to be a function at all? Why not hardcode the answer in and skip the function entirely? (just be sure to document it well though.)

Node JS Tutorial for Beginners #6 - Modules and require()

What is a module?

A module is an additional js file in your directory that is dedicated to a single task. Self contained, does it’s own thing, and is called on by the main app or index js.

What does the word ‘require’ do?

Require allows a js file to “see” other js files in your project. It takes an argument of the other file’s directory path, and will be able to see functions and details within. Note that you must have a module.exports = functionName; within the module itself in addition to the require to allow it to be used elsewhere.

How do we bring another module into the file the we are working in?

require(‘./nameOfModule’); //Do not include the extension js in this argument

What do we have to do to make a module available?

module.exports = functionName;

Placed within the module at the end.

Back To Main Page.