Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Ballerina: Functional programming framework for front end web development (github.com/giuseppemag)
28 points by thunderbong on May 23, 2024 | hide | past | favorite | 19 comments


    export const Child2Animation = 
      Co.Repeat(
        Co.Seq([
          Co.SetState(Child2.Updaters.Core.a(replaceWith(1)).then(
            Child2.Updaters.Core.b(replaceWith("")))),
          Co.Wait(250),
          Co.For(Range(0, 3))(
            _ =>
              Co.Seq([
                Co.SetState(Child2.Updaters.Core.a(_ => _ * 2)),
                Co.Wait(250),
                Co.SetState(Child2.Updaters.Core.b(_ => _ + ".")),
                Co.Wait(250),
              ])
          )
        ])
      );

> Not only is the code pretty self explanatory.

Is it though?


> but the alternative implementation of state machines in any frontend framework would look terrible

  async function animation(setState, signal) {
    while (true) {
      setState("a", 1)
      setState("b", "")
      await wait(250)
      signal.throwIfAborted()

      for (_ of range(0, 3)) {
        setState("a", (_) => _ * 2)
        await wait(250)
        signal.throwIfAborted()
        setState("b", (_) => _ + ".")
        await wait(250)
        signal.throwIfAborted()
      }
    }
  }


I love FP. but this is way more readable than the above. It doesn't fight the ergonomics of javascript.


I think a "before" comparison would've really helped with this example. I'd also argue a state machine approach has the added benefit of allowing you to enter the sequence at any point. If you use `Co.Seq` to e.g. build a form flow, it'd be hard to test or serialize into the middle of the sequence.

There may be something interesting here but it's pretty hard to bite into.


Yea, it is. Granted you have to understand the words used in the explanation.

If your bar for “self-explanatory” is “teaches you both the words and the concepts” then there aren’t any self-explanatory frameworks at all?


> Ballerina integrates the state of the art in functional programming and even category theory.

It's.. just typescript?


> Welcome to ballerina, the effortlessly elegant functional programming

> Ballerina is an advanced professional tool for advanced professionals.

> Ballerina integrates the state of the art in functional programming and even category theory.

> ... And if you are a master of functional programming, together you will write code that can be, well, transcendental.

Then I click through the code and see commented out blocks, using `alert` to debug, random wait times (???), unsure if there's any test coverage.

Example:

https://github.com/giuseppemag/ballerina/blob/main/frontend/...

I may not be an advanced enough professional for this library made for advanced professionals who want to write transcendental code.


Since it has to be transpiled into the severely limited language JavaScript, is it worth it at all? F# for instance should have been a functional language but it turns out to be just some lipstick on the pig of procedural object soup, since the .NET runtime isn't actually capable of anything else. Is the situation any better here?


The comment on F# is rather deranged.

CIL has had functional languages in mind since its inception, particularly because of explicit tailcall support.

If anything, it provides all the low-level building blocks the JVM lacks that enable efficient lowering strategy (even if F# does so relatively conservatively and does not push .NET like it could have).


PureScript is arguably the prettiest functional programming language and it compiles to JS (or Erlang, or C++, or Go, or Chez Scheme, or Kotlin, or C)


Interesting to see a project from Giuseppe's Github here on HN.

FP for browser apps is a lot of fun for us lately, but we picked Elm. The rationale: the absence of runtime errors is really sweet when your code runs in the browser (no need to collect browser console output in a central location in order to know what goes wrong).


Lately I've used Gleam with the Lustre framework (which is inspired by Elm). The coolest thing is that one can do server rendered components with it also. It is a very young ecosystem but the community is great!


Not to be confused with the programming language by WSO2 [1].

[1]: https://ballerina.io/


Hadn't heard of this before, nice! Do you happen to know how they create/generate the diagrams on their homepage?


Yeah, that’s exactly what I’m wondering. I was confused by the same name, so when I did a search, it only came up with a language for system integration and not what I remembered. Thankfully it resurfaced again.


Lol I immediately got this confused. Thanks :D


How does it compare to elm/elmish?


Not to be confused with Ballerina the programming language, which produces some very cool code diagrams automatically: https://ballerina.io/


Co.Nope:)




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

Search: