6

Prime Factors

Is functional programming better than programming with mutable variables? Let’s do a comparative analysis of some familiar exercises. Here, for example, is the traditional Java derivation of the Prime Factors kata using TDD, roughly as it was presented in Chapter 2 of Clean Craftsmanship.3 A related video, Prime Factors, is also available. You can access the video by registering at https://informit.com/functionaldesign.

3. Martin, Clean Craftsmanship, p. 52.

Java Version

We begin with a simple test:

public class PrimeFactorsTest { @Test public void factors() throws Exception { assertThat(factorsOf(1), ...

Get Functional Design: Principles, Patterns, and Practices now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.