4 ms·
Better put 'functional programming is reinventing the way unit tests are written'. Its extremely easier to 'think of' and create unit tests on business logic t
by drubio 18y ago
Better put 'functional programming is reinventing the way unit tests are written'.
Its extremely easier to 'think of' and create unit tests on business logic that avoids using state and mutable data, as do all functional languages.
On the other hand, this is pretty much offset because structuring a program ( the one on which the tests will be performed) using a pure functional style is very hard, especially when its syntax/compiler doesn't enforce it.
Languages like Java which have fields, getter/setter methods and similar syntax are mine-fields for introducing state and mutable data. Erlang really forces you to think in functional style given its 'message passing' style, so unit tests are a snap. In Java and other non-functional languages unit tests would be just as easy, the problem is avoiding state and mutable data.
Though I would still argue the effort forgone in unit testing, still needs to be invested designing the actual business logic taking care it doesn't introduce state and mutable data(non-functional behavior).