News for hackers. Stuff that matters.
Re:Fable: F# to JavaScript compiler by dep_b on Sunday October 29, 2017 @05:16PM (#15581447)
The first thing I worry about reading something like this is how leaky the abstraction will be. I would love to ditch JavaScript for pretty much anything else but if I need to think about the JavaScript part anyway because of certain things that I can or cannot do I prefer to think in JavaScript from the get go.
Re:Fable: F# to JavaScript compiler by tpetricek on Sunday October 29, 2017 @05:43PM (#15581585)
This is a tricky one. If the abstractions were not leaky, you would not be able to interoperate with JavaScript libraries and you'd have to reimplement everything that powers the modern JS ecosystem. On the other hand, if the abstractions were too leaky, you'd lose all benefits of a nice language like F#.

I think Fable strikes the right balance. There are some leaky aspects of how it compiles to JS, but this means that you can quite well use it with existing JS libraries and for things like parsing JSON (you can just cast JSON object to F# records and it'll work).

So, you need to think about something about the JS part when you want to do JavaScript-y things, but you still get plenty of nice help from the F# compiler when writing the logic that the functional-first style makes so much easier.

In my experience with Fable, this pragmatic approach is what makes it great.

Re:Fable: F# to JavaScript compiler by microcolonel on Sunday October 29, 2017 @11:41PM (#15582970)
> you can just cast JSON object to F# records and it'll work

Isn't a "JSON object" just a string?

Re:Fable: F# to JavaScript compiler by TomMarius on Monday October 30, 2017 @04:25AM (#15583669)
He probably wanted to say "plain JS object", which is denoted in JSON. You can put JSON in a string, but the syntax is called JSON as well.
Re:Fable: F# to JavaScript compiler by tpetricek on Monday October 30, 2017 @08:14AM (#15584418)
Yes, that's what I meant, thanks :-). The idea is that you can just write `unbox<MyType>(jsonParse("{whatever:42}"))`.
Re:Fable: F# to JavaScript compiler by noir_lord on Sunday October 29, 2017 @06:07PM (#15581727)
This is exactly why I standardised on TypeScript.

Their isn't actually much of an abstraction in one direction, valid ES6 is valid TS and the types are inter-operable.

Throw in better typing, proper classes, down compiling of async/await to ES3/ES5 (still magic to me) and the ability to progressively port from one to the other (and you can even get a lot of the TS benefits just by annotating your existing JS as a good first step to moving to TS) and for me it was a no-brainer.

I don't think TS is a pretty language but it's a fantastic approach to getting from shitty-A to less shitty-B.

Pragmatism wins for me as much as I'd love to just write everything client side in something else.

Re:Fable: F# to JavaScript compiler by WaxProlix on Sunday October 29, 2017 @09:18PM (#15582523)
I have to agree, the pragmatic and thoughtful approach that the TS team has brought to the language makes it reasonable to write in and easy enough to reason about at any given time. Plus, being a superset means that if you want to 'drop into' JS to take advantage of some quirk or whatever at any time, you can just disable your linter and do the deed.

Coming from a C# and Python fan, TS hits the mark pretty solidly on all levels.

Re:Fable: F# to JavaScript compiler by BigJono on Monday October 30, 2017 @02:18AM (#15583381)
> Plus, being a superset means that if you want to 'drop into' JS to take advantage of some quirk or whatever at any time, you can just disable your linter and do the deed.

This is an exact example of what GP was talking about with leaky abstractions though. You don't have to just learn TS to use TS, you need to learn TS and JS.

IMO a proper, strict typed language; and plain Javascript; are both much better options than TS.

Re:Fable: F# to JavaScript compiler by Osiris on Monday October 30, 2017 @03:36AM (#15583559)
> You don't have to just learn TS to use TS, you need to learn TS and JS.

I don't understand this. TypeScript is not a different language. It's just JavaScript with some type annotations. If you had never used JavaScript before and learned TypeScript you could immediately write plain JavaScript as well.

Re:Fable: F# to JavaScript compiler by isaacabraham79 on Monday October 30, 2017 @05:15AM (#15583809)
Typescript has grown into way more than just "JavaScript with some type annotations". It's a much bigger superset with lots of language features that JS doesn't have.
Re:Fable: F# to JavaScript compiler by TeMPOraL on Monday October 30, 2017 @05:20AM (#15583819)
TS is not a leaky abstraction; TS is no abstraction at all. It extends JavaScript, not alters or replaces it. As a result, all JS is automatically valid TS.
Re:Fable: F# to JavaScript compiler by dep_b on Monday October 30, 2017 @12:16PM (#15586190)
Well I'm perfectly fine with something what languages like C++ or Objective-C are to C since the whole C interface is still available. If I have a problem in the C layer I can touch that directly and fix it. But I don't think it's possible to mix F# and JS code in the same code file without doing really ugly stuff.
Re:Fable: F# to JavaScript compiler by MangelMaxime on Tuesday October 31, 2017 @06:13AM (#15592069)
In fact, Fable interop is a really powerful one.

If you want to make your own opinion, we have a really good guide here: https://medium.com/@zaid.naom/f-interop-with-javascript-in-f...

Re:Fable: F# to JavaScript compiler by jackmott on Sunday October 29, 2017 @08:23PM (#15582362)
I haven't used it myself but the Ionide plugin for VSCode, which creates a full featured IDE experience for F#, is done in F# transpiled to javascript. The maintainers seems to enjoy it.
Re:Fable: F# to JavaScript compiler by nerdponx on Monday October 30, 2017 @04:08AM (#15583633)
People seem to love BuckleScript, so it must be possible to do this kind of thing right.