News for hackers. Stuff that matters.
Re:Is .NET just miles ahead or am I delusional? by williamcotton on Saturday April 13, 2024 @07:41AM (#40022424)
If you’re going to compile a language to JS, why pick TypeScript?

The Fable compiler for F# barely adds any cost on top of what TS adds in terms of dependencies, compilation and tooling and IMO gives you a much better language for developing applications. And you still get to use the JS ecosystem.

Most of the cost is related to familiarity with both F# and JS, node and the browser.

But once you match on a pipeline of Results you can never go back!

Re:Is .NET just miles ahead or am I delusional? by lolinder on Saturday April 13, 2024 @08:05AM (#40022591)
You pick TypeScript because you can compile it to JavaScript by hand or in your head. The file size is smaller because there are no runtime features to bundle. When you're looking at the compiled version it's still recognizable as your code just without the types, when you're stepping through things in the debugger there are no surprises, line numbers for errors point you to places that are completely unsurprising because TypeScript is just JavaScript with a type system.

I've tried plenty of other to-JS compilers, even for languages that I love, and I still choose TypeScript every time.

Re:Is .NET just miles ahead or am I delusional? by williamcotton on Saturday April 13, 2024 @08:16AM (#40022646)
Have you even tried Fable? It’s leagues above other similar approaches and had true JS interop.

It doesn’t feel that much different than the TS compilation process. It is not what you’re expecting.

Re:Is .NET just miles ahead or am I delusional? by grugagag on Saturday April 13, 2024 @09:18AM (#40022955)
The main problem with F# is low popularity and hence gig opportunities are a lot fewer.
Re:Is .NET just miles ahead or am I delusional? by williamcotton on Saturday April 13, 2024 @09:22AM (#40022978)
That is indeed the cost. However, the talent pool is much better. This means your developers aren’t as easily replaceable so that might impact management’s decision making.
Re:Is .NET just miles ahead or am I delusional? by williamcotton on Saturday April 13, 2024 @07:55AM (#40022523)
Really, downvotes?

Am I not contributing to the conversation? Has anyone else even mentioned F# or Fable?

Re:Is .NET just miles ahead or am I delusional? by FrustratedMonky on Saturday April 13, 2024 @08:07AM (#40022604)
I agree here.

I wish that instead of TypeScript, MS had just used F#.

It seems like they took some of the concepts of what can be done in F# and made TypeScript. I wish they had just stuck with F#.

It's almost like it was marketing, like they didn't like how F# was viewed so TypeScript was a re-branding.

Maybe it is because TypeScript can be considered a DSL that could be built by F#. Like Elmish.

EDIT> Yeah, not sure if enough people understand F#. You can easily build TypeScript from F#. Or maybe the downvotes are from Haskell people that just view, a functional language can build anything so it isn't worth commenting on.

Re:Is .NET just miles ahead or am I delusional? by AndrewDucker on Saturday April 13, 2024 @08:37AM (#40022760)
Typescript is a superset of JavaScript. Every JavaScript file is a valid Typescript file. This is not even slightly true of F#.
Re:Is .NET just miles ahead or am I delusional? by chpatrick on Saturday April 13, 2024 @09:42AM (#40023079)
Because it has a strong, really well thought out type system, tons of industry adoption, good debugging in the browser and works with the existing ecosystem.

We tried Haskell in the browser before and it was a huge mistake. We want back to TypeScript afterwards.

Re:Is .NET just miles ahead or am I delusional? by williamcotton on Saturday April 13, 2024 @11:54AM (#40023947)
What makes F# work so well for JS interop is the support for objects and OOP while still offering up all of the syntactic niceties of an ML language like pattern matching, monad-like computation expressions, etc.

Haskell wouldn't work in this context.

I've had a very easy time debugging Fable compiled projects.

Again, I have extensive node and JS experience which is absolutely required for working on a Fable project.

I would argue that the hardest parts of TypeScript aren't that much less of a leap than F#.

I would argue that this code is easier to debug than the equivalent .tsx:

  [<ReactComponent>]
  let Counter() =
      let (count, setCount) = React.useState(0)
      Html.div [
          Html.button [
              prop.onClick (fun _ -> setCount(count + 1))
              prop.text "Increment"
          ]
  
          Html.button [
              prop.onClick (fun _ -> setCount(count - 1))
              prop.text "Decrement"
          ]
  
          Html.h1 count
      ]
And this basically looks like JS to begin with:

  [<ReactComponent>]
  let ShowGreeting(props: {| greeting : Greeting |}) =
      React.fragment [
          Html.h2 props.greeting.heading
          Html.h4 props.greeting.subheading
          Html.p props.greeting.content
      ]
  
  app.get("/", fun req res next ->
      promise {
          let! response = 
              req 
              |> gql "query { greeting { heading subheading content } }" {||}
              
          match response with
          | Ok response -> 
              let greeting : Greeting = response?greeting
              ShowGreeting ({| greeting = greeting |})
              |> res.renderComponent
          | Error message -> next()
      }   
  )
Again, Result types! Computation expressions! Error handling with these constructs is well worth the price of admission.

Compare this to the try/catch approach you'd be using in TS:

https://fex-template.fly.dev/form-validation

Re:Is .NET just miles ahead or am I delusional? by chpatrick on Saturday April 13, 2024 @05:42PM (#40026428)
What does debugging look like?