For compile-to-js languages it seems most attractive to those that use the host language (Clojure, Scala, Kotlin, Haskell, etc.), whereas for would be js expats, Typescript seems like the natural choice given current trends.
I think for a compile-to-js language (vs. a transpiler like Typescript) to take off it's going to need at least:
Tiny generated binaries
Great js interop
Large ecosystem
Seamless cross compilation (e.g. JVM/JS)
Fast compiler
Reason + Bucklescript is the only combination I know of that could potentially pull off the above, blazing fast compilation and miniscule binaries being its greatest strengths at the moment.Essentially Typescript Is too trusting. In Java or similar languages, if something comes in as Object you know all bets are off. If you cast and it succeeds you know 100% what kind of object it is. In Typescript it's possible for the type to look fine but be completely wrong, or worse, wrong in a subtle way. And there's no way to fix this without breaking interop with JavaScript.
Since Java has always been strongly typed and has a ton of libraries available this isn't an issue in Kotlin.
Java/Kotlin are just far better designed languages and no amount of banging on JS is going to make it as well designed. Look at PHP, after 10+ years of trying to make it reasonable it's only "okay", there's too much baggage.
The bytecode for Java/C# is much more compact than JS, the runtime is about 10x faster, they have far better standard libraries. They will compile down easily to wasm since their VM's essentially already compile down to native machine code on whatever platform they run on. It's as easy as adding a "wasm" machine target to their runtime and porting the garbage collectors.
I fully expect Wasm to wipe out front end development as we know it. Java and C# are far better suited for what the web has become, essentially an application platform. We've seen the future already, just 10 years too early, in Java applets.
I believe any language that supports "any" allows this. Doesn't Kotlin? https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/
> If it's a union type, typically (Obj | undefined), everything will work fine until one day the object is undefined and everything blows up.
Not if you set strict: true in your typescript options, or you can separately enable just strictNullChecks
> Essentially Typescript Is too trusting. In Java or similar languages, if something comes in as Object you know all bets are off. If you cast and it succeeds you know 100% what kind of object it is. In Typescript it's possible for the type to look fine but be completely wrong, or worse, wrong in a subtle way. And there's no way to fix this without breaking interop with JavaScript.
Instead of casts that fail, typically you would use type guards to deal with this. That way you can isolate unsafe casting code to a single place.
> Since Java has always been strongly typed and has a ton of libraries available this isn't an issue in Kotlin.
DefinitelyTyped (http://definitelytyped.org/) has types for over 3500 popular libraries: https://www.npmjs.com/~types
> the runtime is about 10x faster.
Hmm. I see 1.5x-6x here, with average around 3-4x: https://benchmarksgame.alioth.debian.org/u64q/compare.php?la...
Kotlin's Any is pretty much the opposite of TypeScript's any. In TS it disables type checking completely (according to the docs). In Kotlin it's the top type (similar to Java's Object type), which anything conforms with, but doesn't expose any operations at all (except for the stuff that the JVM provides for free).
The closest match to TS' any would probably be C#'s dynamic https://docs.microsoft.com/en-us/dotnet/csharp/programming-g....
You can declare a `dynamic` Kotlin variable like this:
val myObject: dynamic = null
The myObject above is not type-safe. It seems that the reason for its existence is interop with existing JavaScript code.The Kotlin `Any` class is actaully more related to Java's `Object` class. (It's the superclass of every Kotlin class.)
function inc(n) {
if (typeof n === 'number') { return n + 1 }
throw new Error('Parameter n is not a number');
}
If you wanted to actually runtime check all types (probably not advised) you could parse the type annotations.Or you could define your types using something like JSON Schema and validate against that.
A check for a string or number will work, but a check against a typescript object or something complex like a union type will just return 'Object'
Note that Typescript tries to follow JS to remain a superset that easily compiles down, and the metadata API is currently a stage II Ecma proposal so it's marked experimental.
It should be fairly easy to build a types casting method using that.
If you want top-type like behavior in TS, you want to use `{}` instead of any, since the language is structural. Anything satisfies it, but it exposes no members without a cast or guard to a more specific type.
Your argument is that TS blindly trusts 3rd party typings, but Kotlin has the same exact issue! In fact the Kotlin docs say to use TypeScript typings, or "dynamic" (read: unsafe) mode for 3rd party libs. So I would expect the same level of safety between TS and Kotlin when it comes to 3rd party libs.
I personally prefer TS because it's safer: with literal types and mapped types, my code is far safer than the equivalent Kotlin. It will surprise you how often you use these features.
Means nothing for alt-Java languages' JS target. While the host language gets the Java ecosystem for free, to replicate on the client every Java library needs to be cross compiled.
It's a non-trivial endeavor, one that ClojureScript and Scala.Js can largely avoid due to their already having a rich set of cross compiled frameworks and libraries in their respective ecosystems.
Not sure what the story is with Kotlin here, seems pretty tightly coupled to Java.
I've tested this with Java console apps and it makes them very small. I'm guessing you could get your app size under 50kb
1. The resulting file size is great, heavily optimized and tree-shaked with Goog Closure Compiler. It seems Bucklescript does even better in this regard!
2. It's there, easy to use, does what you expect. A++ would interop again.
3. The ClojureScript community has some of the best libraries for web development such as DataScript, Specter, Reagent, Re-frame, Om, Rum, etc... Not to mention all the other cool built in stuff. core.async, core.logic, core.spec have been invaluable to me.
4. In my experience, you can re-use most of your core Clojure code in CloureScript. Just put them in a .cljc file. There are platform specific APIs as well, and those will be specific to your platform of course.
The only annoying thing is that you have to define your macros in a different file as your .cljs if I recall correctly.
5. The compiler is fast, but to be honest it doesn't even matter because of the state of the art tooling and browser integration you get during development, you don't have to recompile the project after saving a file. If you think Webpack has nice reloading features and dev tools integration, wait until you connect to the browser via a Clojure REPL directly from your IDE (or terminal). It's just bliss.
So here's my take. From a *-to-js language infrastructure point of view, we already have multiple good choices. However, from a language design/culture perspective, both of these languages are esoteric and most likely always will be. They won't catch on, like TypeScript might. Lisp isn't new. ML isn't either. There's a reason they haven't taken over Java on the server side of things for example.
For the foreseeable future, these languages exist just for the minority of programmers who have decided they want something better.
You can have both, so the question is, what's your poison? LISP or ML?
Edit: While I'm here, might as well link to the Simple Made Easy talk by Rich Hickey. The other thing (aside from inventing Clojure) that gave him prophet-like status in the community.
This is exactly what I'm waiting for.
Being able to compile to 2/3 platforms would be a huge plus
To clarify, you mean 10000%, right? My American brain really wants to parse that as a (very precise) 10% improvement.
Its like an Englishman saying colour and you saying, "you mean color, right?" Just seems unnecessary.
Because on a world-wide message board it's still inherently ambiguous. My comment was meant to serve two purposes. First, to draw attention to the ambiguity for others who use `.` as a decimal separator and read "10.000" as "10" (as I very nearly did). Second, to seek clarification because there is a non-zero chance that the OP is in fact a precision-minded person who saw a small productivity improvement when switching to Kotlin.
>Its like an Englishman saying colour and you saying, "you mean color, right?" Just seems unnecessary.
More like when an Englishman says "biscuit". in many contexts I would ask for clarification because my definition of "biscuit" is different from the common British usage, but it's also possible that the Englishman knows this and really does mean "American biscuit".
Awareness that you might be misinterpreting something and seeking to get clarity is a virtuous habit, both in programming and in productive discourse.
Source: my grandfather made them.
As to gravy: yes. Odd.
I also felt spending an hour for a 10% productivity boost was well worth it, so it didn't strike me as odd.
10.000,40
which is exactly the opposite of the US based 10,000.40
So it's locale rather than language that determines this.> source = "produktname"
Honestly that doesn't look "completely typesafe": what are those "source"s? Don't they refer to another element? What happens if you make a typo there?
What will the compiler infer other than a value of type string?
> to supply something that would not one way or the other convert to the types that source can consume.
Well, clearly `source` takes a string, so it will happily accept "produckname" and blow up at run time.
Short of macros I know of no other compile time mechanism that would enable "safe" strings. The usual workaround is to not use plain string values at all and wrap in a sealed type.
The JSON story is also amazing.
This stack is gonna be the biggest deal in the world.
Not to mention that you can run it on Android and soon enough iOS. This is unprecedented.
Do you mean generic 'use react in kotlin' bindings? If so, have you published them or would you consider doing so?
I have not published them, because
a) they use the same method names like the `kotlin-html` package ("div{}" et. al.), only they create ReactElement instead of manipulating the dom. This could be confusing.
b) The type-safe scoping mechanism, so that each scope has it's correct prop-setters and won't inherit setters from a scope further up is rather complex. It uses extension methods with multiple receivers plus operator overrides for `invoke()`.
That is rather complicated to follow so I want to try it out for some time to check if there's confusion or subtle bugs.
c) I haven't optimised for (allocation-)performance yet.
d) I'm using an early-access version of kotlin 1.1.4 which isn't out yet.
https://kotlinlang.org/docs/reference/type-safe-builders.htm...
In general, when I tend to follow a data-flow ("redux" for JS people) architecture, but have a different approach when it comes to side-effects: My state is always a serialisable description including running side-effects. So even network-requests can be reconstructed from a state-file.
Also I decouple View/React from the actual state via interfaces.
Meaning my state doesn't necessarily contain the data in the format my Views need, but it's able to supply the data via delegation.
If I need background-threads I use actors / CSP.
So much to do, so little time ;)
I'm behind on frameworks, I just build with html/css/js/php
Also the security aspect and whatever with regard to using Laravel vs. using your own PHP.
I don't know I'll figure it out.
Thanks for the link to tachyons.css
I get along with ReactNative, it's decent. The data-application part of my last android-app was already written in (JVM-)Kotlin and in the futures the UI will be as well. ;)
I recommend my styling library for React-native: https://github.com/tachyons-css/react-native-style-tachyons
I have extensive experience in ES6/React for the browser and Java/Kotlin for Server-, Desktop- and Mobile-Apps.
A week ago I switched a fairly new project from the usual setup (react/babel/webpack) to Kotlin-code only. My IDE compiles the Kotlin to JS now and webpack serves it as usual.
Writing the react-bindings took me an hour, after that my productivity went up by about 10.000%. It's finally on par with my productivity on server and desktop. No type errors, fast refactoring, no "undefined" errors and all the goodies (extensions) of Kotlin.
Removing the complex eslint settings and babel-setup from webpack and package.json felt triumphant.
My JSX looks like this now and is completely typesafe:
I even get compiler-errors when I nest HTML-tags the wrong way (h1 inside h1) or so.I couldn't be happier. I'll never touch plain ES6 again.