Hacker News new | past | comments | ask | show | jobs | submit login

If anyone is looking for a really eye-opening video take a look at that this. "Domain Modeling Made Functional"

It's applying Functional Programming to plain old Enterprise line of business apps in F#. The author argues why it's so much simpler, and simply walks through an example with cases. It's hard not to be persuaded. It leaves behind all of the lofty crazy maths you see in a lot of presentations of FP, and just shows how it's a simpler technique to solve real world problems.

Domain Modeling Made Functional - https://www.youtube.com/watch?v=Up7LcbGZFuo&feature=youtu.be... (Watch on 1.25x speed)

It's really impressive, and also surprising why more people promoting FP don't show it's tangible benefits and simplicity vs. the theoretical/abstract way it's usually presented.

It's also a great introduction to 'Domain Driven Design' and data modeling regardless of the language you use.




Agreed 100%, sometimes the FP community is its own worst enemy. Too many FP enthusiasts seem to think that "real" FP requires mastering category theory, which is cool and all but really just a particular subset of the paradigm, and a particularly Haskell-centric subset at that.

I encourage anyone who wants to learn functional programming to pick up the classic "Little Schemer" by Friedman and Felleisen. It's a charming book, designed for undergraduates, that teaches you all the important and appealing aspects of FP. And you won't be made to feel like an idiot because you don't know what a monoid is.


I'll dust it of my nightstand. I really should get to it, I guess now is a good day.

Thanks!


After watching it for 20 minutes, I want to know more.

Where can I learn more about this magic called functional programming? Is there a good course? I want to do it for BLOBAs (as he calls them) apps as I'm not too math-heavy.

Also, to what extent does JS support FP? I use anonymous functions/callbacks (I mean red functions, pun intended) and closures (even as poor man's objects, lol) but I don't really know why that is FP and what makes it FP.

This is a bit of too big of an ask now that I think about it. I sound like a person who never programmed before and to be like: so what programming language should I use?

Is there anything good around for JS to create BLOBAs?


So I didn't include it in the original link, but he has a book he wrote under the same title (Domain Modeling Made Functional). I've been going through it now. It's a much more in-depth treatment of the same topics. He walks through a small product from start to finish.

Additionally he does a really great job of walking through two things that I don't think are covered well enough at all for beginning and intermediate programmers (and even experienced ones like myself may have missed parts of along the way).

1. How to effectively gather customer requirements, what questions to ask, what things to dig into, how to organize them. A simple walk through, better than the hand-wavy stuff most people do when requirements gathering.

2. How to model a domain / problem space before implementing. How to effectively reason about your entities, services and actions. And iterate on these with your customer before coding.

I seriously wish I had run across this when I first started coding. A really great collection of tangible, actionable advice.

I've never done it in javascript so won't try to guess, but the first two parts of the three part book are really applicable regardless of the language. Will have to finish the third to see how it is.

Domain Modeling Made Functional - Scott Wlaschin

  https://pragprog.com/book/swdddf/domain-modeling-made-functional

  https://www.amazon.com/Domain-Modeling-Made-Functional-Domain-Driven/dp/1680502549
(I have zero affiliation with the author and get nothing from any links)

His blog https://fsharpforfunandprofit.com/


Thanks! I bought the book.


You can write JS functionally but to get the benefits from the video like modeling your data as sum & product types as well as static type checking, you need to use a language with its own compiler.

For languages that compile to JS, Elm looks a bit more like the F# in the video (https://elm-lang.org/) and Typescript (https://www.typescriptlang.org/) is a much more like standard JS.


You can also use Fable (https://fable.io/) to compile F# to JS.


Scott's website, F# for Fun and Profit, is really good and has some great articles. His article on Railway Oriented Programming is really good.

As for typed, adt functional languages that compile to javascript, there's F#, Elm, Purescript, and ReasonML. I'm a big fan of F# and Elm.


It's very easy to write JS in a functional style, since as you point out, it already supports first-class functions, which is the most important building block.

To really go whole hog, try setting one constraint for yourself: only use immutable data. Make all your variables `const`s, and only use immutable data structures (Immutable.js is a useful library for this).

You'll discover that it's basically impossible to write code in the familiar imperative style – everything needs to be a pure function, that just takes an input and returns a consistent output, without mutating state. This really is the "secret sauce" of FP.


This seems to be missing the point which the GP makes that a significant advantage for FP is not so much the functions (or even the immutability) as it is the domain modelling. In JavaScript a float is a float and the fact that it is immutable won’t save you from accidentally confusing two things that happen to be numbers (say the width of an element and the duration of an animation, or the price of some product and the amount in stock, or a pipe length in feet and thickness in millimetres).

The other domain-modelling-in-FP feature missing from JS is discriminated unions (aka sum types or enums in some languages).

This domain modelling is a big important feature in rust too (with more invariants which may be expressed using ownership constraints) but no one claims it’s a particularly functional language. Indeed I don’t think one needs FP for this kind of domain modelling that we get via ML-family languages.


Yep, true, DDD with FP looks practical. I love defining new words, and that talk in F# simply made it really clear.

It was weird to see a talk like that and realize to myself "but this is just how my brain works!" I happen to be quite a noun-driven person [1]. And I guess I fell into the trap that this made everything seem so easy and understandable!

Which is why I got excited :P I just bought his book, lol. That was too easy to understand and yet entertaining at the same time while feeling useful as well.

[1] Sometimes even creating new nouns into the Dutch language to make arcane but important concepts clear. My most fun noun is "search term scavenger hunt" (in Dutch it is conjugated) for the situation where you know what you're looking for but don't know the right term to get hits on a search engine and you're hunting for the right word.


I'd also recommend https://youtu.be/tV4pHW_WOrY




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: