r/functionalprogramming • • Feb 02 '23
Question Looking for an alternative to Javascript
I am looking for an alternative to Javascript I could propose to my boss for developing web clients.
We don't do SPAs, we do good old monoliths with some vanilla javascript only where needed.
We have a couple of SPAs, but I don't think of replacing them yet...
- Needs to have some real world use cases
- Should ideally be plugged incrementally (should be able to port some modules, not the whole codebase)
- Statically typed not really necessary
- Should be easy to learn for developers with non-functional background
My thoughts so far:
- Elm seems stuck, although very interesting
- Purescript seems great, but I am a bit afraid for performance (?)
- Clojurescript seems very "professional" but I fear the syntax, especially for newcomers
- rescript / reasonml - what's going on there? I have read some blog posts but still not sure if that situation is stable
- fp-ts that looks like the most boring choice, it would be the best to teach to javascript developers (but I would like to first exclude the other options :))
I would like to hear from your experience!
Kind Regards
15
Upvotes
10
u/danielstaleiny Feb 02 '23
Purescript - I would validate your concerns on Purescript discord. They are all friendly and I am sure they will clear the things out.
9
u/psbfc Feb 02 '23
The nice thing about Elm is that you can isolate it within a normal HTML page as if it were a web component. I wouldn't say that it is stuck, but more of being stable.
ReScript is also stable and has just got async/await. The nice thing about ReScript is the very readable JS output. So if the worst comes to worst, you can ditch ReScript and easily migrate the JS.
There is also Fable, which is F# to JS. It is very flexible and you build apps with the Elm style architecture or use it directly with React. See Feliz to get a feel for it. There is also a new library called Sutil that is similar to Svelte and has no dependancy on React. F# syntax is very nice and easy to learn.
3
u/Luftzig Feb 02 '23
I would like to advocate for Elm also. To start with your concern, I am guessing that by "stuck" you are concerned with the slow release cycle? You can think of it as rather being very conservative in releases and thus stable. Elm is used by Reddit, some AWS teams and Rakuten among other less known companies. It is dead-simple, way simpler than Javascript IMO, while not being too primitive as a trade-off. The compiler errors are actually useful and insightful, and in my experience of using Elm for several medium sized (for single dev) projects, you only encounter bugs in business-logic and integrations, never in the form of unexpected or undefined behaviours. As mentioned, it has a great and friendly community.
Some of the drawbacks of Elm are, in my opinion:
Overall, you can find examples of how to rewrite a single module or even a component in Elm to try it out and integrate it with your code base.
3
u/Alexisbestpony Feb 02 '23
One of my personal favorites is fable. You use F#, It compiles to javascript. If you want it supports using a framework like react, or you can just use the vanilla js it spits out
3
u/pthierry Feb 02 '23
I started using Elm to add small features to a codebase like you describe. It was pretty easy and the reliability was immensely satisfying compared to JS.
The other big advantage of Elm is that it's very beginner friendly. And because of its typing system, you can have a higher confidence in the code produced by inexperienced developers.
3
u/RustinWolf Feb 03 '23
fp-ts is the most complicated and hardest to teach of all in my opinion. It’s constantly evolving so a lot of articles no longer work and documentation is far from user friendly. To understand large parts of the library, usually one has to read Haskell or Purescript literature. It’s still a powerful library and it does a lot, but has a painful amount of boilerplate compared to Purescript which it tries to emulate.
Elm would be the most boring choice here, in a good way.
2
u/BeamMeUpBiscotti Feb 02 '23
ReScript's syntax and core language features are stable and have been for some time, the most notable new feature recently is support for async/await
2
u/Pure-Shift-8502 Feb 03 '23
Phoenix with good old server side rendering. It also has the live feature for real time stuff as well.
2
u/mchwds Feb 03 '23
Elixir with Phoenix LiveView. I’ve been using it for awhile now and I can’t imagine going back.
3
u/bostonou Feb 02 '23
I haven’t done UI in a few years, but spent a lot of time with clojurescript then (been Clojure focused since). If I’m doing an SPA, it’d be my first choice.
The tooling wasn’t beginner friendly but has continually gotten better. The REPL is a game changer. I don’t think clojurescript is any hard for non-FP devs than any other FP language.
I wrote a good bit about my experience with at www.clojurescriptmadeeasy.com. Happy to answer any questions I can.
21
u/hoimass Feb 02 '23
Your requirements seem to indicate Typescript.
5
u/iams3b Feb 02 '23
I'm quite enjoying rescript, it's goal is to be easy to pickup for js developers
3
u/DeepDay6 Feb 03 '23
I don't know why you want to avoid using JavaScript/TypeScript. In my experience there are three points why I'd like to change away from it, though:
constonly means the reference can't be changed, while saying nothing about its contents.So on your languages:
shadow-cljsas package manager. It's FP focused, but not dogmatic about it. You can always create side effects, call JS directly or use/modify JS datastructures, although there's rarely a reason to do so. Contrary to popular memes, there are no more parentheses than in C-style languages like JavaScript, they only start one word farther to the left and there are usually no lines containing only brackets (although nothing will stop you from doing so if you prefer the visual). It's possibly more complicated for beginners to use and understand all the$|><<>><|operators to cope with the auto-curried, bracket-less Elm/PureScript style than having the single rule "the first word after an opening bracket is the function called on the rest of the words in the bracket" of LISPs.PureScript, Elm and ReScript will all have type systems that need less explicit declaration of types than TypeScript will, with the additional benefit that the type assumptions will also hold after deploying your page, something that can not be said about TypeScript code.
Clojure(Script) does not have a static type system, but it has protocols which work the same way as Haskell's typeclasses do and applies nil-punning instead.
My preferences are Elm or ClojureScript.
2
u/[deleted] Feb 03 '23
What problems are you having with javascript? without knowing what problems you're trying to solve, it sounds more like you're trying to avoid javascript for the sake of avoiding javascript, which will ultimately result in frustration because all languages transpile down to javascrtipt for browsers. you're still going to need to know javascript
if you're goal is to develop interactive user interfaces, you should be looking at libraries and frameworks for this instead of switching to a different language switching languages will be a side grade with the trade off being an additional layer of complexity.
what does this mean?
2
u/dbotton Feb 03 '23
Take a look at Common Lisp using CLOG
https://github.com/rabbibotton/clog
2
u/emarthinsen Feb 03 '23
+1 for Elm
2
u/Puzzleheaded-Lab-635 Feb 04 '23
I can't recommend rescript enough, the javascript that it does compile to, is extremely readable and it compiles fasssst.
2
u/mnbkp Feb 05 '23
If you're worried about that, you could try out F#. Its type system is missing some cool stuff that rescript and reasonml have, but it probably has one of the best ecosystems of any of these languages.
Honestly, I'd choose either F# or Elm.
You could also try out Rust + dioxus if you're into that.
0
u/Brilliant_Pickle9683 Feb 02 '23
Pyscript -just random suggestion ,really dunno the usecases
4
u/[deleted] Feb 02 '23
[removed] — view removed comment
0
u/[deleted] Feb 02 '23
[deleted] — view deleted comment