• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Between Clojure and Kotlin as next major language (maybe both?)

 
Ranch Hand
Posts: 112
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to decide between Clojure and Kotlin as my next major language I learn.

Currently I know Java and studied C a bit so I could read my current employer's legacy Embedded SQL C code. I have looked into both Clojure and Kotlin, as well as Lisp, and am very attracted by the words of others saying learning a Lisp-family language will make me a better programmer. On the other hand I work with Spring extensively and if I need help in getting started with Kotlin and Spring I just go to start.spring.io and generate starter projects in Kotlin. My team is all Java on the back end with Spring Boot microservices. If I were to use Kotlin or Clojure here I would need to train my team.

Since it seems it would be easier to teach my team Kotlin than Clojure and since the Spring team seems to favor Kotlin on their starter website it seems that Kotlin is a more natural transition for me at this point. However, in my small startup (currently my side job) I can use whatever I want. I use the same stack at my startup, Ionic front end and Java Spring Microservices backend. I would love to change my backend to a Clojure app so I can start living in that world. Yet, I just have to be able to implement the same functionality I use from Spring with clojure, which is service discovery, oauth2 authorization server, an API gateway, client-side load balancing, and Spring MVC Web framework.

I am a bit hesitant to go full Clojure at this point because of my lack of knowledge and usage. In order to learn Clojure though I would like to start reimplementing a subset of my startup app's functionality in Clojure to see what it is like. I imagine there are plenty of resources for doing microservices with Clojure.

My default is to change my startup app to Kotlin since I think Kotlin is a better Java though I don't want to miss out on a good chance to learn Clojure.

At this point does Clojure seem a compelling choice for my startup and my own personal learning? And, is it more compelling than Kotlin?

 
Sheriff
Posts: 9012
655
Mac OS X Spring VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'll be rather quick for now.

Since you know Java, I'd say Kotlin is a language with more sugar, yes, there are new/more aspects of functional programming, but still, it is primarily object-oriented, sharing same paradigm with Java.

Clojure on the other hand, is a functional programming language (I won't use word 'pure' as someone could argue about that, and they would be right). In my own belief, since Java introducing more and more functional aspects, same as other modern languages as your mentioned Kotlin and Scala, I'd say to learn at least one language where functional programming is in its nature - is much better. The advantage of that I'd see, that you could combine your current Java's knowledge with upcoming Clojure's knowledge, and that way be quite confident about Kotlin without directly even learning it as of now.

When you write programs in Clojure you are forced to shape your thinking, while in Kotlin you can cut corners and write programs exactly in the same way as you'd write in Java, without even trying new features (which mainly come from functional programming).

I was learning at uni Clojure, Racket (also Lisp family), and I really really like them as languages. Racket mostly is known in academia, you might couldn't even find some industrial software in nowadays, but Clojure is a different story, it is one of JVM languages.



 
Rancher
Posts: 379
22
Mac OS X Monad Clojure Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Liutauras is absolutely spot-on: if you wany to use a language as a way to learn functional programming, you're going to be better off with Clojure.

As you rightly assumed, if you go with Clojure for your startup project, you're going to find yourself learning a lot of things from scratch and rewriting quite a lot of your application. Although I believe you can use Clojure with Spring, I don't know of anyone who does -- Spring is really the opposite of Clojure's mindset in many ways. Clojure is certainly good for microservices, but getting started with web and API development has quite a learning curve because it's very different to what you're used to. Clojure eschews frameworks in favor of composing small, focused libraries -- and there is a lot of choice so even choosing your first stack becomes quite a big exercise that involves learning new thinking and new terminology.

If you were starting from scratch, I'd wholeheartedly recommend Clojure -- and I'd be happy to answer questions and help you get up and running. Since you already have a Java code base with Spring, you'll find it a lot easier to incrementally rewrite it in Kotlin.

I've looked at Kotlin and I don't really see the point of learning it, for myself. Yes, it's a (much) better Java, much more concise, and it has an interesting "solution" to the null pointer problem but, as Liutauras said, it's too similar to Java to learn anything new from it.
 
Kent Bull
Ranch Hand
Posts: 112
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wow, that would be awesome. I definitely will start rebuilding my app in Clojure. My first question is which set of libraries to use.
In order to replace my existing Spring stack I need the following:
  • Something to do OAuth2 token authentication with JWTs (password grant flow). -> clj-jwt and buddy-auth?
  • Something to do a basic REST API with. -> Ring?
  • Connect to a PostgreSQL datastore with. -> Java Jdbc?


  • Do these libraries seem like a good starting point? I am sure I am missing at least one thing. My goal is to tend toward microservices, though I would be fine with just one big monolith to start out with. What do you recommend?

    It is interesting you say Clojure is the opposite mindset of Spring in many ways. In listening to Tim Ewald's 2013 Clojure con talk he sarcastically mentioned IoC as Injection of Complexity. Is learning why the mindsets are so different something I will just have to experience to understand?

     
    Sean Corfield
    Rancher
    Posts: 379
    22
    Mac OS X Monad Clojure Linux
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    We used Apache OLTU (Jose JWT, specifically), for the tokens, because we built our own OAuth2 provider. We didn't use any wrapper libraries, just raw Java interop, but looking at buddy-auth is probably worthwhile, if it automates some of what you want (I haven't used it).

    Ring is the basic library on which almost everything else is built in Clojure's web world. I don't know which app server you prefer but most folks either use Ring's embedded Jetty adapter or the http-kit library (Jetty plays nicer with New Relic but we use http-kit in production and have workarounds for New Relic).

    For routing, you'll either want Compojure or Bidi (we use both, but mostly Compojure), or perhaps Compojure-API if you want fancier REST support.

    For any SQL database, org.clojure/java.jdbc is the cornerstone library -- part of the set of Contrib libraries (the closest thing to a "standard library" that Clojure has) -- and I happen to be the maintainer, so I can definitely answer questions there (although we're a heavy MySQL shop and I barely use PostgreSQL).

    I remember Tim's comment -- that was the "Programming with Hand Tools" talk, right? They say that you only understand why you "need" Spring when you have suffered the pain of the problems it exists to solve. Those problems pretty much don't exist in Clojure. That said, I strongly recommend looking at Stuart Sierra's Component library which is the closest thing to Spring you'll find in Clojure but exists to solve a very specific problem regarding initialization (and finalization) of global resources, such as database connection pools, etc. We use Component very heavily at work.
     
    Kent Bull
    Ranch Hand
    Posts: 112
    3
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thanks, that should get me started. I'll check in as I go along writing. Thanks for pointing me in the right direction!
     
    Sean Corfield
    Rancher
    Posts: 379
    22
    Mac OS X Monad Clojure Linux
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    In addition to the Clojure forum here on the ranch, there's a very active Slack community for Clojure (over 11,000 members). You can sign up here and then login here or via the desktop app if you already have that installed (I'm in about a dozen Slack, and an admin on Clojurians). The #beginners channel there is very friendly and welcoming!
     
    Liutauras Vilda
    Sheriff
    Posts: 9012
    655
    Mac OS X Spring VI Editor BSD Java
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Sean, I have assigned you a cow for helpfulness.  Made it in under the hood as didn't know particular post on which to assign
     
    Sean Corfield
    Rancher
    Posts: 379
    22
    Mac OS X Monad Clojure Linux
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Just in case anyone decides to play around with Clojure and then also decides to play around with Kotlin, I created a Kotlin compilation task for Boot (one of Clojure's build tools): https://github.com/seancorfield/boot-kotlinc
     
    Don't get me started about those stupid light bulbs.
    reply
      Bookmark Topic Watch Topic
    • New Topic