DEV Community

Cover image for Top 10: JS Compilables

Top 10: JS Compilables

Arek Nawo on January 26, 2019

This post is taken from my blog so be sure to check it out for more up-to-date content 😉 JavaScript is great for a number of use-cases. It's prett...
Collapse
 
_gdelgado profile image
Gio • Edited

I can only speak for TypeScript and Elm. And I must say that for those of you that really value the ergonomics of the language you use, Elm trumps JS & typescript. Not only do you not get runtime exceptions in Elm, but reasoning about complexity in Elm is much easier given the explicitness of its type system. In typescript you do not have a Maybe type which makes the notion of nullable objects explicit. In typescript you do not have a Result type, which makes failure situations explicit as well. All these additional types might make it seem like a burden to deal with, but what it actually does is force you to reason about all the various states of your program ahead of time instead of after you release and realize your users are looking at a runtime error caused by an edge case you didn't think about.


Edit: Spelling :)

Collapse
 
lyfolos profile image
Muhammed H. Alkan • Edited
let rec fibonacci = fun(n) => switch n {
  | _ when (n < 2) => 1
  | _ => (fibonacci (n - 1)) + (fibonacci (n - 2))
};

for (x in 1 to 10) {
  Js.log(fibonacci(x));
}

to

let rec fibonacci = n =>
  switch (n) {
  | 0 | 1 => 1
  | n => fibonacci(n - 1) + fibonacci(n - 2) 
  }

for (x in 1 to 10) {
  Js.log(fibonacci(x));
}


is a better example

Collapse
 
qm3ster profile image
Mihail Malo • Edited

I wish TypeScript wasn't so shy of adding syntax that actually outputs something.
But at least on the typechecking side as const might be coming as early as 3.3, and opaque types finally seem in the works as well.
Maybe it will go through a second rebirth and finally stop me looking for alternatives for the general small-scale case.

Collapse
 
sagarb3 profile image
Sagar Bhattacharya

Typescript seems the best , as with typescript you are extending your js knowledge and organising it , unlike other's where you are re-learning a whole new language and TS code can be easily used with any existing js project , be it server side nodejs or client side jquery and has a strong community

Collapse
 
_gdelgado profile image
Gio • Edited

Seems the best

Have you used TypeScript on large (10,000+ LOC) projects? It works well when you don't have to use 3rd party packages (React, lodash, etc) because the run-time code for these packages is completely separate from the types. This means that close to 90% of the time, the types are wrong. Which leads to runtime exceptions becasue the typesystem is a completely inacurate representation of the runtime characteristics of the program.

Also, given that you are most likely interfacing with JS, a developer is prone to use the any type way too often, which ultimately defeats the purpose of writing typescript in the first place.


Have you considered that maybe learning a language completely different from JS might help you become a better JS developer? Haskell and Elm are good examples of this. They are radically different from JS and force you to think about your programs in a completely new way. But this thinking can be applied back to JS to help you write more resilient code.


Edit: Check out this blog post where I get into a bit of detail on TypeScript's flaws dev.to/_gdelgado/the-economics-of-...

Collapse
 
mordechaiszw profile image
MordechaiSzw

There's also WebAssembly

Collapse
 
calebwin profile image
Caleb Winston

By the way, "compile-to-JS languages" is probably a better way of saying "JS compilables"

Other than that, nice list! 👍

Collapse
 
diek profile image
diek

I'm thinking of starting with Kotlin, a coworker showed me some code and it looks an interesting language.

Collapse
 
jordonr profile image
Jordon Replogle

+1 for Haxe, it's one of my favorite languages to use.