35 ms·
Kotlin for JavaScript
- lokedhs 5y agoMy project is a programming language interpreted, and from the start it was written in multiplatform Kotlin. Then als to this it was trivial to create a web frontend where the entire implementation runs in the browser. All of this is done without a single line of Javascript, which helps in reducing the pain of web development. The primary implementation is running on the JVM, but almost all code is also reusable in the web version. It's all open source so anyone that is curious about how this looks like in an actual project is freelance to have a look here. https://kapdemo.dhsdevelopments.com https://kapdemo.dhsdevelopments.com
- math-dev 5y agoVery cool stuff, I feel like I need to definitely learn Kotlin more now Swift + Kotlin + Java + C + JS + Lisp + C++ should have you covered for most things
- Larrikin 5y agoCan Rust replace C or C++ yet, atleast for green field projects? Never liked either in school but always felt bad never getting into low level code after my systems classes. Hoping I could just learn Rust one day instead.
- klabb3 5y agoI've worked with both Rust and Go quite a bit, but not professionally with C or C++. Those two cover a lot of potential green field stuff, like networking, CLI, embedded, etc (maybe not games/graphics as much). Rust is significantly harder to pick up, so check out Go if you haven't already considered it. Most people become productive quickly. That said, much of what you learn in Rust is generally useful for understanding, so it depends on what your goal is.
- kaba0 5y agoBut then why Go? Kotlin, java, c# etc fills the exact same niche.
- grayrest 5y ago> Can Rust replace C or C++ yet, atleast for green field projects? Mozilla has been replacing parts of Firefox C++ with Rust for a decade. They recently celebrated Rust hitting 25% of the LoC in the main repo. More broadly, serious code at large companies is written in Rust: A chunk of Google's Fuchsia OS, Dropbox's storage engine, Amazon's VM manager, etc. There are niches where C/C++ are better suited but in general Rust is good for whatever if the team wants to use it.
- genuine_smiles 5y ago> There are niches where C/C++ are better suited What niches?
- mamcx 5y agoTotally, and could even be for old projects too. Is more a problem of will and commitment. The pace of Rust is increasing, and anyway for the things is not possible to change right now Rust interacting with C/C++ is less hairy than other langs FFI...
- travisgriggs 5y agoI wasn’t under the impression that Rust is all there for embedded micros? I know some people have proven it can be done, but when I go to work with the latest Atmel/MicroChip/Nordic/STM chips, the tools normalized are C tool chains. To use Rust, I’d have to blaze paths. Frankly I’m more intrigued by upython for some (but not all) of the embedded work I do.
- ostenning 5y agoDepends which embedded microcontroller. Some are very well supported, e.g: https://github.com/stm32-rs/stm32h7xx-hal https://github.com/stm32-rs/stm32h7xx-hal
- pjmlp 5y agoOnly in some domains, if you do anything in graphics or GUI related, be prepared to be a contributor to the ecosystem.
- xrd 5y agoIt says you could build React applications. What about Svelte? Also, what are the pros/cons over using typescript? I personally dislike typescript but used to love Kotlin when I was doing more Android development.
- vosper 5y agoWhat are the things you liked about Kotlin that Typescript didn’t have or did poorly? I’m not familiar with Kotlin at all.
- xrd 5y agoThe biggest thing was automatic null checking. That is such a pain in Java and has bitten me so hard many times. Having the language prevent you from writing code that can crash because of a null access violation is a big step forward. There were other things that made Kotlin seem more modern to me, but I'm foggy now on what they were. But, when I wrote Android, I would always choose Kotlin for new projects.
- eyelidlessness 5y agoTypeScript has strict null checks and has only made them stricter over recent releases.
- comp_throw7 5y agoYeah, like the other commenter said, Typescript has better (more comprehensive) null-checking than Kotlin (and, imo, a better type system in general). Obviously both are miles ahead of Java.
- lf-non 5y agoA few things Kotlin does better: - The annotation support is just better. JS ecosystem has forever been debating on decorator spec, but kotlin annotations (esp. with addition of KSP) provide good mechanism for compile time code generation. - Support for builder dsl is just better. The js ecosystem has embraced ugly & verbose embedded XML (JSX) thanks to fb, but in kotlin we can do something like: html { body { div(id="hello") { span(text="whatever") } } } This is just syntax sugar for lambdas passed as last arg to a function, but it makes code a lot more readable. - Inline methods - we don't have to worry about being functional vs being performant in most common cases. The implementations of map/reduce etc. in stdlib are all inline methods and compile down to for loops. - Implicit it (single argument in lambda) and implicit this (in class methods) are minor niceties but they reduce verbosity of everyday code quite a bit. - Interfaces don't get erased - you can use reflection to get interface references, check if an object complies with an interface at runtime. In TS this requires ceremony and assistance from third party libraries like zod/fp-ts etc. - Extensions are cool, you can add extension functions to classes you don't control to mold their API in specific contexts. In JS world we can monkey patch whatever and TS interface merging helps with that but its a pattern generally frowned upon and prone to conflicts (which extension functions are not). - Companion objects are nice to have. Instead of static methods/properties, you have a singleton associated with a class which can comply with any interface, can have its own extensions, can be passed around etc. - Kotlin doesn't have F#/OCaml style pipelines, but you can achieve similar chaining by combining let/apply/with/also extensions. Eg. getName().let { it.contains("foo") }.also { println(it) } - expected & actual are pretty handy for multiplatform development What TS does better: - Structural typing: its a better fit when modelling types for a highly dynamic language. Being able to define interfaces for data coming from sources you can't control without needing mappers etc. makes life simpler. - Features like intersection type, index types etc. are useful and missing in Kotlin. - Compilation times are much better. - large collection of typedefs in the definitively typed repo. My current role involves mostly working with TS and a day doesn't go by that I don't miss kotlin.
- skybrian 5y agoThis might be more appealing to programmers outside the Java ecosystem if it didn't depend on Gradle.
- teg4n_ 5y agoYeah. I’ve tried to get into Kotlin multiple times and the tools used for building like Gradle are inscrutable to me.
- InsaneOstrich 5y agoGradle and Maven are both a million times better than whatever constantly changing collection of random stuff you have to use to build a contemporary node project.
- giveupitscrazy 5y agoYou don't need anything to build a node.js app. If you use typescript then yes you'll want typescript, but honestly the experience out of the box in node is pretty fantastic that you don't need anything else, as far as build goes. Granted if you are talking frontend browser code then sure webpack, but that tool has been around and stable for many years now. Added bonus too is browser adoption is way better than ever so you don't really need a transpile either, typescript being the exception.
- skinnymuch 5y agoDeno is making Node seem like exactly what it is. Node being mediocre and something a person made over a decade before Deno.
- root_axis 5y agoNah. Gradle has its advantages but it's way more complex than building a node project. The Gradle DSL is utterly incomprehensible to anyone that isn't a seasoned Java dev. Honestly, I struggle to think of a language with a more complex build system than Gradle, besides building cpp apps.
- esprehn 5y agoI'd be more interested if there was VSCode support. The JetBrains folks response was ridiculous and dismissive: https://discuss.kotlinlang.org/t/official-support-for-visual-studio-code/8242 https://discuss.kotlinlang.org/t/official-support-for-visual... Apparently they refuse to support the most popular web IDE because Kotlin for JS is really about selling IDEA licenses. Fair enough, but it means I don't suggest Kotlin for anything except as a Java alternative and Android. There's better options from companies that are less adversarial to their community.
- nirvdrum 5y agoDoes the LSP implementation [1] linked by the JetBrains employee in that thread not work? It pushed a new minor version release a little over a week ago. It seems pretty reasonable to me for them to not pay employee salaries to build a plugin for a competing product, especially when they already provide a comprehensive IDE solution available for free (in both senses). What other companies are doing that? I don't mean that as a challenge. I'd love to know what the better options are. [1] -- https://github.com/fwcd/kotlin-language-server https://github.com/fwcd/kotlin-language-server
- dboreham 5y agoIt works. At least, it works well enough for me to use on a daily basis, and I'm pretty hard to please.
- hitekker 5y agopron wrote an insightful comment on Kotlin’s future sometime ago, https://news.ycombinator.com/item?id=24197817 https://news.ycombinator.com/item?id=24197817. He has actively commented on Kotlin this past decade in good faith. The key quote: > Kotlin's design goals are now contradictory. It seeks to be a low-overhead language, i.e. provide abstractions that don't add overhead over the target platform, give access to all platform capabilities, and at the same time target multiple platforms -- Java, Android, LLVM and JS -- over none of which does Kotlin exert much influence (maybe a bit on Android). I agree with pron. I don’t see the longevity of the language outside of Android. Too much of drive to use Kotlin focuses on developer experience hype, which is great for starting projects but pretty bad for maintaining them a decade later.
- deleted 5y ago[deleted]
- lf-non 5y agoBe that as it may, but a core benefit of kotlin (as a developer) is that it has actively sought out good design patterns (eg. builders, composition etc.) and codified them into the language. In Kotlin often the best approach is also the most succinct one - which doesn't hold true for most of the platform-native languages (swift probably being an exception). As long as it keeps doing that, even at the cost of a larger API surface area (or occasional backward incompatibility), I (and I suspect many others) will be quite happy to use it.
- richbell 5y agoI (reluctantly) agree with pron as well. Kotlin's push to become a multi-platform language -- and escape the JVM -- has taken years, and seems far from 'production ready'. Unfortunately, the facets of Kotlin that most people use and care about like language design, ergonomics, Gradle, coroutines, etc., seem to have suffered as a result of this. In the beginning they were running laps around Java with functional and quality-of-life improvements; in recent years, they've kept up with Java (sealed interfaces, records) while adding a few improvements; Loom and pattern matching will be coming to Java in the near future, and I'm worried it will be a while until Kotlin catches up.
- The_rationalist 5y agoIt exports typescript typing too. We are successfully using it for sharing businesses code from our backend with our frontend! Even models can be shared.
- richbell 5y ago> It exports typescript typing too... Even models can be shared. Do you know if this is possible with Kotlin/JVM, or only Kotlin/JS? We've been sharing models via Kotlin/JVM -> Open API Spec -> Open API Generator, which is far from perfect or painless, and I was looking at alternatives like https://github.com/ntrrgc/ts-generator https://github.com/ntrrgc/ts-generator.
- crummy 5y agoWe use ts-generator and are pretty happy with it. Better than our JSweet solution we used earlier. We just use the type generation aspect, not the http client stuff.
- The_rationalist 5y agoKotlin jvm cannot but you transform your kotlin jvm easily into kotlin multiplatform code. Kotlin multiplatform is not the same thing as kotlin js and can be used both by jvm and js code. You can also leverage the expect/external/actual keywords
- Aeolun 5y agoMy problem with this is that it’s absolutely unclear to me how to even get started. The whole Java landscape is full of magic to me. Getting started with node is a matter of downloading a single binary, writing one js file, and executing it with said binary. Upgrading that to Typescript is a matter of downloading another binary, and running the two in sequence. Conversely, Java feels like I have to develop a whole program just to get my program to run.
- paxys 5y agoStep 1 is to buy an IntelliJ IDEA license.
- jpgvm 5y agoCommunity build is completely fine for writing Kotlin. You probably only need an IntelliJ license if you want a bunch of the non-Kotlin plugins.
- jillesvangurp 5y agoExactly, it's what I use currently for Kotlin frontend and backend development. I've also used the opensource community edition it for Java and Python development. There are a few things that you would have to pay up for that might be worth the money depending on what you are doing. I think their C/C++ IDE (CLion) costs money for example and they have an alternative to XCode called AppCode that does not have a community edition. And they have a few other things that might be worth the cash. But simple Kotlin development works great without that. Everything you need comes with the community edition. You do need a fast computer to run it. It's a resource hog.
- listenallyall 5y agoThis is a terrible suggestion. IntelliJ Community Edition is enormously powerful and more than sufficient for getting started with Kotlin. I've been coding in Kotlin for years and still don't have a reason to pay for IntelliJ (sorry JetBrains!)
- 5y ago
- jarl-ragnar 5y agoOne of our lead developers at work pushed this for a rush demo job last week (he’s a Kotlin advocate). He spent the week fighting with lack of documentation and has now given up and reverted to plain old javascript. I’d just use Clojurescript.
- jurmous 5y agoDid he report the issues back to the Kotlin JS team? My experience is that they are quick to respond in Kotlin Slack. We use it in production and saves us quite some time sharing code with the backend. I can imagine Kotlin JS takes some effort since it improved a lot but also changed quite a bit throughout the years. Kotlin Slack helped me a lot through this phase.
- jarl-ragnar 5y agoNo idea. I think the demo schedule drove him to find something that he could get working. To be fair, I think he was fighting not just Kotlin JS but using React within it and his own lack of web technology experience being predominantly an Android dev.
- jpgvm 5y agoYeah I don't think you are going to get far with React + Kotlin/JS if you haven't used React before.
- jurmous 5y agoMaybe he could try again with Jetpack Compose for JS? Then he can use his Android knowledge for the UI and there is less complications with bridging Kotlin code in JS/typescript. To be fair though, Jetpack compose for web is quite new so there is not yet a big ecosystem.
- deleted 5y ago[deleted]
- sebi_io 5y ago
- jurmous 5y agoWe use Kotlin JS in production and like it quite well. It enabled us to easily share code with the Kotlin backend and Typescript frontend. Kotlin also generates Typescript type definitions which enables us to easily call those Kotlin methods from typescript. The multiplatform vision allows us to compile/share natively code for mobile platforms too. I also love to see the quickly evolving Jetpack Compose which would enable to write natively executed UI code on most major platforms. (iOS is not there yet and likely depends on new memory model which is currently being developed.)
- jillesvangurp 5y agoSame here. To be fair, it has some rough edges as it is still a bit cutting edge. But it mostly works great. Worth a look if you need to share code between IOS, Android, Web, and server side. We use the Fritz2 ui framework which has been built from the ground up with Kotlin-js. It's a reactive framework desigbed around Kotlin features like co-routines and flows. It comes with a nice component framework, great documentation, and has been rock solid for us. Worth a look if you are looking for something different. We took some risk by betting on this admittedly risky setup one and a half years ago when I had a few junior Android developers that knew Kotlin and we needed a webapp in a hurry. I ran this as an experiment for a few weeks and then realized that I had nothing to worry about: it's fine. We were hitting all our goals. By now we are super productive with this setup and we are adding lots of features, ui polish, etc. every week. Maybe we'll have to switch at some point but so far we're good on not ending up with the usual mess of technical debt that I've come to associate with javascript projects. Jetpack Compose looks promising. Once IOS support lands, it will be a strong competitor to Flutter and React Native. If you can do without IOS support, it's usable right now. I'm guessing IOS support would be at least another one or two years out. Multiplatform is great and getting more usable with every release. We have an API client and some other functionality that we use across JVM on our server and kotlin-js. It should just work for kotlin native, IOS, and android as well but we have not used that so far. I'm kind of looking forward to the web assembly compiler becoming usable as well.
- syzygyhack 5y ago> we do not want to encourage people whose personal preference is not to use JetBrains development tools. Ridiculous take. Waste of a good language frankly.
- Tmpod 5y agoThis. Kotlin is a great language with a lot of potential, but JB keeps locking it away in their own ecosystem. I used to do stuff with it before but this attitude has driven me away.
- matsemann 5y agoHow have they "locked" it in? That's just BS, you are completely free to write your own tooling. The fact they're not making plugins for the language for competing products is in no way "locking it away".
- vletal 5y agoThe Jetbrains ecosystem is well integrated. Kotlin is a dish best served with IDEA. There are people who do not like using it.
- epolanski 5y agoThis is very exciting, I have wanted to try Kotlin for quite some time and one of the biggest reasons has been few libraries such as arrow-kt[1]. > Kotlin/JS provides the ability to transpile your Kotlin code, the Kotlin standard library, and any compatible dependencies to JavaScript. What does it means "compatible dependencies"? [1] https://arrow-kt.io/ https://arrow-kt.io/
- bsaul 5y agoI wish apple realize that kotlin multiplatform is the real threat to the swift ecosystem, and that they refocus the swift project on making it a true cross-platform language
- Svoka 5y agoKotlin, the first and only language made to be (single) IDE friendly.