When is code data, and when is it code?

The first tenet of functional programming: code is data. Store it in variables, pass it as parameters, return it from methods. This is challenging in the JVM, where all code lives inside methods on objects. Therefore, Scala passes around code in a function object. Code lives in the apply() method. When is a function object created? … Read moreWhen is code data, and when is it code?

A third way

Programming is about translating what a human wants into instructions a computer can understand. Or is it? Thinking down this path, there are two ends of a programming language spectrum. A language can be close to the computer’s perspective: imperative languages that declare data, move and store data, carry out instructions in a fixed order. At … Read moreA third way

What makes a functional programmer?

Michael O’Church has a lot to say about the functional programming community. His post, Functional Programming is a Ghetto (in the “isolated, exclusive neighborhood” sense of ghetto) contains some great descriptions of what goes through a programmer’s head after he or she learns to think in a functional style. The following is a paraphrase of … Read moreWhat makes a functional programmer?

Mental revolution

The book Structure of Scientific Revolutions (1962, Thomas Kuhn) brought the word paradigm into common use. Ideas from fifty years ago about research science apply today to computer science and the software industry. This is one parallel Kuhn makes, extended to illuminate how we think about programming. The human mind does not perceive objects incrementally, … Read moreMental revolution

Why Functional Matters: Your white board will never be the same

Why learn functional programming? For better design skills! The other day we designed a process to match cleared deposits with dispensations. This is how I would have white-boarded it a few years ago: Since then I’ve played around with functional programming. It encourages one to think about processing in terms of data streams: data comes … Read moreWhy Functional Matters: Your white board will never be the same

Lessons from SICP: what is iterative programming?

SICP insight of the day: iterative programming doesn’t require a for loop. Tail recursion is iterative programming. It looks very close to recursion, but the distinction is: a program is iterative if everything it needs is stored in a few state variables. In an imperative style the state is stored in mutable variables. In a … Read moreLessons from SICP: what is iterative programming?

Continuation Style Without the Fugly

The previous post discussed advantages of using a continuation style to send our code to the data instead of making our code wait for the data to come back to it. This pseudocode example has three I/O operations, each encasing the operations which should follow in a callback function parameter. let filename = // calculate … Read moreContinuation Style Without the Fugly

Bring the data to the code, or the code to the data?

Object-oriented code was conceived as message-passing between objects. Service-oriented architecture emphasizes delegation to another system. The entire web is a whole bunch of requests flying around. There is one clear way to be efficient about this: stop waiting for results. When we’re writing imperative code, we want to write the operations in the order they … Read moreBring the data to the code, or the code to the data?