concept program in category javascript

appears as: programs, program, program, The program, programs, A program
Functional Programming in JavaScript

This is an excerpt from Manning's book Functional Programming in JavaScript.

If you’re unable to create and modify objects or print to the console, what practical value would you get from a program like this? Indeed, pure functions can be hard to use in a world full of dynamic behavior and mutation. But practical functional programming doesn’t restrict all changes of state; it just provides a framework to help you manage and reduce them, while allowing you to separate the pure from the impure. Impure code produces externally visible side effects like those listed earlier, and in this book I examine ways to deal with this.

Figure 3.7. Control of a program built using Lodash function chains. The array of person objects is processed through a series of operations. Along the way, the data flows and is finally transformed into a single value.

All control structures contribute to CC; the lower the value, the better. A conditional block affects complexity the most because it bifurcates the program’s control flow into two linearly independent paths. So, naturally, the greater the number of control artifacts, the larger the CC metric will be, and, thus, the harder the program is to test.

QuickCheck is a Haskell library for randomized property-based testing of a program’s specification or properties. You design a specification of a pure program in the form of properties the program should fulfill, and QuickCheck generates a large permutation of test cases against your program and produces a report. You can find more information at https://hackage.haskell.org/package/QuickCheck.

By the same token, JavaScript emulates QuickCheck with a library called JSCheck (see the appendix for setup information), by none other than Douglas Crockford,[1] author of JavaScript: The Good Parts (O’Reilly, 2008). JSCheck can be used to create a technical response to a matching referentially transparent specification of a function or program. Hence, proving the properties of a function is done by generating a large number of random test cases aimed at rigorously exercising all possible output paths of your function.

Node.js in Practice

This is an excerpt from Manning's book Node.js in Practice.

If you have some experience making web applications with Node, perhaps with the Express framework, then you’ve already been using the http, net, and fs core modules without necessarily realizing it. Other built-in features aren’t headline-grabbing, but are critical to creating programs with Node.

Node provides some important functionality out of the box, even without loading any modules. In addition to the features provided by the ECMAScript language, Node has several host objects—objects supplied by Node to help programs to execute.

Listing 2.20 uses setTimeout to simulate a long-running operation that will keep the program running while the timer displays the process’s memory usage. Once the timeout’s delay has been reached, the program will exit without calling clearTimeout.

Listing 2.20. Keeping a timer alive until the program cleanly exits

Node provides a simple API to command-line arguments that you can use to pass options to programs.

debug> restart
program terminated<
debugger listening on port 5858
connecting... ok
Restoring breakpoint debug.js:8
break in start.js:1
  1 var a = 0;
  2
  3 function changeA () {
debug>