8 ms·
Kotlin Compiler Crash Course
- Crazyontap 6y agoKotlin is one of those things that I avoided learning for so long just because I didn't want to learn another new thing. And one day I had to work on a project that was 100% kotlin and so i decided to do a 3 hour crash course on Youtube (actually watched it at 3x speed so it was really 1 hour) and once I grasped the basics it really made so much sense and I don't think I'm ever going back to writing Java classes anymore after having seen the light. Same happened with xpath long back. So long I resisted learning it because CSS selectors did the job but once I reluctantly learned it it changes your whole way of thinking. I think my fear of learning new things comes from coffeescript, something that actually had a negative impact and I would have better off not learning it which also made me scared of learning new technologies.
- amval 6y agoWhy do you feel like that about Coffeescript?
- agumonkey 6y agoyeah i'm surprised too, cs wasn't the holy grail but it was a good improvement over es5 at the time.. it really made writing code different
- Crazyontap 6y agoI really don't remember it was a long time ago but from what I recall there was just too much magic happening and things would break a lot of times because it was easy to make mistakes with it. Come to think of maybe I didn't learn it well enough at that time and blamed it for my silly mistakes. CS did introduce a lot of good things like the fat arrow which was just amazing at that time.
- cutler 6y agoThe thing about Coffeescript is that you don't really gain anything other than syntactic sugar. Compare it to, say, Typescript and Clojurescript where you gain a whole set of features and, with Clojurescript, the semblance of a standard library.
- imagine99 6y agoWould you mind sharing a link to that YouTube crash course? That would be awesome. Thanks.
- Crazyontap 6y agoSure it was this one: https://www.youtube.com/watch?v=H_oGi8uuDpA https://www.youtube.com/watch?v=H_oGi8uuDpA (from history) I guess I remember incorrectly it was 3 hours long. It is only 1hr few minutes and you can easily watch it at 2x speed. But overall Youtube is a great resource for learning new things. If you search Kotlin crash course (filter by duration > 20min) you will find ton of such courses and you can easily judge them by number of likes/dislikes. And make sure to watch it at 3x speed with subs ON initially (video speed controller for chrome). This is truly a great hack when learning tech things via video.
- jpgvm 6y agoJava developers are rightfully conservative and sceptical of "new things". That said I believe Kotlin really provides a strong value proposition over Java. You also don't sacrifice much, there is less tools ofc but enough to get by, performance is equal for the most part etc. Also unlike stuff like CS it has a very strong future with Android backing.
- anta40 6y agoMany years ago, I used to think that Scala was going to be my "next Java". Now, guess it's not Scala, by Kotlin. Why? - First class citizen for Android development. Yes, most of my works is on Android. - Not to foreign compared to Java. In general, Java devs should be able to Kotlin in relatively short time. Not sure about Scala, which is influenced by Haskell/ML etc. At least in my circle, not many folks familiar with functional programming. - Of course now Spring also supports Kotlin :)
- olavgg 6y agoOracle does a really good job improving the Java language. I really don't see any reason for why I should start using Kotlin. I use Groovy when I just need to do something fast without all the boilerplate code. But for 95% of the business problems, plain old Java is exactly what I need. For anything else, its Rust, Python, Javascript that shines in each of their category.
- pdpi 6y agoOracle is doing a good job adding features to Java to keep up with modern languages, but it’s not just about adding — some things need to be removed or changed. By way of example: Final classes by default with an open keyword instead of open by default with a final keyword. Inheritance is a very tricky thing to get right and it’s better to explicitly say “I thought about this and put in the effort to make it work”. Checked exceptions are a contentious topic and I’m not sure which choice I prefer, but Kotlin chose to remove that, and it has an impact on style.
- mpweiher 6y ago
- joseluisq 6y agoFrom my modest experience with Kotlin few months ago in a small Android project for learning purposes. I can just say that the language resulted very expressive, concise and easy to use for me. Coming from other languages (Go, Rust, C#, JS, PHP among others) but doing almost no Java in the past, I was able to getting started with that Android project few weeks later after have been passed across Kotlin's docs https://kotlinlang.org/docs/home.html https://kotlinlang.org/docs/home.html So basically I can confirm "Android’s Kotlin-first approach" https://developer.android.com/kotlin/first https://developer.android.com/kotlin/first
- cutler 6y agoTry Clojure after which there's definitely no going back.
- blacktriangle 6y agoCompletely different motivations, and I suspect Kotlin is a reason that Clojure and Scala seem to be losing much of their initial steam. Clojure offers Lisp on the JVM, but what most people really wanted was a fixed Java. That's exactly what Kotlin delivers. Clojure has decent Java interop, but there's a serious impedance mismatch working with native Clojure and Java libs. Kotlin otoh dogmatically sticks to Java's model of programming, just a cleaned up version.
- fulafel 6y agoIME many Clojure programmers come from non-Java backgrounds and aren't looking for a Java like experience. So I can believe the "more better Java" audience probably heads for Kotlin today. I think this is a win for both the Clojure and Kotlin communities and developer cultures. To inject some time perspective, Clojure is 14 years old, so it's not too bad to be moving from initial steam to young-adulthood steam now :)
- tester34 6y ago>https://vinaytech.wordpress.com/tag/disadvantages-of-ast/ https://vinaytech.wordpress.com/tag/disadvantages-of-ast/ cool
- fenk85 6y agoI recently moved to a new team after using Kotlin for a few years (serverside) and transition back to Java is realy annoying, so much boiler plate and rituals and needless code. Instead of concentrating on solving problems it feels like my job now is to do the elaborate java dance. Alot of muttering and cringing from me. I think Jetbrains should have called Kotlin Java++ instead (yes i know theres alot more to Kotlin than JVM) as it would have made it an easier sell in enterprise world to management who dont realise how much overlap and interop with Java there is when using Kotlin, nor the possible productivity gains from not having to create as much code, having better type system and nullability/immutability features and about dozen other features which make Kotlin such a nice language to work in day to day. Anyways yeh, hopefully can steer team back to Kotlin, they should like it, just like previous team came to love it.
- The_rationalist 6y agoKotlin has this amazing concept called compiler plugins where you can extend, intercept and alter the compiler at any stage of the compilation pipeline (ast, psi, ir) through an API. There even are frameworks that make writing such plugins easier such as https://github.com/arrow-kt/arrow-meta https://github.com/arrow-kt/arrow-meta (which enable to bring union type, higher kinded types, pattern matching, etc) Or https://github.com/google/ksp https://github.com/google/ksp
- brabel 6y agoWhile this is cool, it doesn't look like something very different from other existing JVM compiler plugins... it seems quite similar to Javac plugins[0] and perhaps somewhere in between that and Groovy AST transformers[1]. Manifold[2] is basically a javac plugin if I'm not mistaken, and it shows just how powerful stuff can be accomplished with this approach (including e.g. auto-generation of Java types from common modelling languages like GraphQL, JSON, YAML etc. adds extension methods, unit expressions, ranges, C++-like preprocessors, structural subtyping, even crazy stuff like type-safe reflection - like Ceylon used to have!). For Groovy, besides the built-in AST annotations like `@Immutable` and `@Canonical` (which turns a class into a data class, basically), you can achieve stuff like the Spock Testing Framework[3] which changes the Groovy syntax a little bit to make it really awesome for testing. [0] https://www.baeldung.com/java-build-compiler-plugin https://www.baeldung.com/java-build-compiler-plugin [1] https://groovy-lang.org/metaprogramming.html https://groovy-lang.org/metaprogramming.html [2] http://manifold.systems/ http://manifold.systems/ [3] https://spockframework.org/spock/docs/1.0/spock_primer.html https://spockframework.org/spock/docs/1.0/spock_primer.html
- shock 6y ago> crazy stuff like type-safe reflection - like Ceylon used to have I regret so much losing Ceylon :(
- The_rationalist 6y agoInteresting! However I wonder if building Java plugins is harder. For example: JPA entities have for requirement to have a no-arg constructor. Both Java records and Kotlin data classes have not such a constructor by default. However kotlin has a no arg compiler plugin that autogenerate it for data classes (without any annotation) and Java Records don't have anything similar yet to my knowledge. (however they would still remain incompatible with jpa anyway because unfortunately they are immutable)
- christiansakai 6y agoHow's Kotlin compilation story to JavaScript? Can we do frontend in Kotlin?
- jillesvangurp 6y agoYes you can. I'm using the Fritz2 framework, which is pretty nice. There's another one called KVision. There are also some people doing react in Kotlin. You can also just program straight against the browser APIs as they have nice Kotlin DSLs for large parts of that. Basically, to stay on topic, there are currently multiple kotlin compilers, including one that transpiles to Javascript. There is also tooling to interface with npms, to adapt typescript type mappings to Kotlin, and a few more goodies. Basically you lose the java standard library but you gain access to the browser APIs. Node API mappings are more of a work in progress but you should be able to target node.js as well. Browser side kotlin-js is pretty nice. You can do pretty much everything that you would normally do in js/ts. The build tooling uses gradle, which underneath uses webpack. There's a dead code eliminator, source maps, minification, etc. Our web app uses cordova (for IOS and Android wrappers) with a few plugins, integrates Leaflet for maps, has reactive components (using co-routines and flows), has styled components, etc. So, pretty nice and modern way to do frontend. We have a handful of js things we integrate (like leaflet) and quite a few Kotlin multi platform things (like our own API client). There is also a js backend for the new IR compiler, which is the thing that Jetbrains is currently building to unify the many Kotlin compilers they have. There is also a wasm compiler backend for that in the works but it's to early to rely on that probably. The IR to JVM backend is currently in beta and kotlin native also uses the IR compiler. Kotlin-js is not for everyone just yet (a lot of these tools are beta quality) but if you are more comfortable with Kotlin than js/ts, it's worth checking out. That being said, our setup is quite nice compared to some react train wrecks I've been involved with.
- The_rationalist 6y agoHow is the javascript interop? Can I use Angular/Vue and make kotlin components? Can I use any js/ts library from my kotlin code?
- irateswami 6y ago"Don't use the Java ecosystem. It's junk and Oracle is just waiting to fuck all of you." There's my crash course in Kotlin
- miloignis 6y agoKotlin is made by JetBrains and additionally compiles to native code and JavaScript, OpenJDK is open source, Google has their own JVM for Android. You could use Kotlin pretty much everywhere with no/only indirect Oracle contact.
- irateswami 6y agoOracle owns Java, plain and simple. There are alternatives, sure, but it's foolish to think that when it comes to anything within the Java ecosystem, the buck doesn't stop with Oracle. All they have to do is modify the Java license and all that open source goes poof. We're talking about a company that sued it's own salesperson for earning too high of a commission.
- smt1 6y agoThere is Oracle risk to be sure, but people using the greater java ecosystem are far less tied to the JVM itself than they used to be because of cross compilation to targets that help with ffi boundaries, JIT, IO, memory concerns, etc. That's true with both Kotlin and Scala. Meanwhile the Oracle vs Google case is still going on.
- yjftsjthsd-h 6y agoI was under the impression that openjdk was independent from Oracle?
- irateswami 6y agoOracle owns the IP of Java, and begrudgingly allows such things as openjdk.