8 ms·
Fable is a compiler that brings F# into the JavaScript ecosystem
- sbelskie 5y agoI’ve only played around with it on a few smaller projects, but it blew me away with the simplicity and expressiveness. I’ve used it a few times to make simple web based UIs for personal tooling and am looking forward to using it on something bigger. Just one of the many reasons I find myself more and more excited by F#.
- agumonkey 5y agomaybe rust contender on the frontend
- Taikonerd 5y agoIs it my imagination, or has there been an upswing of interest in F# on HN recently?
- 2mol 5y agoYeah, I blame it on version 5 (and dotnet) and the overall tooling improvements. It has really become an excellent and easy to pick up language, with not too many warts and a very good ecosystem.
- mdm12 5y agoAnd version 6 is about to drop! https://devblogs.microsoft.com/dotnet/whats-new-in-fsharp-6/ https://devblogs.microsoft.com/dotnet/whats-new-in-fsharp-6/
- zz865 5y agoI hate myself, 5 years ago I gave up dotnet to move to Java because it was more popular now I'm drowning in Spring beans and wish I never switched.
- svachalek 5y agoHa, I'd be very interested in seeing a sociology study on Java. There's nothing about the language itself says you need to seize on half a dozen design patterns and beat them into the ground, but that's what every Java project I've ever seen looks like.
- mumblemumble 5y agoI'm also a fairly recent migrant from .NET to Java. My sense is that the root cause of a lot of it is missing features in the Java language itself. There are a lot of cases where in C# I'd have used an extension method, or been able to lean more heavily on generic programming or Expression<T>, but, since Java has no good equivalents of these things, instead I have to break out a design pattern to accomplish the same task. And, once you've cracked that seal, it's sort of an, "In for a penny, in for a pound," type situation. Next thing I know, I'm neck deep in it, and I don't even know how I got there.
- dunefox 5y ago"Design patterns are bug reports against your programming language." - Peter Norvig, https://norvig.com/design-patterns/ https://norvig.com/design-patterns/
- mumblemumble 5y agoWhile I did just criticize Java for lacking some features, I genuinely don't agree with that Norvig quote. It's true that, in a single dispatch language, I sometimes need to use the visitor pattern. And the visitor pattern is a little bit annoying to implement, it's true. But the implication of that Norvig quote is that every single language should implement multiple dispatch, and I simply cannot agree with that. And I suspect that a lot of people who like to invoke that sentiment would not prove to have the courage of their convictions when presented with a situation where Haskell needs a design pattern (sorry, "idiom") in order to work around the fact that it doesn't have dynamic dispatch at all, multiple or otherwise. In general, it's OK for languages to be small and focused, or even to be large and multiparadigm but still draw the line at adding some features. That's not my criticism of Java. My criticism of Java is more along the lines of, Java's a kitchen sink language, and there's nothing wrong (aside from perhaps aesthetics) with being a kitchen sink language, but there are other kitchen sink languages that did a better job of cramming more random crap in more cleanly.
- drekipus 5y agoTooling and marketing budget improvements I'd imagine
- sbelskie 5y agoTooling for sure. I would be shocked in the marketing budget increased just based on how many recent .NET changes recently exclude F# (e.g. source generators).
- zamalek 5y agoI have yet to learn it myself, but I get the idea that there is a huge amount of people who "shut up and get shit done" with it. Posts on HN tend to bring these people to the surface. The interest has always been consistent, it's just not vocal.
- agumonkey 5y agoit's always been bubbling over here
- UglyToad 5y agoPartly the question which caused me to brush off my trends site [0] and add support for'#' and '+' tokens in the search. Looks like somewhat of an increase but a very spiky baseline. https://hn-trends.eliot-jones.com/Home/Trend?id=f%23&allwords=true https://hn-trends.eliot-jones.com/Home/Trend?id=f%23&allword...
- pininja 5y agoThere was a wave of popularity in 2017 as well. I used to work on it full time back then, and enjoyed it a lot. The SQLProvider [0] and other type providers like it are super impressive! [0] https://fsprojects.github.io/SQLProvider/ https://fsprojects.github.io/SQLProvider/
- xupybd 5y agoI've done a few little projects with the SQL provider. I worry about maintainability. You can't compile if the schema changes without you knowing about it. I haven't run into any real problems as a result but it does make me nervous.
- mumblemumble 5y ago> You can't compile if the schema changes without you knowing about it. There are those who would argue that making an incompatibility between the database schema and the code that interacts with it a compile-time error instead of a run-time error is a huge win for software quality. I suppose there are situations where you simply can't have access to a database that mimics the structure of the production database during development. In which case, the SQL provider is definitely not the right tool for the job. But it might be worth looking into ways to change how you do things in order to make it the right tool for the job. A SQL database with an unpredictable schema makes me much more nervous.
- pharmakom 5y agoYou can save a snapshot of the schema into your repo.
- piaste 5y ago> You can't compile if the schema changes without you knowing about it That's why you don't normally compile against the production database. You version control the database schema and use it to create a local database to compile against. This way you can also test potential future migrations using branches. Compiling against the production database should be done separately, as a kind of free integration test (usually in CI).
- Zababa 5y agoMaybe a combination of churn from Scala, growing popularity of .NET in general with .NET Core, lack of high-level stuff in Go, static typing coming to dynamic languages (especially JS), functional features getting everywhere. Lots of stuff is pointing at it in a way.
- kirse 5y agoAlong with Fable highly recommend a look at Feliz. A joy to work with and its ViewEngine can also separately be used w/ Giraffe just for the syntax: https://zaid-ajaj.github.io/Feliz/ https://zaid-ajaj.github.io/Feliz/ https://github.com/Zaid-Ajaj/Feliz https://github.com/Zaid-Ajaj/Feliz
- ilaksh 5y agoDoes Feliz work with Fable?
- pharmakom 5y agoFeliz is an F# library designed to be used with Fable
- sbelskie 5y agoFor those interested in Svetle, Sutil is another thing to check out. Top of my head I can’t remember if it is based on or just inspired by Feliz. https://github.com/davedawkins/Sutil https://github.com/davedawkins/Sutil
- djdjgd 5y agoIt's inspired heavily by Svelte itself, and borrows the Feliz DSL for building DOM. Feliz itself is a layer on top of React, Sutil is ground-up raw DOM building.
- eatonphil 5y ago> optimized for happiness I like React and I like F#. But I never understand this kind of marketing. It's not that I want things optimized for pain. But I guess I'm just most interested in the technical choices and actual performance in the domain over my own happiness?
- headphoneswater 5y agoI'd imagine the folks who take up these projects require f# everywhere in their lives to obtain happiness
- spankalee 5y agoI don't know a ton about Fable, but they recently wrapped Google's Lit to allow building functional templating and web components in it: https://fable.io/Fable.Lit/ https://fable.io/Fable.Lit/ Seems like a neat project.
- phillipcarter 5y agoFable is a brilliant project. It doesn't try to hide the fact that when you write a Fable program, you're fundamentally in the JS ecosystem. This can be a bit of a shift if you're used to doing stuff in .NET, but it means that everything will more or less work with your code. It also comes with a few tools/utilities to ease the F#-JS bridge you're on.
- amelius 5y ago> it means that everything will more or less work with your code So you can call any .NET library?
- lgessler 5y agoby "everything" I think GP is referring to the JS ecosystem
- amelius 5y agoOk. Wouldn't it make more sense to compile .NET bytecode to JS?
- mumblemumble 5y agoI've never dealt much with transpiling to JS, but I would guess that it's a lot easier to do it from the AST or some other higher-level intermediate representation than it is from CIL instructions. That way you don't have to fuss with programmatically figuring out what stack manipulation instructions are trying to accomplish or any other target-specific noise like that.
- phillipcarter 5y agoNot necessarily. Aside from being more technically challenging, it's more of a "what are our goals" kind of question. Do you want to give F# developers who are afraid of javascript a way to avoid it altogether, or a way to bring those developers into the javascript ecosystem?
- 5y ago
- brundolf 5y agoMaybe I'm biased, but I'm often skeptical of the benefits of projects like this that translate a language which normally targets runtime A, into another language that targets a wildly different runtime B (usually JS or WASM) (Disclaimer that I'm not talking about compiling runtime-less languages for different platforms) It just seems like it's going to be a very leaky abstraction, like there will be tons of corner cases where some behavior isn't exactly the same and other behavior isn't quite possible, which will cause libraries and in-house code alike to break in weird ways. I know that ClojureScript, for example, has several caveats relative to Clojure; and most of these translators are not nearly as mainstream (and so don't get nearly as much maintenance attention) as ClojureScript does. And then there's the messy question of interacting with the host system, dropping down into the host language for certain things, etc. I haven't really worked with these kinds of systems so I may be way off, but from the outside it seems like a huge increase in complexity just so you get to stay in a familiar language
- kevinmgranger 5y agoI'm only passingly familiar myself, so I might be off here-- but F# already has that sort of feel and experience, where it has some of its own ways of doing things despite integrating into the .NET runtime. In other words, the language designers and users are already used to understanding corner cases and integrations into ecosystems that are different.
- brundolf 5y agoInteresting point! I haven't used F# so I assumed it was pretty "native" to the .NET runtime Still- I have to wonder about things like concurrency, which is perhaps the most obvious limitation of targeting the JS runtime
- kevinmgranger 5y agoThere are some caveats they outline for the usual async stuff[1], but at a cursory glance, it's not that bad. Thanks to F#'s computation expressions, .NET async code and Fable.Promise code look almost identical.[2] 1: https://fable.io/docs/dotnet/compatibility.html#Caveats-II https://fable.io/docs/dotnet/compatibility.html#Caveats-II 2: https://stackoverflow.com/a/54451205/4099287 https://stackoverflow.com/a/54451205/4099287
- icey 5y agoSince we're in here talking about all kinds of F# goodies, has anyone spent time with https://wiz.run/ https://wiz.run/?
- devmunchies 5y agoStory on Wiz is since I’m a growth engineer I tend to think about usage on a more psychological level (optimizing for reduced friction and simpler onboarding). I found that most libs in F# have the .net APIs right in your face so users need to learn both. (E.g. I would define route handlers in the http library but if I want to change the server port I have to look at dotnet docs.) If F# is to be successful, I think more attention needs to be made to build abstractions on .net APIs.
- pharmakom 5y agoI briefly poked around the source code. I would pick Suave over Wiz since Suave has an immutable data model internally. If for whatever reason Suave is not fast enough, Giraffe can be fine tuned. However, it also exposes much of the underlying ASP.NET stuff. I love the website for Wiz though!
- devmunchies 5y agoyeah wiz is still a work in progress. Its mainly just trying to be a simpler API wrapper for asp.net Would challenge the notion of immutability or extensibility being a primary motive for using a library. Would like to see UX (DX more specifically) start to take more of a front seat in F#, since its one of the more neglected parameters of success in the ecosystem. Extensibility can be added, UX is more difficult to retroactively account for. If Wiz only influences other libraries to become simpler for new users then I will consider it a success. I just want more eng teams to use F# or Ocaml without having to justify why you aren't using python/node.js.
- pharmakom 5y agoI admire and share this goal! However, if you translated the Wiz examples to Suave, would they be any more difficult to read? I think the biggest issue is Suave’s docs etc.
- akdor1154 5y agoWhat's even more exciting is there is work underway to allow Fable to target Python instead: https://github.com/fable-compiler/Fable/issues/2339 https://github.com/fable-compiler/Fable/issues/2339 These things are bizarre when you think about the tech stack they lead to, but undeniably still really useful in our unfortunate real world. I think of F# as 'the pragmatist's functional programming language', and projects like this follow that mindset.
- adelarsq 5y agoAlso there are work to support PHP (https://github.com/fable-compiler/Fable/pull/2447 https://github.com/fable-compiler/Fable/pull/2447), Rust (https://github.com/fable-compiler/Fable/pull/2523 https://github.com/fable-compiler/Fable/pull/2523) and Lua (https://github.com/fable-compiler/Fable/pull/2509 https://github.com/fable-compiler/Fable/pull/2509)
- satvikpendem 5y agoIs it named Fable due to its relation to the Fable series which Microsoft publishes?
- vizzier 5y agoI believe it is a portmanteau of "F#" and "Babel" the latter being a common framework for es6+ javascript compilation [1]. [1] https://babeljs.io/ https://babeljs.io/
- cercatrova 5y agoAh that would make more sense.
- Rapzid 5y agoDebating F# for OSS project I'm about to start but the asp.net C# with blazor story(though I need support for loading blazor code at runtime for plugins and can't get a straight answer on that) is very compelling. As to Fable.. I would want to use it on Vuejs perhaps if I can't do blazor, but also with something like mobx and NOT Elmish. I despise redux and it just looks gross. I want the Mobx "magic" for this boring view update stuff.
- dan-robertson 5y agoHow close are the semantics to F#? For example OCaml has bucklescript which produces reasonable looking JavaScript but doesn’t always follow the language semantics, and js_of_ocaml which produces horrid JavaScript (it compiles from 32-bit OCaml bytecode to js, and fakes the OCaml memory layout of objects by using arrays with their first element being the tag of the object, so e.g. a float is represented in js as [<magic number>, <the actual float>]). Similarly, Common Lisp has something called parenscript which compiles a lispy syntax to js but e.g. uses JavaScript arrays for its lists (so you don’t have a cons function).
- pharmakom 5y agoFable produces reasonable JavaScript and makes some semantic concessions towards JS. For example, ints are compiled to JS floats. You still get full compile-time type checking. For shared code it can be wise to maintain tests that can run on both .NET and Node.js.