First thing to do: Stop using class. Ask yourself first: Should i use a class here and there ?
Wait, i miss something here: Writing pure functions is hard ?
First thing to do: Stop using class. Ask yourself first: Should i use a class here and there ?
Wait, i miss something here: Writing pure functions is hard ?
All this should be send to a task queue, triggered by a call to your REST API.
Good luck with purity.
Most of your counter example needs integration tests to test properly anyhow - not really a good point.
If you can give up encapsulation (which IMO isn't actually that useful in practice) and in return, your program becomes 95% functional, that seems like a really good tradeoff.
2. code that listens to the task queue for new jobs
3. code that fetches a file from the FTP server
4. code that converts the JSON file to a format appropriate for the root finding
5. code that performs the root finding
6. code that converts the result of (3) to a format appropriate for insertion into a table
7. code that inserts the result into a Postgres table
Steps 4, 5 and 6 seem easy enough to implement in a pure fashion.
"Functional Core, Imperative Shell" was just posted too, this is the perfect example of where that structure works: https://news.ycombinator.com/item?id=34860164
> Many examples in functional programming assume that you are always on the “happy path”. But to create a robust real world application you must deal with validation, logging, network and service errors, and other annoyances.
> So, how do you handle all this in a clean functional way?
> This talk will provide a brief introduction to this topic, using a fun and easy-to-understand railway analogy.
Functional programming keywords/shorthands: option/either/monads
I recommend you to have a look at Haskell, probably the most famous language for enforcing only pure functions in your program. And I took this example from Haskell.
Here is a good starting point for this concrete example: > https://stackoverflow.com/questions/59035420/understanding-p...
Quote (from the course 'Haskell Fundamentals Part 1' mentioned in the post):
> This example helps illustrate that putStrLn is not a function with side effects.
The answers explain the concept quite well.
$ ghci
GHCi, version 8.8.4: https://www.haskell.org/ghc/ :? for help
Prelude> putStrLn "hello" == putStrLn "hello"
<interactive>:1:1: error:
• No instance for (Eq (IO ())) arising from a use of ‘==’
• In the expression: putStrLn "hello" == putStrLn "hello"
In an equation for ‘it’: it = putStrLn "hello" == putStrLn "hello"
If you want to test your IO code, and you should, you still have to test them from the perspective of them actually executing in the real world. There's no way to test them as pure values. The snippet above is only the beginning of your problems if you wanted to do that, but it a plenty sufficient problem on its own. In addition to the obvious problem that it points out that IO values are already not comparable to each other in the naive sense, there's also the more philosophical problem that the IO values are your programs, so even if you could run the test I show above, on more complicated expressions, your tests would be asserting that you wrote the program you thought you wrote, not that the program you wrote does what you think it should do.You probably replied to the wrong person.
However, solving a business problem with only pure functions is indeed hard