4 ms·
Kotlin is basically Java without the boilerplate. Some of the code snippets on the page, translated into Kotlin, would be: data class User(val username: Str
by nostrademons 7y ago
Kotlin is basically Java without the boilerplate. Some of the code snippets on the page, translated into Kotlin, would be:
data class User(val username: String)
data class Config(val userTable: DynamoTable, val userId: String)
typealias ItemToUserConverter = (Item) -> User
class DynamoDbUserProvider(
val configProvider: ConfigProvider,
val userTableProvider: UserTableProvider,
val dynamoReader: DynamoItemReader,
val itemToUserConverter: ItemToUserConverter) {
fun execute(id: String) = itemToUserConverter(dynamoReader.execute(userTableProvider.execute(config), id))
}
Plus it comes with great debugging/refactoring/IDE support, async/await, type inference, and good Java integration.
- pkulak 7y agoI've heard Kotlin described as what Java would be today if it didn't have to maintain backwards compatibility, and I think that's the perfect way to think about it. But it still compiles down to the same bytecode, so there's near perfect interoperability with any other version of Java you like.
- smabie 7y agoAnd, Scala is Kotlin without the boilerplate. Scala is the most expressive and powerful language on the JVM, hands down. Kotlin is just a poor imitation. Of course, Java is way worse than either, but unless you are targeting Android, do yourself a favor and use Scala. Closure is okay, I guess, but I find dynamic typing and the dogma of Clojure counterproductive.
- nostrademons 7y ago> Scala is the most expressive and powerful language on the JVM, hands down. So I'd agree with that statement... > do yourself a favor and use Scala ...but not that one. I've found that Scala gets too expressive, much the same way that writing production code in Common Lisp or Haskell can be slower than just writing it in Python. It offers incredibly powerful abstraction capabilities that can often dramatically reduce the amount of code you write; but at some point you end up spending more time hunting for the perfect abstraction than actually writing the code. The ideal programming language (for productivity at least, not necessarily for fun or erudition) is one that melts into the background when you program so that you can focus on the problem domain rather than the program. That's the main appeal of languages like Go, Java, and Python: they offer just enough power to write the program, but not so much that you can write the program in a dramatically better way and end up tempted to try and find that way. Kotlin embraces the "it's just a better Java" approach: it's a minor re-skinning of the concepts in Java, and to the extent that it introduces new language features (like closures, lambdas, properties, data classes, anonymous objects, type inference, and immutability), they're all concepts that skilled Java programmers would be immediately familiar with but would otherwise have to write lots of boilerplate for. The Java interop story is also better with Kotlin, because Scala introduces abstractions for which there are no obvious Java equivalents, and hence there's an impedance mismatch when you try to envision how your Java libraries might fit into your Scala program. Kotlin's designers took care to make sure that there's an easy, intuitive mapping between Kotlin concepts and Java ones, usually one that had already been enshrined in existing Java conventions (eg. JavaBeans work nicely with properties, functional objects with lambdas), so most Java libraries just work in an obvious way. Basically they intentionally made it dumber so you don't have to think about as much, which is a win for everyday programming.
- smabie 7y agoI guess I'm not an everyday programmer then? I want the machine to work for me, not the other way around. I find it absurd when I find programmers actually arguing for less power and less abstraction, it's like arguing for less free speech or less freedom: contrary to your own interests.
- nostrademons 7y agoI thought the same way when I got out of college, but changed my mind after a decade or so in the industry. What changed could be neatly summed up by this post: https://www.kalzumeus.com/2011/10/28/dont-call-yourself-a-programmer/ https://www.kalzumeus.com/2011/10/28/dont-call-yourself-a-pr... Basically, I used to program for the intellectual challenge and the thrill of programming itself. If that's your goal, by all means use Scala or Haskell or Lisp. But at some point that faded, and now I program because somebody has a problem that they will pay me to solve or (for various startup ideas) because I want to understand the market or some data source that has the potential to be worth a lot to a lot of people. For these, my focus is on the problem - the programming is a means to an end for solving the problem, and so anything that lets me spend less brainpower on the programming and more brainpower on the problem domain is a net win.
- smabie 7y agoYou can program in Scala just like Java, with both hands tied behind your back if you please. If you can’t restrain yourself and not use free monads or whatever, that’s on you, not the language. I’ve worked on enterprise Scala code bases for a number of years, and no single person on the team would ever switch to Java. In fact, while many of them started as Java devs, many have sworn to never take another Java job in their life.
- mlvljr 7y agoScala is Kotlin without the boilerplate -- and with warts, as per https://www.youtube.com/watch?v=v1wrWQcqLpo https://www.youtube.com/watch?v=v1wrWQcqLpo / https://news.ycombinator.com/threads?id=extempore https://news.ycombinator.com/threads?id=extempore .
- serpix 7y agoAs a polyglot dev with experience in JS, Python, Scala, Clojure, Java to name a few, Clojure is hands down in another league compared to all the rest. My experience is with Clojure is my productivity is a magnitude higher next to others. The REPL and instant feedback alone propel develoment velocity and developer satisfaction so far out there there is just no contest.
- smabie 7y agoScala has a REPL and instant feedback. Clojure is fine and expressive for sure, I just find that static typing is superior to dynamic typing. If you can write perfect code, maybe it isn't, but I personally have a level of peace of mind with Scala that I never gotten with Clojure. I have programmed with both professionally, if that matters, btw. Of course, people are different, and theoretically speaking, Clojure should have as much power as Scala.
- hota_mazi 7y ago> do yourself a favor and use Scala. No thanks. Scala had a shot these past ten years but it failed and the world has moved on.
- smabie 7y agoThe 6,000 Scala jobs on Indeed would disagree.
- mumblemumble 7y agoKotlin takes some inspiration from Scala. Not much, though, when you get down to it. The most immediately notable things are default constructors and companion objects. In actual use, I find the two to be a night and day difference. Scala is actively, desperately straining against the confines of the JVM. It's managed to implement some semblance of every major feature from Haskell on top of the JVM's object-oriented core, but it often has to resort to clever hacks in order to do so, and its language features are a rat's nest of edge and corner cases. For example, it takes Java's already confusing type system where most, but not all, things are objects, where some types can be reflected on, but not all of them, and where there's even a special annotation to help programmers deal with legal code that the compiler is somehow unable to type check, and it tries to render it more manageable (I guess?) by adding even more concepts to the mix: Class tags, type tags, and weak type tags. The end result is. . . well, if you really, absolutely must higher-kinded types and also the JVM, I guess that's as good as you're going to get. Personally, I like Scala. It's my main language right now. I want an ML-style language, but am trapped on the JVM, so it suits me well enough. But if others want to observe that, no matter how much you might like mustard, it's still not a tasty thing to put on pancakes, well, I can't in good faith say that they're wrong. Kotlin takes completely the opposite approach: It accepts that Java's decision to use an unholy blend of type reification and type erasure can't be unmade, and then focuses its effort on unifying the type system. Which is the kind of conservative and pragmatic approach that arguably represents the soul of Java. If you're looking for a revision and not an outright revolution, Kotlin is more likely to be your jam.
- turk73 7y agoGreat, just find me a steady job doing Kotlin here in the Midwest and I'll go there immediately. I was big into Clojure but never did find any work doing it. My current team has a couple microservices written in Kotlin and it's great, but the demand is just not out there and management is worried that they can't hire "Kotlin developers" and they're right. We can't even hire halfway decent Java devs most of the time.
- zmmmmm 7y agoThe problem is it's not though. Kotlin isn't just more concise Java. It sets out to solve a whole set of other problems such as removing use of null pointers, enforcing immutability everywhere, etc. This has a dramatic influence on design philosophy. I'm sure if that's how you would have programmed java then its great. But if you actually just program Java normally (mutable state, null is acceptable, etc) then something like Groovy is a much more natural fit.
- thu2111 7y agoIn fairness, you can just put ? on the end of every type and they will all be nullable like in Java. It can all be mutable state just by writing var instead of val. No big deal. The compiler will yell at you if you use a nullable pointer in a place that needs non-null but you can cast it away using !! But I write Kotlin all the time and nullness checking is one of its best features. I wouldn't want to go back.