DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Cover image for My Way of (Purely Functional) Programming
#benaryorg
#benaryorg

Posted on

My Way of (Purely Functional) Programming

Top comments (6)

Collapse
 
justgage profile image
Gage

This is how I structure basically everything. Side effects on far edges, pure logic in the middle. It's only when I break from this pattern that I regret the code I write. I use Elixir for my web applications. The only thing I miss is the type system

Collapse
 
benaryorg profile image
#benaryorg

Apart from my previous reply to a similar question, I can point you to Yesod.

Collapse
 
gesuwall profile image
ガブγƒͺエル

What framework do you use for your "generic web applications"?

Collapse
 
benaryorg profile image
#benaryorg

The chapter "Application" (the one mentioning generic web applications) was meant as describing what services do from an outside perspective.
Internals may very well vary, but emphasizing on this structure removes a few problems (mostly state) and enables some performance optimizations (said laziness for external data).

To be honest, I did not yet write any meaningful application.
Mostly reinventing the wheel for educational purposes.

Haskell is just my hobby, as opposed to my job which is a GNU/Linux sysadmin.
The sysadmin background kind of taught me to just take already existing components and stick them together.
In sysadmin world this means sticking tools together with shell-scripts.
In Haskell world this means taking libraries like async or conduit and libraries for parsing the application specific protocols (HTTP, JSON) and sticking them together which, due to purely functional nature of those libraries is actually pretty easy.

I also mostly use Haskell itself for parsing (Parsec), so there is little I know in that respect.
However once again my sysadmin background helps out here: CLI-tools mostly take a stream of input on stdin and map it to something else on stdout.
If you write your "business logic" in a way that it takes a continuous stream of events and responds to each one using a response and a state-change then you can use it in any environment you like, as long as you can map something (HTTP requests, UDP packets, messages on unix-sockets, Websockets messages,.…) to that event stream.

Do not hesitate to ask for clarification, I'm pretty lousy in communicating my thoughts.

An Animated Guide to Node.js Event Lop

Node.js doesn’t stop from running other operations because of Libuv, a C++ library responsible for the event loop and asynchronously handling tasks such as network requests, DNS resolution, file system operations, data encryption, etc.

What happens under the hood when Node.js works on tasks such as database queries? We will explore it by following this piece of code step by step.