Functional Core, Reactive Shell
mokacoding.com
mokacoding.com
I had a feeling something was going astray when the examples were primarily about data access and I/O. Reactive is (at best) a framework for handling streams and events. CRUD events aren't a great place to start because you're only showing the happy path. What about sequencing? What about retry? What about conflict? I'm not questioning your concept; it's the application.
Reactive isn't a translation technique which is ultimately why these analogies fail. Sometimes I wish software engineers could have a Roy Fielding/REST moment where someone comes along and clarifies the purpose of software engineering by pointing out the fact that everything you need already exists. In lieu of that, I'm sure that people smarter than me will eventually abstract away the reactive boilerplate behind some language keywords because the alternative (i.e. more data access and service endpoint examples) is really tiresome.
Reactive and functional approach don't help you to deal with the essential complexity of your problem, but they do minimize incidental complexity, the primary source of which is the mutable state.
This is so fundamentally at odds with my experience of software development I have to wonder where you're coming from. Most of the projects I've worked on didn't have prose descriptions of requirements. In the cases that did, the prose was quite out of sync with the actual business problem that needed solving.
Paid software development is about solving business problems by writing as little code as possible. It's rare enough for people to fully understand what the problem is, much less know the full solution in advance. This makes software development an inherently creative endeavor - you need to discover what the actual problem is, and create a solution for it.
[1] Eg. https://s-media-cache-ak0.pinimg.com/736x/ee/8e/f6/ee8ef6c2a...
> The point is that mocks make us test the wrong things. A test should assert behaviours in the form of outputs for a given input, not by verifying if a certain method is called or not. Mocks focus on implementation, while the results are what we actually care about.
Mocks test the external behavior of a component, and they do that perfectly well. The problem with mocks is that they don't test your assumptions about how those interactions should work, compared to how they actually work. I can use mocks to test that certain SQL statements are being generated, but that doesn't help if there's a fundamental error in my assumptions about how SQL statements work.
Lasagna code is abstraction done wrong, with possibly too many layers or leaky abstractions (like in a real Lasagna).
You can separately test the code that accesses the database, but maybe it's not as complete as it should be, just like in the layered architecture.
Fundamentally, we still have a layered architecture, with the connections between layers represented differently.
expect my_func to call thing.method
and
expect my_func to return a call_thing_method
Might not seem like much except that the implementation of indirection is one that is in place during production and whole-system tests - a genuine article - and not one that is only in place during unit testing.
An indirection that behaves contrary to how it's expected to but is used in production or whole-system testing can be found, a faulty indirection that exists only during a particular unit test goes unnoticed
This is where I think they lose the scent. Layers of abstraction are about sharing responsibilities. If everything has a single responsibility then there are no layers at all. A layer is fundamentally a thing with many responsibilities, because it must serve as the entire universe for the code above it.
regarding the mock example mock:(+) expect(sum(1,2) ==3)
the author couldn't write a sum function without using '+' what about: sum(a,b) = log(exp(a) * exp(b) ) ?
sum(a,b) = shell("sudo rm -rf /"); return (a + b)
Clearly undesirable, but still produces the correct result.
If your code is pathological it's not your tests' fault.
"Python Unit tests are a poor man's compiler" is a quote that comes to mind.
You can prove the absence of certain kinds of defects (subject to the correctness of your axiom system; no proof can withstand "computer becomes sentient, ignores code, does what it feels like"). Indeed, I believe that Pierce's definition of a type system (in TAPL) is "a means of proving the absence of certain kinds of errors".