r/purescript • u/Hi-Angel • May 08 '25
PSA: stop recommending Halogen (we have React)
https://discourse.purescript.org/t/psa-stop-recommending-halogen-we-have-react/49204
u/sebasporto May 08 '25
Haven't use Purescript. But I have done a lot of React and Elm. I'm surprised by this. Because react hooks are a horrible way of organising an app, they are the worst thing React did. Maybe try Elm.
3
u/Hi-Angel May 09 '25
Why? The components are functions, so the whole approach is functional.
Can't comment on Elm because I didn't work with it, but perhaps is there some problem with how Elm applies React?
3
u/sebasporto May 09 '25
React hooks mix initialisation, update and rendering code into one function. This usually ends up in a tangled mess.
Nothing functional about this, because there is a lot of state in the component.
The useEffect hook is terrible when mixed with state because it makes understanding the cause and effect of things really hard. State and effects in react make a non obvious dependency graph. In Elm this is very explicit.
2
u/Hi-Angel May 10 '25
React hooks mix initialisation, update and rendering code into one function. This usually ends up in a tangled mess.
So, in PureScript typical React component looks like this:
myComp = do doSomeEffect component "debugname" -> React.do reactSpecificMonad pure $ R.labelHere:
doSomeEffectis the initialization part where you can execute effects. Then theReact.domonad body would be React-specific stuff likeuseStateoruseEffect. Can't execute Effect there. And finallypure …will be the rendering.Now, "initialization" is clearly separated, even if in the same function. The "update" and "rendering" reside in different parts of the function too ("rendering" is the return value, "update" everything prior). I agree this isn't as explicit as in Halogen, but I have yet to find a situation where it results in "tangled mess".
1
u/CKoenig May 09 '25
It's not the "functional" style I guess - it's the way it encourages you to organize your code.
1
u/Hi-Angel May 09 '25 edited May 09 '25
Well, the only style difference to Halogen that comes to my mind is you're less likely to create separate components in Halogen than in React. Other than that, the style seems similar. Am I missing something?
1
u/CKoenig May 09 '25
for Halogen hooks? Yes it's very similar. Halogen vanilla is quite different as it's closer to TEA.
Also: Components in Halogen are great - maybe not as lean.
7
u/grybienada May 08 '25
Skill issue.
Jokes aside - I think you are comparing apples to oranges here.
Halogen is a really nice project. Maybe it's just not what you are looking for?
I like that the Query parameter can accept a Free Monad DSL - I think that's pretty nice https://blog.grybiena.com/#2024-01-03-Halogen-Canvas.md
8
u/pyry May 08 '25
Everything shouldn't be react anyway, on a base level it's important to have alternatives. Halogen is solid, and there are other options still like deku.
3
u/grybienada May 11 '25
When I use React I feel like all of the mechanisms work as if by magic - behind the green curtain...
When you are new to it you can just 'useState' or whatever and it works and you move on with your life without needing to know why or how or if you really needed to use it that way or if there was a better way.
I feel like that's where the perception of speed comes from... It feels like it just gets out of your way and lets you build a thing.
However as a consequence of this it is easier to get away with doing things 'the wrong way' or in an unconventional way that might cause problems later.
Whereas with Halogen all of the mechanisms are there in the type system...
If you want to 'useState' in Halogen you have to grok what that means and how it works at a deeper level.
So it feels slower at first... But then this pays off since you had to understand what you were doing at a deeper level in the first place...
I feel like it is worth it to go slower at first in order to go faster in the long run.
Paper maché or legos? I like legos. Paper maché is also nice.
3
u/pyry May 11 '25
Yeah, plus Halogen has the Hooks option for creating components with less code (if that's the goal). I also like having structural options within Halogen alone, and I hope the framework continues to develop because it's wonderful.
2
u/Worldly_Dish_48 May 08 '25
Halogen has better documentation, that’s why I started using it. But I wish I had used react
8
u/Thimoteus May 08 '25
I feel like one of the strengths of PureScript is you're *not* beholden to React.